task1: 最简单的 on-cpu 火焰图
首先生成最简单的 on-cpu 火焰图,参考 https://www.bilibili.com/video/BV1hg4y1o7Sb/?spm_id_from=333.337.search-card.all.click&vd_source=7a1a0bc74158c6993c7355c5490fc600
首先安装工具,这似乎是 Linux 自带的工具
sudo apt install linux-tools-common
sudo apt install linux-tools-generic
接着,生成 perf record
sudo perf record -F 99 -g ./test -- sleep 60
perf script -i perf.data > out.perf
再生成火焰图
./FlameGraph/stackcollapse-perf.pl out.perf > out.floded
./FlameGraph/flamegraph.pl out.floded > cp.svg
task2: 差分火焰图
参考:https://zhuanlan.zhihu.com/p/639996512
sudo perf record -F 99 -g ./test -- sleep 60sudo perf script -i perf.data > A.stackssudo perf record -F 99 -g ./test -- sleep 60sudo perf script -i perf.data > B.stacks
./stackcollapse-perf.pl ../A.stacks > A.folded
./stackcollapse-perf.pl ../B.stacks > B.folded
# 基于折叠结果做差
./difffolded.pl A.folded B.folded > diff.folded
# 生成差分火焰图
./flamegraph.pl diff.folded > diff.svg