【问题标题】:Using MS Standalone profiler in VS2008 Professional在 VS2008 Professional 中使用 MS 独立分析器
【发布时间】:2010-04-21 19:39:07
【问题描述】:

我在从 VS 单元测试工具运行时尝试分析我的 .NET dll,但我遇到了问题。我使用的是独立的命令行分析器,因为 VS2008 Professional 没有内置分析器。

我有一个打开的 CMD 窗口并运行了以下命令(我之前对其进行了检测,这就是 vsinstr 发出警告的原因):

C:\...\BusinessRules\obj\Debug>vsperfclrenv /samplegclife /tracegclife /globalsamplegclife /globaltracegclife
Enabling VSPerf Sampling Attach Profiling. Allows to 'attaching' to managed applications.

Current Profiling Environment variables are:
COR_ENABLE_PROFILING=1
COR_PROFILER={0a56a683-003a-41a1-a0ac-0f94c4913c48}
COR_LINE_PROFILING=1
COR_GC_PROFILING=2

C:\...\BusinessRules\obj\Debug>vsinstr BusinessRules.dll
Microsoft (R) VSInstr Post-Link Instrumentation 9.0.30729 x86
Copyright (C) Microsoft Corp. All rights reserved.

Error VSP1018 : VSInstr does not support processing binaries that are already instrumented.

C:\...\BusinessRules\obj\Debug>vsperfcmd /start:trace /output:foo.vsp
Microsoft (R) VSPerf Command Version 9.0.30729 x86
Copyright (C) Microsoft Corp. All rights reserved.

C:\...\BusinessRules\obj\Debug>

然后,我运行单元测试来执行已检测的代码。当单元测试完成后,我做了......

C:\...\BusinessRules\obj\Debug>vsperfcmd /shutdown
Microsoft (R) VSPerf Command Version 9.0.30729 x86
Copyright (C) Microsoft Corp. All rights reserved.


Waiting for process 4836 ( C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\vstesthost.exe) to shutdown...

显然是在等待 VS2008 关闭所以我关闭了它...

Shutting down the Profile Monitor
------------------------------------------------------------

C:\...\BusinessRules\obj\Debug>

看起来不错,目录中有一个 3.2mb 的 foo.vsp 文件。接下来我做了...

C:\...\BusinessRules\obj\Debug>vsperfreport foo.vsp /summary:all

Microsoft (R) VSPerf Report Generator, Version 9.0.0.0
Copyright (C) Microsoft Corporation. All rights reserved.

VSP2340: Environment variables were not properly set during profiling run and managed symbols may not resolve.  Please use vsperfclrenv before profiling.
File opened
Successfully opened the file.
A report file, foo_Header.csv, has been generated.
A report file, foo_MarksSummary.csv, has been generated.
A report file, foo_ProcessSummary.csv, has been generated.
A report file, foo_ThreadSummary.csv, has been generated.
Analysis completed
A report file, foo_FunctionSummary.csv, has been generated.
A report file, foo_CallerCalleeSummary.csv, has been generated.
A report file, foo_CallTreeSummary.csv, has been generated.
A report file, foo_ModuleSummary.csv, has been generated.

C:\...\BusinessRules\obj\Debug>

注意到关于环境变量和使用 vsperfclrenv 的警告了吗?但我已经运行它了!也许我使用了错误的开关?我不知道。无论如何,将 csv 文件加载到 Excel 或使用 perfconsole 工具会提供大量有用的信息和无用的符号名称:

*** Loading commands from: C:\temp\PerfConsole\bin\commands\timebytype.dll
***   Adding command: timebytype
*** Loading commands from: C:\temp\PerfConsole\bin\commands\partition.dll
***   Adding command: partition

Welcome to PerfConsole 1.0 (for bugs please email: joshwil@microsoft.com), for help type: ?, for a quickstart type: ??

> load foo.vsp
*** Couldn't match to either expected sampled or instrumented profile schema, defaulting to sampled
*** Couldn't match to either expected sampled or instrumented profile schema, defaulting to sampled
*** Profile loaded from 'foo.vsp' into @foo

> 
> functions @foo
>>>>> Function Name

Exclusive            Inclusive            Function Name  Module Name
-------------------- -------------------- -------------- ---------------
900,798,600,000.00 % 900,798,600,000.00 % 0x0600003F     20397910
14,968,500,000.00 %  44,691,540,000.00 %  0x06000040     14736385
8,101,253,000.00 %   14,836,330,000.00 %  0x06000041     5491345
3,216,315,000.00 %   6,876,929,000.00 %   0x06000042     3924533
<snip>
71,449,430.00 %      71,449,430.00 %      0x0A000074     42572
52,914,200.00 %      52,914,200.00 %      0x0A000073     0
14,791.00 %          13,006,010.00 %      0x0A00007B     0
199,177.00 %         6,082,932.00 %       0x2B000001     5350072
2,420,116.00 %       2,420,116.00 %       0x0A00008A     0
836.00 %             451,888.00 %         0x0A000045     0
9,616.00 %           399,436.00 %         0x0A000039     0
18,202.00 %          298,223.00 %         0x06000046     1479900

只要它能给我函数和模块名称而不是十六进制数字,我就可以找到瓶颈了!

我做错了什么?

--- 阿利斯泰尔。

【问题讨论】:

    标签: visual-studio-2008 profiling


    【解决方案1】:

    原因是我没有在定义环境变量的同一进程中运行可执行文件。需要访问环境变量的是检测代码,而不是分析器。

    所以我在使用 vsperfclrenv 后直接从命令行运行 VS2008,一切正常,我有了我的函数名称。

    遗憾的是,我仍然遇到 Schema 错误,这意味着我无法深入了解调用树,但我至少设法确定了这个特定的瓶颈。

    --- 阿利斯泰尔。

    【讨论】:

      【解决方案2】:

      一些可能的尝试(请注意,我不是命令行分析器方面的专家 - 我之前只使用过几次):

      1. docs for vsperfclrenv 说:

        您选择的选项取决于您使用的三种分析类型中的哪一种:采样、检测或全局。

        在致电vsperfclrenv 时,您可以选择所有 3 种类型的分析 - 我建议您选择一种类型开始,如果可行,则从那里继续,但您想尝试其他方法看看他们是否工作得更好。

      2. 您可能还需要指定符号的位置(即使这不是使用vsperfclrenv 完成的)。可以使用_NT_SYMBOLS_PATH 环境变量或vsperfreport/SymbolPath 选项来配置符号位置(或者通过将.pdb 文件与二进制文件放在同一位置)。详情请见"How to: Specify Symbol File Locations from the Command Line"

      【讨论】:

        猜你喜欢
        • 2018-12-02
        • 2010-10-12
        • 1970-01-01
        • 2011-10-14
        • 2016-05-26
        • 2015-05-26
        • 1970-01-01
        • 2013-09-21
        • 1970-01-01
        相关资源
        最近更新 更多