在Visual Studio 2010中测量C++项目性能的问题

13

我想测试一些控制台应用程序项目中的函数和方法的性能,使用的是Visual Studio 2010。

我将性能分析方法配置为instrumentation。问题在于性能监视器不起作用。输出信息如下:

Profiling started.
Instrumenting w:\MyProject\ProfilingTest\Build\Debug\ProfilingTest.exe in place
Info VSP3049: Small functions will be excluded from instrumentation.
Microsoft (R) VSInstr Post-Link Instrumentation 10.0.40219 x64
Copyright (C) Microsoft Corp. All rights reserved.
File to Process:
   w:\MyProject\ProfilingTest\Build\Debug\ProfilingTest.exe --> w:\MyProject\ProfilingTest\Build\Debug\ProfilingTest.exe
Original file backed up to w:\MyProject\ProfilingTest\Build\Debug\ProfilingTest.exe.orig
Successfully instrumented file w:\MyProject\ProfilingTest\Build\Debug\ProfilingTest.exe.
The process cannot access the file 'w:\MyProject\ProfilingTest\Build\Debug\ProfilingTest.exe' because it is being used by another process.
Data written to w:\MyProject\ProfilingTest\ProfilingTest110611(17).vsp.
Profiling finished.
File contains no data buffers
File contains no data buffers
Analysis failed
The process cannot access the file 'w:\MyProject\ProfilingTest\Build\Debug\ProfilingTest.exe' because it is being used by another process.
Profiling complete.

我认为"万恶之源"是: 由于另一个进程正在使用文件,因此该进程无法访问文件“...”。

有人尝试在Visual Studio 2010中开发本地应用程序时遇到类似的问题并解决了吗?

后来添加: 如果我选择直接构建的可执行文件进行分析,而不是选择要分析的项目,则可以成功进行分析,而且没有收到进程阻塞的消息,甚至还收到了文件分析报告。但是,在分析结束时监视应用程序会崩溃。我怀疑这与IDE有关,但我不能确定。


我已经将忽略文件的位置添加到了杀毒软件中,但仍然无法正常工作。 - Cătălin Pitiș
你是从性能分析器中运行可执行文件,还是从IDE中运行它,然后尝试使用性能分析器?...可能是其他程序在你启动性能分析器之前启动了该应用程序或正在使用它。 - AJG85
我从集成开发环境中执行所有操作。 - Cătălin Pitiș
我刚遇到了完全相同的错误,并找到了这篇文章。没有解决方案,但你并不是唯一一个遇到这个问题的人。我通过禁用仪器和使用CPU%采样方法获得了一些数字,但无论如何,仪器都会给我带来与你看到的相同的错误(也是本机C ++项目)。而进程资源管理器在这里是无用的,因为该进程实际上并未运行,这似乎是VS本身的内部问题。 - DXM
1
实际上,昨晚我尝试直接对可执行文件进行插装,而不是从向导中插装项目。它起作用了。我怀疑IDE在监视时阻止了exe文件。在两种情况下发生的情况是,在执行结束后,Visual Studio的性能监视器崩溃了。 - Cătălin Pitiș
显示剩余2条评论
3个回答

10

从性能向导中选择可执行文件作为目标,并提供可执行文件的路径。这样对我来说解决了问题。


这就是我最终所做的(请查看我对问题的最后一条评论)。看起来,我不是唯一遇到这个问题的人 :) - Cătălin Pitiș

0
使用进程资源管理器的查找句柄功能(Ctrl + F)来确定哪个进程打开了ProfilingTest.exe。这将帮助您进入故障排除过程的下一步。

以前没有尝试过,但是 procmon(也来自 sysinternals)可能会实时提供相同的信息。 - pepsi

0

我发现的另一个解决方法是执行以下操作:

1) Launch performance wizard
2) choose your project
3) un-check the box to automatically start your profiling 
4) Choose "New Performance Session" and choose your project again (top button on Performance explorer window)
5) Select your performance session from "Targets" and choose "Start Profiling"

我想知道微软的好心人是否注意到了这个问题。

谢谢。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接