Make callgrind show all function calls in the kcachegrind callgraph

荒凉一梦 提交于 2019-11-30 22:33:42
rengar

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).

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.

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).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!