From 7a8342a0489d3d56b1f6f2cdd13521682957cbd7 Mon Sep 17 00:00:00 2001 From: luwenpeng Date: Wed, 14 Jul 2021 10:44:54 +0000 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=84=9A=E6=9C=AC=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E7=94=9F=E4=BA=A7=E7=81=AB=E7=84=B0=E5=9B=BE=20=091?= =?UTF-8?q?=5Fcollect=5Fdata.sh=20=20=20=20:=20=E9=87=87=E9=9B=86=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=20CPU=20=E7=9A=84=E8=BF=90=E8=A1=8C=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=20=092=5Fconversion=5Fdata.sh=20=EF=BC=9A=E5=B0=86=E9=87=87?= =?UTF-8?q?=E9=9B=86=E7=9A=84=E6=95=B0=E6=8D=AE=E8=BD=AC=E5=8C=96=E6=88=90?= =?UTF-8?q?=E7=81=AB=E7=84=B0=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FlameGraph/1_collect_data.sh | 10 ++++++++++ FlameGraph/2_conversion_data.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 FlameGraph/1_collect_data.sh create mode 100644 FlameGraph/2_conversion_data.sh 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 进行关键字搜索