C++:perf + Flame Graph火焰图生成

1.安装FlameGraph

wget https://github.com/brendangregg/FlameGraph/archive/master.zip
unzip master.zip
sudo mv FlameGraph-master/ /opt/FlameGraph

2.添加到环境变量

export PATH=$PATH:/opt/FlameGraph

3.火焰图生成脚本

#!/bin/sh

if [ $# -lt 1 ]; then
    echo 'input pid'
    exit 1
fi

rm -f perf.*
perf record -F 99 -p $1 -g -- sleep 60
perf script -i perf.data &> perf.unfold
stackcollapse-perf.pl perf.unfold &> perf.folded
flamegraph.pl perf.folded > perf.svg

你可能感兴趣的:(C++:perf + Flame Graph火焰图生成)