【工具】Perf性能分析工具火焰图生成

Perf,一款性能剖析工具。

安装步骤

当前环境为:ubuntu18.04

  • 安装perf工具,使用命令
sudo apt-get install linux-tools-common

运行perf指令,提示缺少模块,如下:

  • 安装工具:
sudo apt-get install linux-tools-5.4.0-107-generic
sudo apt-get install linux-cloud-tools-5.4.0-generic
sudo apt-get install linux-tools-generic
sudo apt-get install linux-cloud-tools-generic

输入perf指令,然后发现安装成功:

 

Perf操作指令 

Record指令:

  • 每秒采集99次,进行录制,保存文件默认为perf.data,保存到控制台开启的当前目录下。
# Sample on-CPU functions for the specified command, at 99 Hertz:
perf record -F 99

 

Perf火焰图查看工具

  • 使用Github上的开源工具,FlameGraph,地址:
git clone https://github.com/brendangregg/FlameGraph.git
  • 生成火焰图 

 eg:例如使用perf record -F 99 -a -g 生成一段数据,结果保存在perf.data中

# 给perf文件权限,登录到su权限下
chmod -R 777 perf.data 

# 转换成out.perf文件
sudo perf script -i perf.data > out.perf

# 利用工具转换为out.folded文件
FlameGraph/stackcollapse-perf.pl out.perf  > out.floded

#转换为svg文件
FlameGraph/flamegraph.pl out.floded > out.svg

如果遇到权限问题,记得给777权限

效果如下:

 

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值