diff --git a/FlameGraph/1_collect_data.sh b/FlameGraph/1_collect_data.sh deleted file mode 100644 index 948e515..0000000 --- a/FlameGraph/1_collect_data.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/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 deleted file mode 100644 index 230e638..0000000 --- a/FlameGraph/2_conversion_data.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/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 进行关键字搜索 diff --git a/FlameGraph/run_flamegrah.sh b/FlameGraph/run_flamegrah.sh new file mode 100644 index 0000000..7ce4244 --- /dev/null +++ b/FlameGraph/run_flamegrah.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +usage() +{ + printf "Usage: $0 [opt] [val]\n\n" + printf " -c cpuid Collect data of the specified cpu id\n" + printf " -t threadid Collect data of the specified thread id\n" + printf " -p processid Collect data of the specified process id\n" + printf " -h Help\e[0m\n\n" + exit 0 +} + +if [ ! -n "$1" ] || [ ! -n "$2" ]; then + usage +fi + +opt_type="h" +while getopts c:t:p:h opt +do + case $opt in + c) opt_type="c" ;; + t) opt_type="t" ;; + p) opt_type="p" ;; + h|?) usage ;; + esac +done + +# 执行后在当前目录下会生成采样数据 perf.data +rm -rf perf.data + +if [ $opt_type == "c" ]; then + printf "\e[32m Collect data on cpu $2\e[0m\n" + perf record -e cpu-clock --call-graph dwarf -C $2 -- sleep 5 +elif [ $opt_type == "t" ]; then + printf "\e[32m Collect data on thread $2\e[0m\n" + perf record -e cpu-clock --call-graph dwarf -t $2 -- sleep 5 +elif [ $opt_type == "p" ]; then + printf "\e[32m Collect data on process $2\e[0m\n" + perf record -e cpu-clock --call-graph dwarf -p $2 -- sleep 5 +else + usage +fi + +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 + +printf "\e[32m Convert data to flame graph\e[0m\n" + +# 用 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 进行关键字搜索 diff --git a/FlameGraph/run_flamegrap.sh b/FlameGraph/run_flamegrap.sh deleted file mode 100644 index dddd207..0000000 --- a/FlameGraph/run_flamegrap.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -if [ ! -n "$1" ] ;then - echo "Please input pid !" - exit 0 -fi - -rm -rf perf.data out.perf-folded result.svg - -perf record -F 99 -p $1 -g -- sleep 10 -perf script | FlameGraph-master/stackcollapse-perf.pl > out.perf-folded -FlameGraph-master/flamegraph.pl out.perf-folded > result.svg