Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Profiler] Gleocadie/clean up profiler code #6291

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,8 @@ std::vector<int32_t> GetProcessThreads(int32_t pid)
}
else
{
static bool alreadyLogged = false;
if (!alreadyLogged)
{
alreadyLogged = true;
auto errorNumber = errno;
Log::Error("Failed at opendir ", dirname, " error: ", strerror(errorNumber));
}
auto errorNumber = errno;
LogOnce(Error, "Failed at opendir ", dirname, " error: ", strerror(errorNumber));
}

return threads;
Expand Down Expand Up @@ -271,13 +266,8 @@ std::vector<std::shared_ptr<IThreadInfo>> GetProcessThreads()
}
else
{
static bool alreadyLogged = false;
if (!alreadyLogged)
{
alreadyLogged = true;
auto errorNumber = errno;
Log::Error("Failed at opendir ", dirname, " error: ", strerror(errorNumber));
}
auto errorNumber = errno;
LogOnce(Error, "Failed at opendir ", dirname, " error: ", strerror(errorNumber));
}

return threads;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,8 @@ bool ProfilerSignalManager::CheckSignalHandler()
{
if (!_canReplaceSignalHandler)
{
static bool alreadyLogged = false;
if (alreadyLogged)
return false;

alreadyLogged = true;
_isHandlerInPlace = false;
Log::Warn("Profiler signal handler was replaced again. As of now, it will not be restored: the profiler is disabled.");
LogOnce(Warn, "Profiler signal handler was replaced again. As of now, it will not be restored: the profiler is disabled.");
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
#include "COMHelpers.h"
#include "FrameworkThreadInfo.h"
#include "HResultConverter.h"
#include "IAppDomainStore.h"
#include "IConfiguration.h"
#include "IManagedThreadList.h"
#include "IFrameStore.h"
#include "IThreadsCpuManager.h"
#include "IAppDomainStore.h"
#include "IManagedThreadList.h"
#include "IRuntimeIdStore.h"
#include "ISampledAllocationsListener.h"
#include "IThreadsCpuManager.h"
#include "Log.h"
#include "MetricsRegistry.h"
#include "OsSpecificApi.h"
Expand All @@ -22,17 +22,13 @@
#include "shared/src/native-src/string.h"

std::vector<SampleValueType> AllocationsProvider::SampleTypeDefinitions(
{
{"alloc-samples", "count"},
{"alloc-size", "bytes"}
}
);
{{"alloc-samples", "count"},
{"alloc-size", "bytes"}});

std::vector<SampleValueType> AllocationsProvider::FrameworkSampleTypeDefinitions(
{
{"alloc-samples", "count"},
}
);
});

AllocationsProvider::AllocationsProvider(
bool isFramework,
Expand Down Expand Up @@ -96,7 +92,6 @@ AllocationsProvider::AllocationsProvider(
_shouldSubSample = !_pConfiguration->IsAllocationRecorderEnabled();
}


void AllocationsProvider::OnAllocation(uint32_t allocationKind,
ClassID classId,
const WCHAR* typeName,
Expand All @@ -116,8 +111,12 @@ void AllocationsProvider::OnAllocation(uint32_t allocationKind,

// create a sample from the allocation

std::shared_ptr<ManagedThreadInfo> threadInfo;
CALL(_pManagedThreadList->TryGetCurrentThreadInfo(threadInfo))
auto threadInfo = ManagedThreadInfo::CurrentThreadInfo;
if (threadInfo == nullptr)
{
LogOnce(Warn, "AllocationsProvider::OnAllocation: Profiler failed at getting the current managed thread info ");
return;
}

const auto pStackFramesCollector = OsSpecificApi::CreateNewStackFramesCollectorInstance(_pCorProfilerInfo, _pConfiguration, &_callstackProvider);
pStackFramesCollector->PrepareForNextCollection();
Expand Down Expand Up @@ -236,16 +235,16 @@ void AllocationsProvider::OnAllocation(uint64_t timestamp,
rawSample.AppDomainId = -1;
}
}
else // create a fake IThreadInfo that wraps the OS thread id (no name, no profiler thread id)
else // create a fake IThreadInfo that wraps the OS thread id (no name, no profiler thread id)
{
rawSample.ThreadInfo = std::make_shared<FrameworkThreadInfo>(threadId);

// TODO: do we need to set to -1?
//rawSample.AppDomainId = -1;
// rawSample.AppDomainId = -1;
}

//rawSample.AllocationSize = objectSize;
//rawSample.Address = address;
// rawSample.AllocationSize = objectSize;
// rawSample.Address = address;
rawSample.MethodTable = classId;

// The provided type name contains the metadata-based `xx syntax for generics instead of <>
Expand Down
60 changes: 24 additions & 36 deletions profiler/src/ProfilerEngine/Datadog.Profiler.Native/COMHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,32 @@

#include "HResultConverter.h"

#define CALL(x) \
{ \
HRESULT hr = x; \
if (FAILED(hr)) \
{ \
static bool callAlreadyLogged = false; \
if (callAlreadyLogged) \
return; \
callAlreadyLogged = true; \
Log::Warn("Profiler call failed with result ", HResultConverter::ToStringWithCode(hr), ": ", #x); \
return; \
} \
#define CALL(x) \
{ \
HRESULT hr = x; \
if (FAILED(hr)) \
{ \
LogOnce(Warn, "Profiler call failed with result ", HResultConverter::ToStringWithCode(hr), ": ", #x); \
return; \
} \
}

#define INVOKE(x) \
{ \
HRESULT hr = x; \
if (FAILED(hr)) \
{ \
static bool invokeAlreadyLogged = false; \
if (invokeAlreadyLogged) \
return false; \
invokeAlreadyLogged = true; \
Log::Warn("Profiler call failed with result ", HResultConverter::ToStringWithCode(hr), ": ", #x); \
return false; \
} \
#define INVOKE(x) \
{ \
HRESULT hr = x; \
if (FAILED(hr)) \
{ \
LogOnce(Warn, "Profiler call failed with result ", HResultConverter::ToStringWithCode(hr), ": ", #x); \
return false; \
} \
}

#define INVOKE_INFO(x) \
{ \
HRESULT hr = x; \
if (FAILED(hr)) \
{ \
static bool invokeAlreadyLogged = false; \
if (invokeAlreadyLogged) \
return false; \
invokeAlreadyLogged = true; \
Log::Info("Profiler call failed with result ", HResultConverter::ToStringWithCode(hr), ": ", #x); \
return false; \
} \
#define INVOKE_INFO(x) \
{ \
HRESULT hr = x; \
if (FAILED(hr)) \
{ \
LogOnce(Info, "Profiler call failed with result ", HResultConverter::ToStringWithCode(hr), ": ", #x); \
return false; \
} \
}
Loading
Loading