在 C++ 中逐行分析
我有一个正在尝试优化的 C++ 程序。 因为我希望它运行得快,所以我没有使用很多函数调用。我见过的大多数分析工具都可以在函数调用解析中为您提供分析信息。但是,我希望以逐行分辨率的方式进行。有这样的选择吗?
我在 Windows 上使用 Visual Studio 2010。
谢谢。
I have a C++ program I am trying to optimize.
Since I want it to run fast, I am not using a lot of function calls. Most profiling tool I have seen can give you profiling info in a function-call resolution. However, I would like it in a line-by-line resolution. Is there some option like this?
I am using Visual Studio 2010 on Windows.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
英特尔并行放大器应该能够满足您的需求。如果这就是您想要的:
Intel Parallel Amplifier should be capable of what you want. If that is what you want:
如果您在 AMD 处理器上运行,CodeAnalyst 是免费的并且可以做到这一点(至少在基于时间的分析中);实际上,您可以“放大”和缩小,查看从进程到函数再到单个汇编指令,什么占用了最多的 CPU 时间。
但是,请记住,要通过基于时间的分析获得有意义的结果,您应该运行关键部分多次检查代码,否则您获得的统计数据没有多大意义。
顺便说一句,在我看来,你应该忘记更少的函数调用=>更快的想法。如果函数调用的成本大于其“有效负载”,编译器应该能够自行确定是否方便内联调用,并且在某些情况下,甚至内联太多也会减慢代码速度。
If you're running with on an AMD processor, CodeAnalyst is free and can do that (at least, in time-based profiling); you can actually "zoom" in and out seeing what is taking the most CPU time from processes to functions down to single assembly instructions.
However, keep in mind that to get meaningful results to that resolution with time-based profiling you should run the critical part of the code several times, otherwise the statistics you get doesn't have much sense.
By the way, in my opinion you should forget about the less function calls=>faster idea. If the cost of a function call is bigger than its "payload", the compiler should be able to figure out by itself if it's convenient to inline the call, and in some cases even inlining too much can slow down the code.
AQTime 是一款适用于 Windows 的商业分析器,我发现它在功能和性能方面都表现得非常好线路时序。我喜欢它的一件事是您不必摆弄编译器选项或 Visual Studio 设置 - 即您不需要任何额外编译器选项来启用分析:您只需进行分析即可是 pdb(符号)文件和可执行文件。 (是的,您可以为发布编译创建一个 pdb 文件。)
AQTime is a commercial profiler for Windows and I have found it to work pretty well for both function and line timings. One thing I like about it is that you do not have to fiddle with compiler options or Visual Studio settings -- i.e. you do not need any additional compiler options to enable profiling: All you need to do the profiling is the pdb (symbol) file and the executable. (And yes, you can create a pdb file for your release-compile.)
恕我直言,这种方法是最好的,由于这些原因,下面是一个43 倍加速。对于一个示例,以及另一个 ,以及另一个< /a>.您可能会感到惊讶,它的技术含量很低且需要手动操作,但您无法超越结果。
哦,顺便说一下,对于 Visual Studio,LTProf 可能是下一个最好的选择。它为您提供线路级百分比,该百分比源自随机挂钟时间采集的堆栈样本。不要被大量花哨的用户界面选项或计时准确性的承诺所吸引。那些事情并不重要。重要的是它指出了值得优化的地方。
IMHO, this method is best, for these reasons, and here's an example of a 43x speedup. It's not a well-known technique, except to a small number of people, for one example, and another, and another. You may be surprised that it's very low-tech and manual, but you can't beat the results.
Oh, and by the way, for Visual Studio, LTProf may well be the next best thing. It gives you line-level percents, derived from stack samples taken at random wall-clock times. Don't get sucked in by a lot of fancy UI options or promises of accuracy of timing. Those things don't matter. What matters is that it pinpoints the spots worth optimizing.