diff --git a/FlameGraph/1_collect_data.sh b/FlameGraph/1_collect_data.sh new file mode 100644 index 0000000..948e515 --- /dev/null +++ b/FlameGraph/1_collect_data.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +if [ ! -n "$1" ]; then + echo "Please input CPU ID !" + exit 0 +fi + +# 执行后在当前目录下会生成采样数据 perf.data +rm -rf perf.data +perf record -e cpu-clock --call-graph dwarf -C $1 -- sleep 10 diff --git a/FlameGraph/2_conversion_data.sh b/FlameGraph/2_conversion_data.sh new file mode 100644 index 0000000..230e638 --- /dev/null +++ b/FlameGraph/2_conversion_data.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +if [ ! -f "perf.data" ]; then + echo "Please Collect data !" + exit 0 +fi + +if [ ! -d FlameGraph ]; then + echo "git clone https://github.com/brendangregg/FlameGraph.git" + git clone https://github.com/brendangregg/FlameGraph.git +fi + +rm -rf perf.unfold +rm -rf perf.folded +rm -rf perf.svg + +# 用 perf script 工具对 perf.data 进行解析 +perf script -i perf.data &> perf.unfold + +# 将 perf.unfold 中的符号进行折叠 +./FlameGraph/stackcollapse-perf.pl perf.unfold &> perf.folded + +# 生成 svg 图 +./FlameGraph/flamegraph.pl perf.folded > perf.svg + +# 使用浏览器查看 perf.svg, 在浏览器中使用 Ctrl + F 进行关键字搜索