火焰图介绍
https://www.ruanyifeng.com/blog/2017/09/flame-graph.html
火焰图生成教程
https://www.brendangregg.com/FlameGraphs/cpuflamegraphs.html
下载根据perf输出得到火焰图的可执行文件./stackcollapse-perf.pl
&./flamegraph.pl
git clone https://github.com/brendangregg/FlameGraph # or download it from github
cd FlameGraph
perf你的程序,会将数据放到./perf.data
中
sudo perf record -F 2999 -a --call-graph dwarf yourRunningCmd
# The perf record command samples at 2999 Hertz (-F 2999) across all CPUs (-a), capturing stack traces so that a call graph (-g) of function ancestry can be generated later.
# The samples are saved in a perf.data file, which are read by perf script.
# --call-graph dwarf: When "dwarf" recording is used, perf also records (user) stack dump
# when sampled. Default size of the stack dump is 8192 (bytes).
# User can change the size by passing the size after comma like
# "--call-graph dwarf,4096".
# 或者,更快一点的:
sudo perf record -F 2999 -a --call-graph fp yourRunningCmd
# --call-graph fp: faster then --call-graph dwarf
根据./perf.data
生成火焰图
sudo perf script | ./stackcollapse-perf.pl > out.perf-folded
./flamegraph.pl out.perf-folded > perf.svg
modfun上火焰图装在/home/shared/FlameGraph/
生成火焰图
sudo perf script | /home/shared/FlameGraph/stackcollapse-perf.pl > out.perf-folded
/home/shared/FlameGraph/flamegraph.pl out.perf-folded > perf.svg
火焰图分析
点击块,会expand
支持统计关键字(可正则搜索)出现的百分比,且根据选择的根块自动换算百分比
点击根块,然后ctrl+f搜索要统计的关键字,然后火焰图上就会用粉紫色高亮匹配到的块,并在右下角显示总共的百分比
且关键词支持正则搜索,比如搜Database::|getobjIDlistBysubIDpreID|getsubIDlistByobjIDpreID
自动换算是指,比如调用栈是main->fun1->fun2,统计某关键字的百分比时,点击main块得到的结果和点击fun1块得到的结果不一样