gprof2dot perf

什么是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

下载方式

虚拟机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

  1. 使用perf抓取采样数据,如果已经安装debuginfo的时候,可以指定栈遍历的方式为dwarf

    root@curtis-Aspire-E5-471G:/home/curtis/write_code/jianshou/gprof2dot# perf record -g --call-graph dwarf -- 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) ]
    
  2. 使用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
    

在这里插入图片描述

  1. stdio,以文本的方式输出调用栈。

    perf report --stdio
    

    在这里插入图片描述

参数说明

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值