I tried to find a related question but all previous questions are about profilers for native c++ in windows. I googled a while and learned about gprof, but the output of gprof actually contained lot of obscure internal functions. Is there a good opensource c++ profiler with good documentation?
-
1You can also try manual profiling with http://code.google.com/p/profiny Its overhead should be really small compared to other tools. – user2001885 Jan 22 '13 at 23:16
-
2possible duplicate of [What can I use to profile C++ code in Linux?](http://stackoverflow.com/questions/375913/what-can-i-use-to-profile-c-code-in-linux) – user Sep 10 '13 at 12:53
6 Answers
Don't use gprof, for the reasons given here.
What you need are stackshots, explained here. One way to take stackshots is the pstack utility. Another way is to use "Pause" or ctrl-break under the debugger. Also lsstack, if you can get a copy.
If you want to spend money, RotateRight makes a nice tool based on stack sampling called Zoom.

- 40,059
- 14
- 91
- 135
-
1@MarkJ.Adams: They keep doing that, taking down unpopular stuff. I put in the archived link. – Mike Dunlavey Oct 24 '18 at 02:07
If you don't mind the KDE library dependencies, KCachegrind is very useful with the added visualization. It depends on Callgrind and Valgrind, as one could have guessed, so no special compiler flags required during compile-time.

- 338
- 3
- 10
How much detail do you need in your profile reports. If you just want to do some really simple time profiling for a few functions, then the new functionality available via the C++11 chrono
classes makes it easy to profile in a cross platform, cross compiler way.
See this article for some simple profiling code that works similarly to Matlab's super easy to use tic
and toc
functions.

- 15,455
- 16
- 74
- 121
I've heard oprofile is really, really good for real time apps. Linux only though, AFAIK.

- 8,529
- 7
- 65
- 105