6

I'm just starting out with gprof and am trying to generate a call graph. I'm using cmake for setting up my makefiles and I'm setting CMAKE_EXE_LINKER_FLAGS = -gp to enable profiling. The only cxx flags I have enabled is -g.

Then I simply call gprof on my gmon.out file.

The generated output file has only a flat profile within which the calls, self ts/call and total ts/call are all empty.

More importantly, it doesn't generate a call-graph. If I try to explicitly provide -q while running gprof to generate the call-graph it says 'File is missing call-graph data'.

I'm not sure what I'm doing wrong here and would appreciate pointers on getting this fixed.

Thanks.

Vaidy
  • 61
  • 1
  • 2
  • I'm interested to know if gprof has been recommended to you, and the reasons that were given. [You can do better than gprof](http://stackoverflow.com/questions/1777556/alternatives-to-gprof/1779343#1779343). – Mike Dunlavey Oct 09 '11 at 17:59
  • gprof has not been recommended to me. I was just looking at a quick and easy way to get going and gprof looked like that to me. I did look at your post. To be frank, I was just a little lazy to read through :p I will however be taking the time to do so. – Vaidy Oct 09 '11 at 21:25
  • Different profilers do different things, and they're not all just about as good as each other. I have no stake in [Zoom](http://www.rotateright.com/) but I think, as profilers go, it's doing the right things. That is, stack sampling (not just the program counter), on wall-clock time (not just unblocked CPU time), and reporting percent by line-of-code (not by function/method). – Mike Dunlavey Oct 09 '11 at 23:50

2 Answers2

0

Possibly missing -pg when linking?

0

The proper switch for profiling is -pg, not -gp. Is this what you're doing?

Dennis
  • 14,264
  • 2
  • 48
  • 57
  • well.. I would have assumed that being switches, the characters can be interchanged. Just to be sure though, I swapped them and still can't see a call-graph – Vaidy Oct 09 '11 at 03:28
  • Also, does you program contain any functions? `gprof` won't output anything useful if there are no function... – Dennis Oct 09 '11 at 03:37
  • 2
    @Vaidy: `-pg` is a single option, not a pair of switches. GCC is a little unusual in the *nix world in that it (like some other programs that have been around for a while) doesn't use `--` for long options. – Cascabel Oct 09 '11 at 04:01
  • @Vaidy perhaps you need to recompile after changing the switches – David Feurle Oct 09 '11 at 05:16
  • @Dennis & David I cleaned up by build directory and recompiled after updating my switches. The code I'm trying to profile here is a raytracer. So yes, it contains quiet a few functions. Like I mentioned in the OP, I get a flat profile with timing for all my methods. But no call graph. Here is a link to what I get http://pastebin.com/4EYjHMEv – Vaidy Oct 09 '11 at 21:34