C 和 C++ 源代码分析工具

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4141307/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 14:37:41  来源:igfitidea点击:

C and C++ source code profiling tools

c++cprofiling

提问by Alok Save

Possible Duplicate:
What's your favorite profiling tool (for C++)

可能的重复:
您最喜欢的分析工具是什么(用于 C++)

Are there any good tools to profile a source code which is mix of of C and C++. What are the pros and cons of any, and which ones have you used and would reccomend for usage. Please do not get me a list of tools from google. I can do that too, what i want is to leverage the personal experience of someone who has used these tools and knows the pros and cons about them.
Thanks in advance.

是否有任何好的工具来分析混合了 C 和 C++ 的源代码。任何优点和缺点是什么,您使用过哪些并且会推荐使用。请不要从谷歌给我一份工具列表。我也可以这样做,我想要的是利用使用过这些工具并了解它们的优缺点的人的个人经验。
提前致谢。

回答by Matt Joiner

I've found gprofto be the best CPU hotspot profiler, and Google Performance Toolsto be the best sampling profiler. Both work for C and C++.

我发现gprof是最好的 CPU 热点分析器,而Google Performance Tools是最好的采样分析器。两者都适用于 C 和 C++。

In my opinion there are no good profiling tools on Windows.

在我看来,Windows 上没有好的分析工具

GNU gprof pros and cons

GNU gprof 优缺点

  • GCC only
  • Works with C and C++
  • Only treats CPU time, and code insidethe binary, you need everything you wish to profile statically linked in
  • Very accurate
  • Adds a small overhead to execution
  • 仅海湾合作委员会
  • 适用于 C 和 C++
  • 只有把CPU时间,以及代码里面的二进制文件,你需要的一切你想在配置文件静态链接
  • 非常精准
  • 为执行增加了少量开销

Google Performance Tools pros and cons

谷歌性能工具的优缺点

  • I think it requires the GNU tool chain
  • Occasionally fails to identify symbols
  • Very customizable
  • Outputs to a huge variety of formats, including the Callgrind format, and automatically loads KCacheGrind for you
  • Has various memory profiling tools also
  • Is a samplingprofiler, with minimal overhead
  • 我认为它需要 GNU 工具链
  • 有时无法识别符号
  • 非常可定制
  • 输出为多种格式,包括 Callgrind 格式,并自动为您加载 KCacheGrind
  • 还有各种内存分析工具
  • 是一个采样分析器,开销最小

Related useful questions and answers

相关有用的问题和答案

回答by Mike Dunlavey

I would respectfully disagree with Matt.

我会恭敬地不同意马特。

The tool I use all the time on Windows is the random-pausing technique, and it works with all languages that the IDE supports.

我一直在 Windows 上使用的工具是随机暂停技术,它适用于 IDE 支持的所有语言。

As an example of using it to do performance tuning, this caseshows how a speedup of 43 times was achieved through a series of steps.

作为使用它进行性能调优的示例,本案例展示了如何通过一系列步骤实现 43 倍的加速。

Gprof has a lot of problems, listed here, and according to the google-perftools manual, some of the same issues are repeated there, such as reporting procedures, not lines, emphasizing self (local) time, emphasizing the graph, etc. (I can't tell from the doc if it samples while blocked.)

gprof有很多问题,这里列出来了,根据google-perftools手册,有一些相同的问题在那里重复了,比如上报程序,不行,强调自己(本地)时间,强调图形等(我无法从文档中判断它是否在被阻止时进行采样。)

As software systems become ever larger, self time becomes less and less relevant. The program counter spends most of its time in library routines or blocked in the system. Graphs become gigantic nests. People ask "I know function X is costly, but where in function X is the problem?" What's more, the "bottlenecks" get bigger and bigger, because the stack gets deeper on average, and every layer of the stack is a fresh opportunity to do more function calls than necessary.

随着软件系统变得越来越大,自我时间变得越来越不重要。程序计数器大部分时间都花在库例程中或在系统中被阻塞。图变成了巨大的巢穴。人们问“我知道函数 X 的开销很大,但是函数 X 的问题出在哪里?” 更重要的是,“瓶颈”越来越大,因为堆栈平均变得更深,堆栈的每一层都是一个新的机会,可以执行更多不必要的函数调用。

An example of a stack-sampler that reports percent by line, and samples while blocked, and allows user control of sampling so as not to dilute the sample set during user input, is Zoom.

堆栈采样器的一个示例是Zoom,它按行报告百分比,并在阻塞时进行采样,并允许用户控制采样以免在用户输入期间稀释样本集。

EDIT: Sorry, can't leave well enough alone. Here's a new explanation:

编辑:对不起,不能独自离开。这是一个新的解释:

The way programs work, they trace out a call tree, which is a lot like the oak tree outside my window. It has a trunk (main) which sprouts branches (call sites) which sprout further branches for several levels out to leaves (instructions) and acorns (blocking calls).

程序的工作方式,它们追踪出一个调用树,它很像我窗外的橡树。它有一个树干(主干),它长出树枝(呼叫点),这些树枝长出更多的树枝,延伸到叶子(指令)和橡子(阻塞呼叫)。

When the tree surgeon comes to prune (optimize) it, does he look only where the leaves are (hotspots)? Does he ignore acorns (no samples during blocking)? No, he looks for branches (call sites) that are both heavy (on the stack a lot) and unhealthy (unnecessary). Those are what he prunes. That's what random-pausing and Zoom do, is help find those call sites.

当树木外科医生开始修剪(优化)它时,他是否只看叶子所在的位置(热点)?他是否忽略了橡子(阻塞期间没有样本)?不,他寻找既重(在堆栈上很多)又不健康(不必要)的分支(调用点)。这些就是他修剪的东西。这就是随机暂停和缩放所做的,帮助找到那些呼叫站点。

回答by MOnsDaR

You can use Callgrindto create profiling output. It is part of Valgrind. Callgrind-output could be used with KCacheGrind, which is probably worth a look as long as you're using Linux.

您可以使用Callgrind创建分析输出。它是Valgrind 的一部分。Callgrind-output 可以与KCacheGrind一起使用,只要您使用 Linux,这可能值得一看。

回答by Vitor Py

AMD CodeAnalystis pretty nice. It's also cross platform which is nice when one finds a platform specific bottleneck.

AMD CodeAnalyst非常好。它也是跨平台的,当发现特定于平台的瓶颈时,这很好。