perf + 火焰图分析程序性能https://www.cnblogs.com/happyliu/p/6142929.html
如何读懂火焰图?http://www.ruanyifeng.com/blog/2017/09/flame-graph.html
perf与火焰图使用介绍https://blog.csdn.net/xuhaitao23/article/details/124016932
一、可以用git将其clone下来:git clone https://github.com/brendangregg/FlameGraph.git
yum install git perf -y
git clone https://github.com/brendangregg/FlameGraph.git
我们以perf为例,看一下flamegraph的使用方法:
1、第一步
perf record -e cpu-clock -g -p pid
#Ctrl+c结束执行后,在当前目录下会生成采样数据perf.data.
或者
#采集300秒
perf record -F 99 -p $pid -g -- sleep 300
2、第二步
用perf script工具对perf.data进行解析
perf script -i perf.data &> perf.unfold
3、第三步
将perf.unfold中的符号进行折叠:
FlameGraph/stackcollapse-perf.pl perf.unfold &> perf.folded
4、最后生成svg图:
FlameGraph/flamegraph.pl perf.folded > perf.svg
5、一个例子
#!/bin/bash
pid=$1
perf record -F 99 -p $pid -g -- sleep 60
perf script > out.perf
./stackcollapse-perf.pl out.perf > out.folded
./flamegraph.pl out.folded > out.svg