如何从 macOS 进程样本生成火焰图?

问题描述 投票:0回答:1

有人有将 macOS 上的示例转换为 FlameGraphs 的干净过程吗?

经过一番摆弄后,我想我也许可以使用

flamegraph-sample
之类的工具,但它似乎给我带来了一些麻烦,所以我想也许还有其他更新的选择缺少太多以至于这个工具给出了一个错误:

$ sudo sample PID -file ~/tmp/sample.txt -fullPaths 1
Sampling process 198 for 1 second with 1 millisecond of run time between samples
Sampling completed, processing symbols...
Sample analysis of process 35264 written to file ~/tmp/sample.txt

$ python stackcollapse-sample.py ~/tmp/sample.txt > ~/tmp/sample_collapsed.txt

$ flamegraph.pl ~/tmp/sample_collapsed.txt > ~/tmp/sample_collapsed_flamegraph.svg
Ignored 2335 lines with invalid format
ERROR: No stack counts found
macos sample macos-monterey dtrace flamegraph
1个回答
0
投票

以下为过程

ProcessName
生成一个适当的 10 秒样本,并附带 SVG,将 FlameGraph 克隆到
~/dev/macos/FlameGraph
,并将输出放在
~/tmp/
中,并在其上附加当前时间戳,以实现唯一性和便于参考:

sudo dtrace -x ustackframes=100 -n 'profile-10ms /execname == "ProcessName"/ { @[ustack()] = count(); } tick-10s { exit(0); }' \
| tee ~/tmp/$(date +"%Y-%m-%d_%H.%M.%S")-ProcessName_sample.txt \
| ~/dev/macos/FlameGraph/stackcollapse.pl \
| ~/dev/macos/FlameGraph/flamegraph.pl \
> ~/tmp/$(date +"%Y-%m-%d_%H.%M.%S")-WindowServer_sample.txt.svg

例如,在

WindowServer
上运行它会产生以下输出:

2023-02-20_13.06.10-WindowServer_sample.txt.svg
2023-02-20_13.06.10-WindowServer_sample.txt
© www.soinside.com 2019 - 2024. All rights reserved.