性能分析-火焰图
ssk-wh Lv4

介绍

火焰图是一种可视化工具,用于直观地展示程序的性能瓶颈和函数调用层次。它通过图形化展示函数调用栈,使得用户可以轻松地识别性能瓶颈和分析程序的性能特征。
在Linux系统中,使用火焰图通常需要使用工具如 FlameGraph 和 perf 来生成和分析火焰图。

使用比较简单,按照下面的步骤固定操作即可

安装

安装 perf 和 FlameGraph 工具

1
2
3
4
5
6
sudo apt-get install linux-base
# 因为我的内核版本是4.19,所以安装的是linux-perf-4.19
sudo apt-get install linux-perf-4.19

# 安装 FlameGraph,用于将 perf 采集的数据生成火焰图
git clone https://github.com/brendangregg/FlameGraph.git

采集

perf record -F 99 -g -p <pid_or_command>
perf record -F 99 -g <command>

perf script | ./FlameGraph/stackcollapse-perf.pl > out.folded

./FlameGraph/flamegraph.pl out.folded > output.svg

 Comments