什么是 Linux 上易于使用的 C++ 分析器?

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

What is a good easy to use profiler for C++ on Linux?

c++linuxprofiler

提问by shergill

I need to profile some code running C++ on Linux. Can you guys recommend some profilers?

我需要分析一些在 Linux 上运行 C++ 的代码。大家可以推荐一些profiler吗?

回答by dfa

valgrindis a well-know linux profiler

valgrind是一个著名的 linux 分析器

回答by Falaina

I'm a fan of Oprofile. It involves installing a kernel module and has a bit of a learning curve to it, but it's fairly powerful and works very well for optimized programs/programs without debugging symbols.

我是Oprofile的粉丝。它涉及安装内核模块并有一些学习曲线,但它相当强大,并且对于没有调试符号的优化程序/程序非常有效。

Vtuneis another very powerful profiler made by Intel. I believe the Linux version is free for Non-commercial software.

Vtune是英特尔制造的另一个非常强大的分析器。我相信 Linux 版本对于非商业软件是免费的。

There is also the Valgrindsuite of tools proposed by dfa. Callgrind would probably be what you're most interested in. Cachegrind(whose featureset is a subset of Callgrind's) and Massif are interesting as well, but I have no experience with the latter.

还有dfa 提出的Valgrind工具套件。Callgrind 可能是您最感兴趣的。Cachegrind(其功能集是 Callgrind 的一个子集)和 Massif 也很有趣,但我对后者没有经验。

回答by twk

gprof is the standard gnu tool for profiling.

gprof 是用于分析的标准 gnu 工具。

回答by Dirk Eddelbuettel

Google also has a nice profiler as part of the google-perftools-- which are included in Debian / Ubuntu and possibly other distros.

作为google-perftools 的一部分,Google 也有一个不错的分析器——它包含在 Debian/Ubuntu 和可能的其他发行版中。

回答by Milan Babu?kov

Take a look at KCacheGrindwhich is a graphical frontend to valgrindand makes it really easy to use it.

看一看KCacheGrind,它是valgrind的图形前端,它非常易于使用。

回答by smcameron

Use gprof.

使用 gprof。

Just compile with -pgflag (I think (but am not sure) you have to turn of optimizations though.) and use gprof to analyze the gmon.out file that your executable will then produce.

只需使用-pg标志编译(我认为(但我不确定)您必须关闭优化。)并使用 gprof 分析您的可执行文件将生成的 gmon.out 文件。

eg:

例如:

gcc -pg -o whatever whatever.c

./whatever

gprof whatever gmon.out

Same thing with g++ and cpp.

与 g++ 和 cpp 相同。

回答by XWare

Zoom from RotateRight ( http://www.rotateright.com) is what I've been using. It has a butterfly view of functions and you can double-click any function to dive into source or asm code. Build with debugging information (-g) to see your source, but you should still build and profile optimizedcode.

从 RotateRight ( http://www.rotateright.com)缩放是我一直在使用的。它具有函数的蝴蝶视图,您可以双击任何函数以深入查看源代码或汇编代码。使用调试信息 (-g) 构建以查看您的源代码,但您仍应构建和分析优化的代码。

回答by S?ren Sandmann

Take a look at Sysprof. You distribution most likely has it available already.

看看Sysprof。您的发行版很可能已经提供了它。

Note that all of the mentioned profilers work best if your application is compiled with frame pointers. That is, you should use -fno-omit-frame-pointer on the gcc command line.

请注意,如果您的应用程序是使用帧指针编译的,那么所有提到的分析器都能发挥最佳效果。也就是说,您应该在 gcc 命令行上使用 -fno-omit-frame-pointer。