我正在使用CLR profiling interfaces开发一个CLR分析器,并且在运行我的分析器时很难让CLR加载普通的,非配置文件优化的本机映像(使用ngen.exe
编译而没有/profile
选项)(或者至少,似乎这些图像没有加载,但现在我无法确定)。我究竟做错了什么?
我已经验证了COR_PRF_USE_PROFILE_IMAGES
标志(仅允许配置文件优化的原生图像)未在我的探查器中设置。
以下是我尝试过的。任何帮助/提示非常感谢!
FUSLOGVW输出:
我一直在检查本机图像活页夹日志(在FUSLOGVW.exe
中),试图找出图像是否已加载:
HelloWorld.exe
时 - 与启用了分析器的ngen.exe install HelloWorld.exe
进行了NGEN - 组装活页夹日志(ExplicitBind!FileName=(HelloWorld.exe).HTM
)显示:
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable d:\work\dotnet\projects\HelloWorld\HelloWorld\bin\x64\Debug\HelloWorld.exe
--- A detailed error log follows.
WRN: Native image compile options do not match request. Looking for next native image.
因此,基于该警告,似乎未加载本机映像。ngen.exe install HelloWorld.exe /Profile
运行配置文件图像NGEN时,图像似乎已成功加载,并且装配活页夹输出为:
LOG: Start validating all the dependencies.
LOG: [Level 1]Start validating native image dependency mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
Native image has correct version information.
LOG: Validation of dependencies succeeded.
LOG: Bind to native image succeeded.
Attempting to use native image C:\WINDOWS\assembly\NativeImages_v4.0.30319_64\HelloWorld\5647de1868c93e9132a1952a34e0a785\HelloWorld.ni.exe.
Native image successfully used.
所以看来这次,图像被加载了。c:\Windows\assembly\NativeImages_v4.0.30319_32\mscorlib
以同意使用的设置(没有额外的依赖关系到HelloWorld.exe
)。附加信息:
COR_PRF_DISABLE_ALL_NGEN_IMAGES
,它完全禁用了原生图像(在David Broman的blog post中描述)。这可能有助于排除故障。回来回答我自己的问题,看起来本机图像确实已经加载了! (两种 - 平原和轮廓优化)。问题是我的理解,确实如此。
我的消费来源是误读了FUSLOGVW日志输出。具体来说,不知何故,我错过了看到WRN: Native image compile options do not match request. Looking for next native image
是为/profile
图像,但图像搜索继续,发现平原,非剖面图像,并成功。
最终帮助我理解的是Visual Studio。在Visual Studio中调试CLR概要分析器时,本地映像的绑定显示在“调试输出”窗口中,其中还显示正在加载的DLL:
'CSharpTestProgram.exe' (Win32): Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_64\mscorlib\2ef49acbb43c068f6ddf1587283b5f29\mscorlib.ni.dll'.
一旦我得到这个,FUSLOGVW日志开始变得更有意义,我可以准确理解加载的图像和时间。
另一个观察结果是mscorlib /profile
图像占用的磁盘空间比普通原生图像多(在我的情况下大30%),这也帮助我在图像路径和它是否是/profile
之间进行关联。