你最喜欢的分析工具是什么(用于 C++)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26663/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's your favorite profiling tool (for C++)
提问by OysterD
So far, I've only used Rational Quantify. I've heard great things about Intel's VTune, but have never tried it!
到目前为止,我只使用了 Rational Quantify。我听说过有关英特尔 VTune 的好消息,但从未尝试过!
Edit: I'm mostly looking for software that will instrument the code, as I guess that's about the only way to get very fine results.
编辑:我主要是在寻找可以检测代码的软件,因为我想这是获得非常好的结果的唯一方法。
See also:
也可以看看:
回答by Al.
For linux development (although some of these tools might work on other platforms). These are the two big names I know of, there's plenty of other smaller ones that haven't seen active development in a while.
对于 linux 开发(尽管其中一些工具可能适用于其他平台)。这是我所知道的两个大公司,还有很多其他较小的公司已经有一段时间没有看到积极的发展了。
回答by Weidenrinde
For Linux: Google Perftools
对于 Linux: 谷歌 Perftools
- Faster than valgrind (yet, not so fine grained)
- Does not need code instrumentation
- Nice graphical output (--> kcachegrind)
- Does memory-profiling, cpu-profiling, leak-checking
- 比 valgrind 快(但不是那么细粒度)
- 不需要代码检测
- 漂亮的图形输出(--> kcachegrind)
- 是否进行内存分析、cpu 分析、泄漏检查
回答by Mike Dunlavey
IMHO, sampling using a debuggeris the best method. All you need is an IDE or debugger that lets you halt the program. It nails your performance problems before you even get the profiler installed.
恕我直言,使用调试器采样是最好的方法。您所需要的只是一个 IDE 或调试器,可以让您停止程序。它甚至在您安装分析器之前就解决了您的性能问题。
回答by Matt Dillard
My only experience profiling C++ code is with AQTimeby AutomatedQA (now SmartBear Software). It has several types of profilers built in (performance, memory, Windows handles, exception tracing, static analysis, etc.), and instruments the code to get the results.
我分析 C++ 代码的唯一经验是使用AutomatedQA(现在是 SmartBear Software)的AQTime。它内置了多种类型的分析器(性能、内存、Windows 句柄、异常跟踪、静态分析等),并检测代码以获得结果。
I enjoyed using it - it was always fun to find those spots where a small change in code could make a dramatic improvement in performance.
我喜欢使用它 - 找到那些代码中的小改动可以显着提高性能的地方总是很有趣。
回答by jsight
I've used Glowcodeextensively in the past and have had nothing but positive experiences with it. Its Visual Studio integration is really nice, and it is the most efficient/intuitive profiler that I've ever used (even compared to profilers for managed code).
我过去曾广泛使用Glowcode,但对它只有积极的体验。它的 Visual Studio 集成非常好,它是我用过的最有效/最直观的分析器(甚至与托管代码的分析器相比)。
Obviously, thats useless if your not running on Windows, but the question leaves it unclear to me exactly what your requirements are.
显然,如果您不在 Windows 上运行,那将毫无用处,但是这个问题让我不清楚您的要求究竟是什么。
回答by Dark Shikari
oprofile, without a doubt; its simple, reliable, does the job, and can give all sorts of nice breakdowns of data.
oprofile,毫无疑问;它简单,可靠,可以完成工作,并且可以提供各种很好的数据细分。
回答by Dimitri C.
The profiler in Visual Studio 2008is very good: fast, user friendly, clear and well integrated in the IDE.
Visual Studio 2008 中的分析器非常好:快速、用户友好、清晰且很好地集成在 IDE 中。
回答by Moberg
I have never done profiling before. Yesterday I programmed a ProfilingTimer class with a static timetable (a map<std::string, long long>) for time storage.
我以前从未做过分析。昨天我用静态时间表(map<std::string, long long>)编写了一个 ProfilingTimer 类,用于时间存储。
The constructor stores the starting tick, and the destructor calculates the elapsed time and adds it to the map:
构造函数存储起始刻度,析构函数计算经过的时间并将其添加到地图中:
ProfilingTimer::ProfilingTimer(std::string name)
: mLocalName(name)
{
sNestedName += mLocalName;
sNestedName += " > ";
if(sTimetable.find(sNestedName) == sTimetable.end())
sTimetable[sNestedName] = 0;
mStartTick = Platform::GetTimerTicks();
}
ProfilingTimer::~ProfilingTimer()
{
long long totalTicks = Platform::GetTimerTicks() - mStartTick;
sTimetable[sNestedName] += totalTicks;
sNestedName.erase(sNestedName.length() - mLocalName.length() - 3);
}
In every function (or {block}) that I want to profile i need to add:
在我想要分析的每个函数(或 {block})中,我需要添加:
ProfilingTimer _ProfilingTimer("identifier");
This line is a bit cumbersome to add in all functions I want to profile since I have to guess which functions take a lot of time. But it works well and the print function shows time consumed in %.
添加我想要分析的所有函数这一行有点麻烦,因为我必须猜测哪些函数需要很多时间。但它运行良好,打印功能以百分比显示消耗的时间。
(Is anyone else working with any similar "home-made profiling"? Or is it just stupid? But it's fun! Does anyone have improvement suggestions?
(是否还有其他人使用任何类似的“自制分析”?或者只是愚蠢?但这很有趣!有人有改进建议吗?
Is there some sort of auto-adding a line to all functions?)
是否有某种自动向所有函数添加一行?)
回答by user15071
For Windows, check out Xperf. It uses sampled profile, has some useful UI, & does not require instrumentation. Quite useful for tracking down performance problems. You can answer questions like:
对于 Windows,请查看Xperf。它使用采样配置文件,具有一些有用的用户界面,并且不需要检测。对于跟踪性能问题非常有用。您可以回答以下问题:
- Who is using the most CPU? Drill down to function name using call stacks.
- Who is allocating the most memory?
- Who is doing the most registry queries?
- Disk writes? etc.
- 谁使用的 CPU 最多?使用调用堆栈深入到函数名称。
- 谁分配的内存最多?
- 谁在进行最多的注册表查询?
- 磁盘写入?等等。
You will be quite surprised when you find the bottlenecks, as they are probably not where you expected!
当您发现瓶颈时,您会感到非常惊讶,因为它们可能不是您所期望的!
回答by rlerallut
Since you don't mention the platform you're working on, I'll say cachegrind under Linux. Definitely. It's part of the Valgrind toolset.
既然你没有提到你正在使用的平台,我就说 Linux 下的 cachegrind。确实。它是 Valgrind 工具集的一部分。
http://valgrind.org/info/tools.html
http://valgrind.org/info/tools.html
I've never used its sub-feature Callgrind, since most of my code optimization is for insidefunctions.
我从未使用过它的子功能 Callgrind,因为我的大部分代码优化都是针对内部函数的。
Note that there is a frontend KCachegrind available.
请注意,有一个可用的前端 KCachegrind。