什么是gprof2dot
这是一个用于将许多探查器的输出转换为点图Python
脚本。
使用需要安装的依赖
- Python: known to work with version 2.7 and 3.3; it will most likely not work with earlier releases.
- Graphviz: tested with version 2.26.3, but should work fine with other versions.
Linux users 使用
On Debian/Ubuntu run:
apt-get install python3 graphviz
On RedHat/Fedora run
yum install python3 graphviz
下载方式
-
PyPI
pip install gprof2dot
-
Standalone script
-
Git repository
虚拟机Linux使用perf stat提示cycles not supported
The cpu_core/cycles/ event is not supported.
查看perf stat只显示cpu-clock, context-switches, cpu-migrations
剩余cycles, instructions, branches, branch-misses均为not supported
原因分析
该参数使用物理机可测量,猜测问题出在虚拟化。
解决方案
关闭VMware虚拟机电源,找到硬件配置选项中CPU
勾选☑️虚拟化CPU性能计数器重启问题解决
虚拟机中为什么采集不了perf
相关数据??
使用实例
使用perf
工具生成采样数据,一直想要跟踪dd
读取磁盘数据的调用栈,用perf
试试看,根据以往调试的经验,会发现perf
采集到的数据并不是非常详细的,抓的是调用流程上的主要函数,如果需要更详细的信息可以尝试使用ftrace
。
- 使用
perf
抓取采样数据
root@curtis-Aspire-E5-471G:/home/curtis/write_code/jianshou/gprof2dot# perf record -g -- dd if=/dev/sda of=./test.img bs=1M count=100 iflag=direct
100+0 records in
100+0 records out
104857600 bytes (105 MB, 100 MiB) copied, 0.349992 s, 300 MB/s
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.129 MB perf.data (577 samples) ]
- 使用
gprof2dot
生成dot图
root@curtis-Aspire-E5-471G:/home/curtis/write_code/jianshou/gprof2dot# perf script | c++filt | ./gprof2dot.py -f perf | dot -Tpng -o output.png
参数说明
root@curtis-Aspire-E5-471G:/home/curtis/write_code/jianshou/gprof2dot# ./gprof2dot.py -help
Usage:
gprof2dot.py [options] [file] ...
Options:
-h, --help show this help message and exit
-o FILE, --output=FILE
output filename [stdout](输出文件名)
-n PERCENTAGE, --node-thres=PERCENTAGE
eliminate nodes below this threshold [default: 0.5]
-e PERCENTAGE, --edge-thres=PERCENTAGE
eliminate edges below this threshold [default: 0.1]
-f FORMAT, --format=FORMAT(支持转换的文件类型)
profile format: axe, callgrind, dtrace, hprof, json,
oprofile, perf, prof, pstats, sleepy, sysprof or xperf
[default: prof]
--total=TOTALMETHOD preferred method of calculating total time: callratios
or callstacks (currently affects only perf format)
[default: callratios]
-c THEME, --colormap=THEME
color map: bw, color, gray, pink or print [default:
color]
-s, --strip strip function parameters, template parameters, and
const modifiers from demangled C++ function names
--color-nodes-by-selftime
color nodes by self time, rather than by total time
(sum of self and descendants)
-w, --wrap wrap function names
--show-samples show function samples
--node-label=MEASURE measurements to on show the node (can be specified
multiple times): self-time, self-time-percentage,
total-time or total-time-percentage [default: total-
time-percentage, self-time-percentage]
--list-functions=LIST_FUNCTIONS
list functions available for selection in -z or -l,
requires selector argument ( use '+' to select all).
Recall that the selector argument is used with
Unix/Bash globbing/pattern matching, and that entries
are formatted '<pkg>:<linenum>:<function>'. When
argument starts with '%', a dump of all available
information is performed for selected entries, after
removal of leading '%'.
-z ROOT, --root=ROOT prune call graph to show only descendants of specified
root function
-l LEAF, --leaf=LEAF prune call graph to show only ancestors of specified
leaf function
--depth=DEPTH prune call graph to show only descendants or ancestors
until specified depth
--skew=THEME_SKEW skew the colorization curve. Values < 1.0 give more
variety to lower percentages. Values > 1.0 give less
variety to lower percentages
-p FILTER_PATHS, --path=FILTER_PATHS
Filter all modules not in a specified path