simpleperf和火焰图的使用

抓取perf

simpleperf stat 抓取-- 统计

simpleperf stat -e cpu-cycles -p 2589 --duration 10

simpleperf record 抓取记录 – 细节数据

adb shell simpleperf record -p 1791 -g --duration 10 --call-graph fp -o /sdcard/perf.data
//  simpleperf record -p [PID] -f [sample/s] --duration [Time]
// 1791 是pid; duration 10 : 10s
//camerahal:  simpleperf record -g -p `pidof camerahalserver` -f 1000000 --duration 10 -e instructions --call-graph fp -o /sdcard/perf.data
adb pull /sdcard/perf.data ./

扩展

在simpleperf工具中,使用"-e"选项可以指定要收集的事件。这里列举了一些常用的事件选项:
cpu-cycles:收集CPU周期计数数据。
instructions:收集指令计数数据。
cache-references:收集缓存引用计数数据。
cache-misses:收集缓存缺失计数数据。
branch-instructions:收集分支指令计数数据。
branch-misses:收集分支缺失计数数据。
page-faults:收集页面错误计数数据。
context-switches:收集上下文切换计数数据。

simpleperf report 生成报告

分析生成report.txt

adb shell "simpleperf report -i /sdcard/perf.data -o /sdcard/report.txt"
adb shell "simpleperf report -g -i /sdcard/perf.data -o /sdcard/report_g.txt"

生成调用关系图

simpleperf report -g --symfs . >report

过滤输出

$simpleperf report --comms sudogame
# Report records in process 7394 or 7395
$simpleperf report --pids 7394,7395
 
# Report records in thread 7394 or 7395.
$simpleperf report --tids 7394,7395

排序输出

// 最耗时的共享库文件
adb shell "simpleperf report --sort dso -i /sdcard/perf.data"
// 按 %, 函数,库 排序
adb shell "simpleperf report --sort symbol,dso -i ./sdcard/perf.data"
// 单个共享库中最耗时的函数。需要全部路径/vendor/lib64/lib3a.af.so
adb shell "simpleperf report --dsos /vendor/lib64/lib3a.af.so --sort symbol  -i /sdcard/perf.data"

pull出perf结果

adb pull ./sdcard/perf.data
adb pull ./sdcard/report.txt

生成火焰图

生成report.html

谷歌官网下载Android NDK: https://developer.android.google.cn/ndk/downloads/
进入到android-ndk-r25b-linux/android-ndk-r25b/simpleperf
将上述生产的perf.data文件拉取出来放到这个同级目录下
adb pull /sdcard/perf.data
直接运行
python report_html.py -i ./perf.data -o ./perf.html

生成火焰图

python ./simpleperf/report_sample.py > out.perf
./FlameGraph/stackcollapse-perf.pl out.perf > out.folded
./FlameGraph/flamegraph.pl out.folded > out.svg

扩展事件

SimpleperfSimpleperf事件分析
⼀、list帮助⽂档
输⼊命令:./simpleperf help list
Usage: simpleperf list [options] [hw|sw|cache|raw|tracepoint]
List all available event types.
Filters can be used to show only event types belong to selected types:
hw          hardware events
sw           software events
cache        hardware cache events
raw          raw cpu pmu events
tracepoint   tracepoint events
cs-etm       coresight etm instruction tracing events
这里PMU事件,处理器性能监视器单元(PMU)可以检测到的信息有限:比如CPU指令数是可以读取寄存器,cpu cycle数可以,硬件上有专门的计数器。对访问ddr的带宽,可以统计到访问ddr的次数和读取的数据大小。

对数据访问

  raw-bus-access                # bus access 包含硬件CPU+GPU对bus的访问,指的是原始总线访问次数
  raw-l1-dcache         # level 1 data cache access L1数据缓存的原始访问次数
  raw-l1-dtlb           # level 1 data or unified TLB access
  raw-l1-icache         # level 1 instruction cache access
  raw-l1-itlb           # level 1 instruction TLB access
  raw-l2-dcache         # level 2 data cache access L2数据缓存的原始访问次数
  raw-l2-dtlb           # level 2 data or unified TLB access
  raw-l2-itlb           # level 2 instruction TLB access
  raw-l3-dcache         # level 3 data or unified cache access L3数据缓存的原始访问次数
  raw-mem-access                # data memory access  数据内存访问次数

raw-bus-access ,bus访问在Arm处理器上不包括L1的部分
raw-mem-access
raw-l3-dcache
raw-l1-dcache
raw-l2-dcache

CPU访问ddr带宽: = raw-mem-access * 128bit / duration
BUS总带宽(含有CPU+GPU+…): = raw-bus-access * 128bit / duration

参考文档

https://gaozhipeng.me/posts/simple-perf-4/ 推荐
https://blog.csdn.net/tq08g2z/article/details/77311712 推荐
https://www.freesion.com/article/14261068445/
SimpleperfSimpleperf事件分析:
https://wenku.baidu.com/view/719a0ae54328915f804d2b160b4e767f5acf8099.html?wkts=1691803485989&bdQuery=SimpleperfSimpleperf%E4%BA%8B%E4%BB%B6%E5%88%86%E6%9E%90

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值