10

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?

Boolean
  • 14,266
  • 30
  • 88
  • 129
  • 1
    You 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
  • 2
    possible 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 Answers6

10

Valgrind

I totally recommend this http://en.wikipedia.org/wiki/Valgrind

iamslash
  • 126
  • 1
  • 3
6

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.

Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135
3

Compile using the flag -pg and use gprof.

LiraNuna
  • 64,916
  • 15
  • 117
  • 140
1

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.

okun
  • 338
  • 3
  • 10
0

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.

learnvst
  • 15,455
  • 16
  • 74
  • 121
0

I've heard oprofile is really, really good for real time apps. Linux only though, AFAIK.

Engineer
  • 8,529
  • 7
  • 65
  • 105