Make callgrind show all function calls in the kcachegrind callgraph
Asked Answered
P

3

8

I was using valgrind tool - callgrind and kcachegrind for profiling a large project and was wondering if there is a way that callgrind reports the stats from all the functions (not just the most expensive functions).

To be specific - When I visualized the callgraph in kcachegrind, it included only those functions that are quite expensive, but I was wondering if there is a way to include all the functions from the project in the callgraph. Command used for generating profiling info is given below :

valgrind --dsymutil=yes --tool=callgrind $EXE 

I am not sure if I have to give any options to valgrind or may be compile the application at a different optimization. This might be something trivial but I couldn't find a solution. Any pointers regarding this highly appreciated.

Thanks !

Prune answered 17/11, 2015 at 23:51 Comment(1)
Kcachegrind will hide functions with small weight (some limits can be changed with main menu - settings - like count of items in lists; some - with context menu on graph tabs). You can also try callgrind_annotate console tool which has no limits.Sewn
S
8

enter image description here

It occurred to me yesterday. As shown in the picture, I found in call graph of kcachegrind, there is a right click menu, in which you can set up the threshold above which the node will be visualized.

There is also a option "no minimum", however it can not be chosen. I think maybe it's because, if every function, no matter how trivial it is, takes up a node, the graph may be too large to handle.

I just found that the script gprof2dot can handle this.
The script can convert the output of callgrind to dot, which can be visualized as graph. The script has two relevant parameters:

  • -n PERCENTAGE, --node-thres=PERCENTAGE to eliminate nodes below this threshold [default: 0.5]. In order to visualize all nodes in the graph, you can set the parameter like -n0
  • -e PERCENTAGE, --edge-thres=PERCENTAGEto eliminate edges below this threshold [default: 0.1]. In order to visualize all edges in the graph, you can set the parameter like -e0

In order to generate the complete call graph you would use both of the options (-n0 and -e0).

I've tried this, however, as the graph generated is too large, the dot software warned me that "graph is too large for cairo-renderer bitmaps. Scaling by 0.328976 to fit. " But you can set up the output format as eps which can handle this. You also can change the parameter to adapt your objective.

Example

Let's say that you have a callgrind output file called callgrind.out.1992. To generate a complete call graph you would use:

gprof2dot.py -n0 -e0 ./callgrind.out.1992 -f callgrind

To generate a PNG output image of the graph, you could run the following commands:

gprof2dot -n0 -e0 ./callgrind.out.1992 -f callgrind > out.dot

dot -Tpng out.dot -o out.png

Now you have an out.png image with the full graph.

Note the usage of the -f parameter to specify the profile format (callgrind in our case).

Sissel answered 10/5, 2017 at 12:14 Comment(1)
can't comment yet, here's the solution to > There is also a option "no minimum", however it can not be chosen. from rengar's answer: stackoverflow.com/questions/29449548/…Boucicault
B
7

The command I am using is valgrind --tool=callgrind --dump-instr=yes --collect-jumps=yes $EXE and as far as I have seen it includes all the functions in the call graph.

Hope it helps.

Blacktail answered 25/2, 2016 at 16:17 Comment(0)
D
1

I'm going to complete rengar's answer with information that will allow you to generate the complete call graph, as well as give an example of the full process.

You can use the gprof2dot to show all functions in a callgraph. The script can convert the output of callgrind to dot, which can be visualized as graph. The script has two relevant parameters:

  • -n PERCENTAGE, --node-thres=PERCENTAGE to eliminate nodes below this threshold [default: 0.5]. In order to visualize all nodes in the graph you should set this parameter to -n0
  • -e PERCENTAGE, --edge-thres=PERCENTAGEto eliminate edges below this threshold [default: 0.1]. In order to visualize all edges in the graph you should set this parameter to -e0

In order to generate the complete call graph you would use both of the options: -n0 and -e0.

Example

Let's say that you have a callgrind output file called callgrind.out.1992. To generate a complete call graph you would use:

gprof2dot -n0 -e0 ./callgrind.out.1992 -f callgrind

To generate a PNG output image of the graph, you could run the following commands:

gprof2dot -n0 -e0 ./callgrind.out.1992 -f callgrind > out.dot

dot -Tpng out.dot -o out.png

Now you have an out.png image with the full graph.

Note the usage of the -f parameter to specify the profile format (callgrind in our case).

Donte answered 19/3, 2018 at 18:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.