安装linux对应版本的头文件和内核调试信息

查看版本号

uname -r

安装完成如下

linux-headers-generic
linux-headers-3.10.20-xxx
linux-image-3.10.20-xxx
linux-image-3.10.20-xxx-dbg

或者

linux-headers-generic
linux-headers-3.13.0-88
linux-headers-3.13.0-88-generic
linux-image-3.13.0-88-generic
linux-image-3.13.0-88-generic-dbgsym

 

安装nginx调试信息

安装依赖库

sudo apt-get install linux-headers-generic gcc libcap-dev
sudo apt-get install elfutils
sudo apt-get install libluajit-5.1-dev
sudo apt-get install liblua5.1-0-dbg

安装systemtab

sudo apt-get install systemtap

检查安装是否成功

stap -e 'probe kernel.function("sys_open") {log("hello world") exit()}'

下载生成工具

https://github.com/openresty/nginx-systemtap-toolkit
https://github.com/brendangregg/FlameGraph

生成火焰图

ps aux | grep nginx
./nginx-systemtap-toolkit/sample-bt -p [worker-pid] -t 5 -u > a.bt

FlameGraph/stackcollapse-stap.pl a.bt > a.cbt
FlameGraph/flamegraph.pl a.cbt > a.svg

 也可以使用ngx-sample-lua-bt

参考

systemtap

nginx-systemtap-toolkit

下载

​https://github.com/openresty/nginx-systemtap-toolkit​

说明

​https://github.com/openresty/nginx-systemtap-toolkit/blob/master/README-CN.markdown#ngx-sample-bt​

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

FlameGraph

​https://github.com/brendangregg/FlameGraph​