1、下载systemtap安装包并安装
从https://sourceware.org/systemtap/ftp/releases/下载最新版的systemtap.tar.gz压缩包
我安装的时候,最新版本是3.2
wget https://sourceware.org/systemtap/ftp/releases/systemtap-3.2.tar.gz --no-check-certificate
解压
./configure
报错1
configure: error: missing elfutils development headers/libraries (install elfutils-devel, libebl-dev, libdw-dev and/or libebl-devel)
yum install elfutils-devel
报错2
configure:
configure: For a private or temporary build of systemtap, we recommend
configure: configuring with a prefix. For example, try
configure: ./configure python='/usr/bin/python' pyexecdir='${exec_prefix}/lib64/python2.6/site-packages' --prefix=/root/systemtap-3.2-9194
configure: Running systemtap uninstalled, entirely out of the build tree,
configure: is not supported../configure python='/usr/bin/python' pyexecdir='${exec_prefix}/lib64/python2.6/site-packages' --prefix=/root/systemtap-3.2-9194
make; make install
安装完成之后,在systemtap目录下,执行
stap -ve 'probe begin { log("hello systemtap!") exit() }'
如果提示pass 5: run completed ... 就表示安装成功。
2、下载
该工具包即是用perl生成stap探测脚本并运行的脚本,如果是要抓Lua级别的情况,请使用工具 ngx-sample-lua-bt
wget https://github.com/brendangregg/openresty-systemtap-toolkit/archive/master.zip --no-check-certificate
该工具包中包含多个火焰图生成工具,其中,stackcollapse-stap.pl才是为SystemTap抓取的栈信息的生成工具
wget https://github.com/brendangregg/FlameGraph/archive/master.zip --no-check-certificate
3、测试
ps -ef|grep nginx
查询nginx worker process的进程号
在openresty-systemtap-toolkit下
./ngx-sample-lua-bt -p 15010 --luajit20 -t 5 > tmp.bt (-p 是要抓的进程的pid --luajit20|--luajit51 是LuaJIT的版本 -t是探测的时间,单位是秒, 探测结果输出到tmp.bt)
./fix-lua-bt tmp.bt > flame.bt (处理ngx-sample-lua-bt的输出,使其可读性更佳)
在FlameGraph下
./stackcollapse-stap.pl flame.bt > flame.cbt
./flamegraph.pl flame.cbt > flame.svg
如果一切正常,那么会生成flame.svg,这便是火焰图,用浏览器打开即可。