问题描述
我正在使用valgrind工具-callgrind和kcachegrind来分析大型项目,并且想知道是否有一种方法可以使callgrind报告所有功能(不仅是最昂贵的功能)的统计信息.
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).
具体来说-当我在kcachegrind中可视化调用图时,它仅包含那些非常昂贵的函数,但是我想知道是否有一种方法可以将项目中的所有函数都包含在调用图中.生成分析信息的命令如下:
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
我不确定是否必须为valgrind提供任何选项,或者是否可能以其他优化方式编译应用程序.这可能有些琐碎,但我找不到解决方案.任何对此的高度赞赏.
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.
谢谢!
推荐答案
昨天发生在我身上.如图所示,我在kcachegrind的调用图中发现,有一个右键单击菜单,您可以在其中设置阈值,高于该阈值将可视化该节点.
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.
还有一个选项"no minimum",但是不能选择.我认为这也许是因为,如果每个函数(无论多么琐碎)占用一个节点,那么该图可能就太大了.
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.
我刚刚发现脚本 gprof2dot 可以解决这个问题.
该脚本可以将callgrind的输出转换为点,可以将其可视化为图形.该脚本有两个相关参数:
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
消除此阈值以下的节点[默认值:0.5].为了可视化图中的所有节点,您可以设置-n0
之类的参数. -
-e PERCENTAGE
,--edge-thres=PERCENTAGE
以消除低于此阈值的边缘(默认值:0.1).为了可视化图形中的所有边,您可以设置-e0
之类的参数
-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=PERCENTAGE
to eliminate edges below this threshold [default: 0.1]. In order to visualize all edges in the graph, you can set the parameter like-e0
为了生成完整的调用图,您将同时使用两个选项(-n0
和-e0
).
In order to generate the complete call graph you would use both of the options (-n0
and -e0
).
但是,我尝试过此操作,因为生成的图形太大,点软件警告我图形对于cairo-renderer位图太大.按0.328976缩放以适合."但是您可以设置输出格式为eps可以处理此问题.您还可以更改参数以适应您的目标.
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.
假设您有一个名为callgrind.out.1992
的callgrind输出文件.要生成完整的调用图,您可以使用:
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
要生成图形的PNG
输出图像,可以运行以下命令:
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
现在,您有一个带有完整图形的out.png
图片.
Now you have an out.png
image with the full graph.
请注意使用-f
参数指定配置文件格式(在本例中为callgrind
).
Note the usage of the -f
parameter to specify the profile format (callgrind
in our case).
这篇关于使callgrind显示kcachegrind调用图中的所有函数调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!