环境:Linux
以下几个工具都是基于FlameGraph (http://www.brendangregg.com/flamegraphs.html)来展开的。
首先安装python-flamegraph
https://github.com/evanhempel/python-flamegraph
pip/ pip3 install git+https://github.com/evanhempel/python-flamegraph.git
cd pyflame
./autogen.sh
./configure
此时运行make命令会出现提示:
Making all in src
make[1]: Entering directory `/root/pyflame/src'
make all-am
make[2]: Entering directory `/root/pyflame/src'
make[2]: Leaving directory `/root/pyflame/src'
make[1]: Leaving directory `/root/pyflame/src'
make[1]: Entering directory `/root/pyflame'
make[1]: Nothing to be done for `all-am'.
make[1]: Leaving directory `/root/pyflame'
不用管它。
继续运行:
make check
会提示以下
Making check in src
make[1]: Entering directory `/root/pyflame/src'
make[1]: Leaving directory `/root/pyflame/src'
make[1]: Entering directory `/root/pyflame'
make[1]: Nothing to be done for `check-am'.
make[1]: Leaving directory `/root/pyflame'
./runtests.sh -v
make: *** [check] Error 1
继续不用管
运行 make install
提示:
Making install in src
make[1]: Entering directory `/root/pyflame/src'
make[2]: Entering directory `/root/pyflame/src'
/usr/bin/mkdir -p '/usr/local/bin'
/bin/sh ../libtool --mode=install /usr/bin/install -c pyflame '/usr/local/bin'
libtool: install: /usr/bin/install -c pyflame /usr/local/bin/pyflame
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/root/pyflame/src'
make[1]: Leaving directory `/root/pyflame/src'
make[1]: Entering directory `/root/pyflame'
make[2]: Entering directory `/root/pyflame'
make[2]: Nothing to be done for `install-exec-am'.
/usr/bin/mkdir -p '/usr/local/share/man/man1'
/usr/bin/install -c -m 644 'docs/pyflame.man' '/usr/local/share/man/man1/pyflame.1'
make[2]: Leaving directory `/root/pyflame'
make[1]: Leaving directory `/root/pyflame'
此时要注意了:
此时运行提示里的:
/usr/bin/mkdir -p '/usr/local/bin'
/usr/bin/install -c pyflame /usr/local/bin/pyflame
即可安装成功
运行以下命令如果有输出即安装成功
pyflame -t python -c 'print(sum(i for i in range(100000)))'
4999950000
接下来安装FlameGraph
wget https://github.com/brendangregg/FlameGraph/archive/master.zip
unzip master.zip
mv FlameGraph-master/ /opt/FlameGraph
export PATH=$PATH:/opt/FlameGraph
cd /opt/FlameGraph
cp flamegraph.pl /usr/local/bin
flamegraph.pl -h
如果有以下输出,则安装成功
Option h is ambiguous (hash, height, help)
USAGE: /usr/local/bin/flamegraph.pl [options] infile > outfile.svg
--title TEXT # change title text
--subtitle TEXT # second level title (optional)
--width NUM # width of image (default 1200)
--height NUM # height of each frame (default 16)
--minwidth NUM # omit smaller functions (default 0.1 pixels)
--fonttype FONT # font type (default "Verdana")
--fontsize NUM # font size (default 12)
--countname TEXT # count type label (default "samples")
--nametype TEXT # name type label (default "Function:")
--colors PALETTE # set color palette. choices are: hot (default), mem,
# io, wakeup, chain, java, js, perl, red, green, blue,
# aqua, yellow, purple, orange
....