VS2010分析器:是否可以分析一种特定方法?

发布于 2024-08-31 03:44:59 字数 52 浏览 7 评论 0原文

可能有一些方法可以打开和关闭代码分析?

或者您可以选择要分析的特定函数吗?

Possibly some methods to turn on and turn off profiling from code?

Or can you select a specific function to profile ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

深府石板幽径 2024-09-07 03:44:59

您还可以使用分析器的数据收集 API 来启动和停止围绕您感兴趣的方法进行分析。请参阅 这篇 MSDN 文章 提供了演练。

在这种情况下,使用 API 的最佳方法是在方法执行之前调用 StartProfile,然后在执行之后调用 StopProfile。您应该通过“开始时暂停分析”选项开始分析,这样在第一次调用 StartProfile 之前您不会开始分析。

使用数据收集 API 将与采样或仪器配合使用。

You can also use the profiler's data collection API to start and stop profiling around the methods you're interested in. See this MSDN article for a walkthrough.

The best way to use the API in this case would be to call StartProfile just before your methods execute and then call StopProfile just after. You should start profiling via the "Start With Profiling Paused" option so you don't start profiling until you hit the first call to StartProfile.

Using the data collection API will work with sampling or instrumentation.

娇妻 2024-09-07 03:44:59

是的,如果您进行仪器分析(而不是采样),您可以通过一点努力来做到这一点:

  1. 将二进制文件/项目添加为性能资源管理器中的目标
  2. 右键单击​​目标,单击“属性”
  3. 转到“仪器”部分,取消选中“排除”小函数...”
  4. 转到“高级”部分的“其他检测选项”下,指定您特别想要分析的方法(例如 /include:ConsoleApp.Program::Main,MyNamespace.MyClass::MyFunc)

/include 语法有点奇怪,但是如果您启动 VS 命令提示符并转到二进制文件的目录,则可以运行 vsinstr.exe /dumpfuncs foo.exe 查看可以显式包含的方法列表。

有关详细信息,请参阅vsinstr.exe 命令行语法

Yes, with a little effort, you can do this if you do instrumentation profiling (not sampling):

  1. Add your binary/project as a Target in Performance Explorer
  2. Right-click on the target, click Properties
  3. Go to the Instrumentation section, uncheck "Exclude small functions..."
  4. Go to the Advanced section, under "Additional instrumentation options", specify the methods you specifically want to profile (e.g. /include:ConsoleApp.Program::Main,MyNamespace.MyClass::MyFunc)

The /include syntax is a little weird, but if you launch a VS command prompt and go to your binary's directory, you can run vsinstr.exe /dumpfuncs foo.exe to see the list of methods you can explicitly include.

See the vsinstr.exe command-line syntax for more info.

混浊又暗下来 2024-09-07 03:44:59

不。

您正在寻找“瓶颈”,对吗?

它可能不在您认为的功能中。

这是我的方法依赖于任何语言或操作系统。

如果问题出在该函数中,它会告诉您。如果它在其他地方,它会告诉你。


@downvoter:有什么问题吗?如果您关心应用程序启动速度,请在应用程序启动过程中手动采样。

探查器中的替代方法是全程运行它,然后尝试找出时间线的哪一部分是启动的。由于大部分时间都花在用户等待上,当您不需要样本时,您可以将其置于 CPU 采样模式。这样做的问题是,您看不到诸如加载 dll、查询 DNS 等所花费的 I/O 时间之类的事情,这些事情在启动期间可能占主导地位。

然后就是像“热路径”这样的愚蠢的演示问题,真正的时间掌握者可以轻松隐藏

如果您问“我如何检查数千个堆栈样本?”答案是你不需要。如果初创公司的速度明显缓慢,那是因为它花费了很大一部分时间做一些不需要做的事情——保守地说,大约有 30% 的时间。
这意味着平均每 3.33 个样本您就会看到一次。
由于您需要查看两次或多次才能知道这是一个问题,因此平均需要 6.67 个样本。
问题越大,需要的样本就越少。
(如果是 90%,则只需要 2/0.9 = 2.2 个样本。)
如果你检查 20 个样本,你会发现任何问题的成本都超过 10%,如果你解决了它,任何较小的问题都会占据更大的百分比 - 它们会被加速比放大,因此下次更容易找到它们-大约。
这是数学计算。

Don't.

You are looking for "the bottleneck", right?

It's probably not in the function where you think it is.

This is the method I rely on, for any language or OS.

If the problem is in that function, it will tell you. If it is somewhere else, it will tell you.


@downvoter: What's the problem? If you are concerned about speed of application startup, manually take samples during application startup.

The alternative in a profiler is to run it over the whole time and then try to figure out which part of the timeline was the startup. And since much of the time is spent in user-wait, when you don't want samples, you put it in CPU-sampling mode. The trouble with that is, you don't see things like I/O time spent loading dlls, querying DNS, etc., which can be dominant during startup.

Then there's the whole issue of presentation silliness like "hot path", where the true time-taker can easily hide.

In case you're asking "How can I examine thousands of stack samples?" the answer is you don't need to. If the startup is noticeably slow, it is because it is spending some large fraction of its time doing something it doesn't need to do - some fraction like, say, 30%, to be conservative.
That means you will see it, on average, once every 3.33 samples.
Since you need to see it two or more times to know it is a problem, on average you need 6.67 samples.
The bigger the problem is, the fewer samples you need.
(If it's 90%, you only need 2/0.9 = 2.2 samples.)
If you examine 20 samples, you will see any problem costing more than about 10%, and if you fix it, any smaller problems take a larger percent - they are amplified by the speedup ratio, so they are easier to find on the next go-around.
Here's the math.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文