我正在从 Visual Studio 2013 分析 C# 程序。我转到分析 -> 性能和诊断来启动向导。它让我可以选择分析方法。如果我选择默认的 CPU 采样,那么分析就会起作用,我可以看到结果。但是,如果我选择第三个选项,.NET 内存分配,那么在我的应用程序完成后,我会在 Visual Studio 输出窗口中看到空结果和此错误:
VSP2340: Environment variables were not properly set during profiling run and managed
symbols may not resolve. Please use vsperfclrenv before profiling
我在网上看到的所有文档都表明vsperfclrenv
与独立探查器一起使用,直接从 Visual Studio 运行探查器时不需要。但是,为了安全起见,我尝试从命令提示符窗口设置必要的环境变量,然后直接从该窗口运行 IDE,以便它选择环境:
C:
cd "\Program Files (x86)\Microsoft Visual Studio 12.0\Team Tools\Performance Tools\x64"
vsperfclrenv /samplegclife /tracegclife /globalsamplegclife /globaltracegclife
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe"
然后我像以前一样进入Visual Studio内部的性能向导。但结果是一样的;我仍然看到VSP2340试图分析结果。我究竟做错了什么?
我注意到该向导有四种分析可供选择:CPU 采样、检测、内存分配和资源争用。这与提供的选项不太匹配vsperfclrenv
,其中仅讨论采样和跟踪分析(每个程序都有应用程序与服务变体;我的程序是应用程序而不是服务,但我启用了所有选项只是为了确定)。
内存分配分析是否需要一些额外的环境变量?或者 Visual Studio 消息是关于vsperfclrenv
误导?
这可能与管理权限有关。就我而言,我知道有两种解决方法:
- 以具有真正管理员权限的用户身份运行 Visual Studio。
- 使用 [开始 -> Microsoft Visual Studio 2012 -> Visual Studio 工具 -> ] VS2012 开发人员命令提示符 -> 以管理员身份运行。在命令提示符下,
vsperfclrenv /samplegclife
。窗口标题更改为Administrator: Developer Command Prompt for VS2012
to Administrator: VSPerf Sampling Attaching and Allocation Profiling with objects lifetime 'ON'
. Then "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe"
.
第二种方法看起来就像原始海报所做的那样,除了我使用的不是普通的 cmd.exe 窗口以管理员身份运行使用开发人员命令提示符。对我来说,当我不以管理员身份运行时,我会收到 VSP2340 错误。
我在略有不同的环境中遇到了非常相似的症状:Windows 7,作为普通用户(不在本地管理员组中),从“开始”菜单启动 Visual Studio 2012,使用 Avecto Defendpoint 向 Visual Studio 可执行文件授予提升的权限,CPU 分析产生正常结果,但 .NET 内存分配采样结果为空白。输出窗口说:
Profiling started.
Profiling process ID #### (xxxx).
Process ID #### has exited.
Data written to C:\path\to\solution\xxxxyymmdd.vsp.
Profiling finished.
VSP2340: Environment variables were not properly set during profiling run and
managed symbols may not resolve. Please use vsperfclrenv before profiling.
Profiling complete.
对于 CPU 分析运行,我得到的不是 VSP2340,而是一长串Loaded symbols for [full/path/to/dll]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)