.net - .NET 分析 API 初始化
问题描述
我正在尝试学习如何使用分析 API 编写一个简单的 .net 分析器。
第一步,我只想能够加载分析器 dll 并从 ICorProfilerCallback::Initialize 写入日志文件。
在一个测试 .net 控制台应用程序中,我设置了以下环境变量:
COR_ENABLE_PROFILING="1"
COR_PROFILER="ProfilerTest"
--> 这就是我认为的问题所在。我不知道如何找到 GUID,而 ProfilerTest 是我的 dll 的名称。这里说从 .NET Framework 4 开始,不必注册分析器。这是否意味着不需要设置这个环境变量?
在微软的 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;
}
解决方案
推荐阅读
- laravel - ->where('id', '<>', $id) 中的 '<>' 有什么用
- powershell - test batch statements directly in powershell without wrapping the call in a batch file
- python - 如何使用 BeautifulSoup 仅提取给定类或标签内的文本?
- typescript - Typescript knex:无法读取未定义的属性“客户端”
- java - Java:仅打印字符串中的唯一字符
- docker - Docker 堆栈不按标签更新容器数据
- python - 行中的 Python/Pandas 数据帧时间数据(按名称分组)
- ip-address - 如何在 Azure VMSS 中为单个 NIC 创建多个 IP 地址
- javascript - 如何对chart.js饼图的每个弧段的borderColor进行更多控制
- python - 根据其他列中的值替换列值