perf分析C++性能

2019-04-10  本文已影响0人  vilian_acfc
使用脚本

#! /bin/sh

perf_ver=`perf --version`

if [[ ! $perf_ver =~ "perf version" ]]

then

  echo "perf is not installed yet. please use 'yum -y install perf' to install first."

  exit 1

fi

if [[ ! -n "$1" ]] || [[ ! -n "$2" ]]

then

echo "$0 进程id 抓取时间"

exit 1

fi

flameGraph=/data/vilian/tools/FlameGraph

output=/data/vilian/svg

file=$RANDOM

if [[ ! -d "$flameGraph" ]]

then

  echo "flameGraph is not exist. please use 'git clone https://github.com/brendangregg/FlameGraph.git' to get it."

  exit 1

fi

if [[ ! -d "$output" ]]

then

  mkdir -p $output

fi

cd $output

if [[ ! -n "perf.data" ]]

then

`rm -f perf.data`

fi

timeout $2 perf record -e cpu-clock -g -p $1

`perf script -i perf.data &> perf$file.unfold`

`$flameGraph/stackcollapse-perf.pl perf$file.unfold &> perf$file.folded`

`$flameGraph/flamegraph.pl perf$file.folded > perf$file.svg`

echo "output=$output/perf$file.svg"

上一篇下一篇

猜你喜欢

热点阅读