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

C++LinuxProfiler

C++ Problem Overview


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

C++ Solutions


Solution 1 - C++

Use gprof.

Just compile with -pg flag (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.

eg:

gcc -pg -o whatever whatever.c

./whatever

gprof whatever gmon.out

Same thing with g++ and cpp.

Solution 2 - C++

valgrind is a well-know linux profiler

Solution 3 - C++

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 optimized code.

Solution 4 - C++

I'm a fan of [Oprofile][1]. 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.

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

There is also the [Valgrind][3] suite 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.

[1]: http://oprofile.sourceforge.net/news/ "Oprofile" [2]: http://software.intel.com/en-us/intel-vtune/ "vtune" [3]: http://valgrind.org/info/tools.html "Valgrind"

Solution 5 - C++

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

[1]: https://github.com/gperftools/gperftools "google-perftools"

Solution 6 - C++

Take a look at http://kcachegrind.sourceforge.net/">KCacheGrind</a> which is a graphical frontend to http://valgrind.org/">valgrind</a> and makes it really easy to use it.

Solution 7 - C++

gprof is the standard gnu tool for profiling.

Solution 8 - C++

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

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.

Solution 9 - C++

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionshergillView Question on Stackoverflow
Solution 1 - C++smcameronView Answer on Stackoverflow
Solution 2 - C++dfaView Answer on Stackoverflow
Solution 3 - C++XWareView Answer on Stackoverflow
Solution 4 - C++FalainaView Answer on Stackoverflow
Solution 5 - C++Dirk EddelbuettelView Answer on Stackoverflow
Solution 6 - C++Milan BabuškovView Answer on Stackoverflow
Solution 7 - C++twkView Answer on Stackoverflow
Solution 8 - C++Søren SandmannView Answer on Stackoverflow
Solution 9 - C++Mike DunlaveyView Answer on Stackoverflow