I am trying to learn how to write a simple .net profiler using profiling API.
For the first step, I just want to be able to load the profiler dll and to write to a log file from ICorProfilerCallback::Initialize.
In a test .net console app I set followning environment variables:
COR_ENABLE_PROFILING="1"
COR_PROFILER="ProfilerTest"
--> This is where I think the problem is. I don't know how to find the GUID and ProfilerTest is the name od my dll. Here it says that starting with the .NET Framework 4, profilers do not have to be registered. Does this mean that this environment variable doesn't need to be set?
In the CLRProfiler source code from microsoft, they also set COR_PROFILER_PATH
.
Just to be complete here is the initialize function from dll:
HRESULT STDMETHODCALLTYPE Profiler::Initialize(IUnknown* pICorProfilerInfoUnk)
{
// A macro that writes to a log file.
LOG(INFO);
auto queryInterfaceResult = pICorProfilerInfoUnk->QueryInterface(__uuidof(ICorProfilerInfo), reinterpret_cast<void **>(&this->corProfilerInfo));
if (FAILED(queryInterfaceResult))
return E_FAIL;
DWORD eventMask = COR_PRF_ALL;
auto hr = this->corProfilerInfo->SetEventMask(eventMask);
if (hr != S_OK)
printf("ERROR: Profiler SetEventMask failed (HRESULT: %d)", hr);
printf("ERROR: Profiler SetEventMask failed (HRESULT: %d)", hr);
LOG(INFO);
return S_OK;
}