以下工具均最好在 dev
或者说 debug
模式下进行,方便查看到具体方法调用栈。
注:以下的 xxx
均指编译后的执行文件或其名字
注2:所列工具,对 c/c++
分析也有效
cargo flamegraph
安装
使用
cargo flamegraph --no-inline --image-width 1500 --freq 1000 --bin xxx cargo flamegraph --no-inline --image-width 1500 --freq 1000 --test xxx cargo flamegraph --dev --no-inline --image-width 1500 --freq 1000 --bin xxx cargo flamegraph --dev --no-inline --image-width 1500 --freq 1000 --test xxx
|
perf
- 观察
On-CPU
事件,进行分析
- 观察
Off-CPU
事件,进行分析
安装
apt install perf yum install perf
|
使用
perf list # event list # 执行后观察 perf stat -e event1,evnet2,... ./xxx # 执行记录,事后回看 perf record -e event1,evnet2,... ./xxx perf report --stdio
|
valgrind
- 观察
On-CPU
事件,进行分析
- 观察
Off-CPU
事件,进行分析
安装
apt install valgrind yum install valgrind
|
使用
valgrind --tool=callgrind ./xxx valgrind --tool=cachegrind ./xxx
|
输出文件为 callgrind.out.<pid>
cachegrind.out.<pid>
。可通过下面将说到的 flamegraph
输出图像。也可以直接使用 kcachegrind
打开。
安装
apt install bpfcc-tools yum install bpfcc-tools
|
使用
sudo offcputime-bpfcc -df -p `pgrep -nx xxx` 60 > out.stacks
|
flamegraph.pl
安装
官网:flamegraphs,下载,解压
使用
flamegraph.pl --color=io --title="Off-CPU Time" --countname=us < out.stacks > wait.svg
|