yum install systemtap kernel-devel
- 找到内核版本和glibc版本
uname -r
rpm -qa |grep glibc
- 下载kernel和glibc的debuginfo包
例如centos6,到以下网页下载:
http://debuginfo.centos.org/6/x86_64/
例如:
glibc-debuginfo-common-2.12-1.192.el6.x86_64.rpm
glibc-debuginfo-2.12-1.192.el6.x86_64.rpm
kernel-debuginfo-common-x86_64-2.6.32-279.el6.x86_64.rpm
kernel-debuginfo-2.6.32-279.el6.x86_64.rpm
rpm -Uvh *.rpm
测试一下systemtap能否用:
stap -ve 'probe kernel.function("do_fork") { print("hello world\n") exit() }'
git clone https://github.com/openresty/openresty-systemtap-toolkit
git clone https://github.com/openresty/stapxx
git clone https://github.com/brendangregg/FlameGraph
# 18900是某个nginx worker进程pid
export PATH=$PATH:~/stapxx
~/stapxx/samples/lj-lua-stacks.sxx --arg time=30 --skip-badvars -x 18900 > /tmp/a.bt
~/openresty-systemtap-toolkit/fix-lua-bt /tmp/a.bt > /tmp/b.bt
~/FlameGraph/stackcollapse-stap.pl /tmp/b.bt > /tmp/b.cbt
~/FlameGraph/flamegraph.pl --encoding="ISO-8859-1" --title="Lua-land on-CPU flamegraph" /tmp/b.cbt > /tmp/b.svg
https://github.com/openresty/openresty-systemtap-toolkit#sample-bt
https://github.com/openresty/openresty-systemtap-toolkit#sample-bt-off-cpu