Make callgrind show all function calls in the kcachegrind callgraph

后端 未结 3 1265
一生所求
一生所求 2020-12-18 04:47

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 functio

相关标签:
3条回答
  • 2020-12-18 05:24

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

    0 讨论(0)
  • 2020-12-18 05:25

    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.

    0 讨论(0)
  • 2020-12-18 05:37

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

    0 讨论(0)
提交回复
热议问题