安装
yum install autoconf automake
git clone https://github.com/uber/pyflame
cd pyflame/
./autogen.sh
./configure
(MacOS出错Pyflame only supports Linux hosts)
make && make install
从https://github.com/brendangregg/FlameGraph
获取flamegraph.pl
使用
Profile PID for 60 seconds, sampling every 100ms.
pyflame -s 60 -r 0.1 PID | flamegraph.pl > myprofile.svg
或者 Trace Mode
pyflame [regular pyflame options] -t command arg1 arg2...
样例
横条越长的部分,表示被采样到的次数越多,从下往上可以看到在每一层上的函数耗时分布。
Warn
: pyflame 上采样到的部分是 CPU heavy的代码.
怎么理解?
比如 call 一个很慢的 rpc server, client 等待过程中,采集到的时间就是 IDLE.或者C扩展代码甚至进程本身就是IDLE. 等等状态,采集到的都是IDLE
资料
https://github.com/akatrevorjay/pyflame