29

I am interested in getting the profiling of some number crunching program. I compiled it with -g and -pg options and linked it and got it gmon.out. After reading the info (plain text) it looks a bit ugly. I wonder if there are some open source tools for getting a graphical representation of the 10 functions where the program spends the most of the time as well as a flux diagram.

Thanks

Open the way
  • 26,225
  • 51
  • 142
  • 196

2 Answers2

31

Gprof2Dot by jrfonseca is a tool that converts the output of many profilers, amongst which gprof, into a dot graph.

Cimbali
  • 11,012
  • 1
  • 39
  • 68
msw
  • 42,753
  • 9
  • 87
  • 112
  • Wow this looks like a great tool... thanks for the link! Great answer – Sam Post Mar 13 '10 at 16:58
  • thaks a lot! Now just a short question. How can I get a graphical representation now of the control flow of the program. i mean which functions are called and in which order, and which precent is spent on each of them. thanjks – Open the way Mar 13 '10 at 17:05
  • @Werner: Does not the call graph of Gprof2Dot do that? If not I must be misunderstanding you. Or: http://code.google.com/p/jrfonseca/wiki/Gprof2Dot#Frequently_Asked_Questions – msw Mar 13 '10 at 17:19
  • By default it only shows functions that took a certain percentage of the execution and ignores many functions in the stack. With that being said, I would recommend checking out valgrind/kcachegrind (see Norman Ramsey's comment, or http://gernotklingler.com/blog/gprof-valgrind-gperftools-evaluation-tools-application-level-cpu-profiling-linux/). – cs01 Dec 21 '16 at 19:08
22

Not quite an answer to your question, but maybe a solution to your problem: I switched from gprof to valgrind's callgrind tool, primarily because of the incredible graphical tool kcachegrind, which you can use to visualize the results. It's interactive, so you can zoom in on interesting parts of the call graph.

Gprof2dot works with callgrind as well as gprof.

Norman Ramsey
  • 198,648
  • 61
  • 360
  • 533
  • 2
    But there is also the simple xdot.py which is an interactive viewer for .dot files. https://github.com/jrfonseca/xdot.py – stanm Sep 10 '14 at 10:37
  • 3
    Scratch that - so much eye candy in kcachegrind! O.O – stanm Sep 10 '14 at 12:19
  • It would be amazing if kcachegrind could open gprof output: https://stackoverflow.com/questions/7274095/view-gprof-output-in-kcachegrind – Ciro Santilli OurBigBook.com Mar 14 '20 at 05:58
  • 2
    `Callgrind` only gives instruction counts while `gprof` gives the actual time profile. I don't recommend switching to `callgrind` just for its GUI. – hansolo Apr 30 '20 at 14:27