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?
问题:
回答1:
Valgrind
I totally recommend this http://en.wikipedia.org/wiki/Valgrind
回答2:
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.
回答3:
Compile using the flag -pg
and use gprof
.
回答4:
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.
回答5:
I've heard oprofile is really, really good for real time apps. Linux only though, AFAIK.
回答6:
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.