27

I need a dynamic call graph for my app. I run it with callgrind tool (valgrind suite) and got callgrind.out.xxxxx file. Now, I want to make a graphical representation of this data. KCacheGrind doesn't help me much because it draws a limited part of the graph (draws ~50 functions instead of ~1500 profiled and I don't know how to fix that). How can I get a graph image where all of the functions will be drawn?

Nicolas Kaiser
  • 1,628
  • 2
  • 14
  • 26
maverik
  • 5,508
  • 3
  • 35
  • 55
  • Does the callgrind.out contain data that's missing in the graph? Also, if you sort by "self", is there relevant time/instructions left that's spent in functions not listed? I can't remember a case where relevant parts were left out. – Frank Osterfeld Feb 14 '12 at 20:49
  • Yes, callgrind.out contains all the data I need (including functions missing in the graph) and most of the functions that aren't listed in the graph have relevant time/instructions spent. Don't know why `KCacheGrind` draws only part of it. UPD: if I choose the function I want in the list of functions (placed in the left in default `KCacheGrind` layout) then graph is redrawn to display this functions, but still missing others. I need the whole graph at once. Thanks in advance. – maverik Feb 15 '12 at 07:01

2 Answers2

36

Using the following command to generate graph.png using gprof2dot

$ ./gprof2dot.py --format=callgrind --output=out.dot /path/to/callgrind.out
$ dot -Tpng out.dot -o graph.png
Mateen Ulhaq
  • 24,552
  • 19
  • 101
  • 135
samaitra
  • 724
  • 7
  • 7
33

Ok, I've found the way. The generated callgrind.out file you can convert to dot file using gprof2dot (yes, this tool can parse callgrind files as well). And then you can get the graph image using dot -T<type> dotfile.dot -o graphfile.<type>

Matthieu M.
  • 287,565
  • 48
  • 449
  • 722
maverik
  • 5,508
  • 3
  • 35
  • 55
  • Interesting. Is the generated graph readable for 1500 functions? – Frank Osterfeld Feb 15 '12 at 11:22
  • The deal is that actually I need to compare two graphs from two different versions of software, so there is no aim to read/understand the whole graph, I need only some paths and I know where I should look for them. OTOH, generation `png` image takes about 5 minutes on my `Core i7-2600 3.4GHz / 8 Gb DDR3` an resulting file's size is 23 MBytes. Not all image viewers can handle it fast and correctly (perfect stress-test IMO :) ) – maverik Feb 15 '12 at 14:44
  • 1
    are we supposed to actually type in the `-T` ? or do we replace `` with something? – nmz787 Oct 24 '17 at 19:27
  • 3
    @nmz787 yes you need to specify the type. e.g. `dot -Tsvg dotfile.dot -o graphfile.svg`. You can also use pdf or png amongst others. – Wodin Feb 24 '18 at 07:55