29

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?

2
  • 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. Commented Feb 14, 2012 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
    Commented Feb 15, 2012 at 7:01

2 Answers 2

40

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
32

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>

4
  • Interesting. Is the generated graph readable for 1500 functions? Commented Feb 15, 2012 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
    Commented Feb 15, 2012 at 14:44
  • 1
    are we supposed to actually type in the -T<type> ? or do we replace <type> with something?
    – nmz787
    Commented Oct 24, 2017 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
    Commented Feb 24, 2018 at 7:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.