Skip to content

Instantly share code, notes, and snippets.

@kingluo
Last active March 14, 2018 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kingluo/3a11af38c5ecf09fbb34a01c111523ad to your computer and use it in GitHub Desktop.
Save kingluo/3a11af38c5ecf09fbb34a01c111523ad to your computer and use it in GitHub Desktop.
ngx_lua systemtap安装

1. 先安装systemtap和kernel-devel

yum install systemtap kernel-devel

2. 安装debuginfo

  • 找到内核版本和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() }'

3. 下载openresty systemtap工具

git clone https://github.com/openresty/openresty-systemtap-toolkit
git clone https://github.com/openresty/stapxx
git clone https://github.com/brendangregg/FlameGraph

4. 生成on-CPU火焰图

# 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

5. on-cpu and off-cpu

https://github.com/openresty/openresty-systemtap-toolkit#sample-bt

https://github.com/openresty/openresty-systemtap-toolkit#sample-bt-off-cpu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment