.NET分析API初始化

时间:2019-05-02 19:19:16

标签: .net com profiling clr clr-profiling-api

我正在尝试学习如何使用概要分析API编写简单的.net分析器。

第一步,我只想能够加载探查器dll并从ICorProfilerCallback :: Initialize写入日志文件。

在一个测试.net控制台应用程序中,我设置了以下环境变量:

COR_ENABLE_PROFILING="1"

COR_PROFILER="ProfilerTest"->我认为这是问题所在。我不知道如何找到GUID,ProfilerTest是dll的名称。 Here表示从.NET Framework 4开始,不必注册分析器。这是否意味着不需要设置此环境变量?

在Microsoft的CLRProfiler源代码中,他们还设置了COR_PROFILER_PATH

这里要完成的是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;
}

0 个答案:

没有答案