1. 安裝perf
sudo apt-get install linux-tools-common linux-tools-generic linux-tools-`uname -r`
2. 安裝火焰圖工具
git clone //github.com/brendangregg/FlameGraph.git
3. 繪制火焰圖
PID=$(ps aux | grep 'nginx: worker process' | grep -v grep | awk '{print $2}' | head -n 1)
perf record -F max -p $PID -a -g -- sleep 30
perf script > out.perf
./FlameGraph/stackcollapse-perf.pl out.perf > out.folded
./FlameGraph/flamegraph.pl --width=3000 out.folded > flamegraph.svg
rm out.perf out.folded
4. 查看火焰圖
使用Chrome瀏覽器打開flamegraph.svg即可