# rpm -ivh kernel-debuginfo-common-($version).rpm # rpm -ivh kernel-debuginfo-($version).rpm # rpm -ivh kernel-devel-($version).rpm
其中 $version 使用 linux 命令 uname -a 查看,須要保證內核版本和上述開發包版本一致才能使用 systemtap。php
centos 7 的 debuginfo 相關 rpm 包能夠在以下連接下載:debuginfo.centos.org/7/x86_64。
kernel-devel-uanme-r 的 rpm 在該連接中下載:kernel-devel-uname-rhtml
# yum install -y systemtap # ... # 測試systemtap安裝成功否: # stap -v -e 'probe vfs.read {printf("read performed\n"); exit()}' # 出現以下信息表示安裝成功: Pass 1: parsed user script and 472 library scripts using 239992virt/41844res/3436shr/38528data kb, in 430usr/30sys/618real ms. Pass 2: analyzed script: 1 probe, 1 function, 7 embeds, 0 globals using 398364virt/193628res/2916shr/196900data kb, in 2940usr/1090sys/5956real ms. Pass 3: translated to C into "/tmp/stapxURoCZ/stap_f5b7f67a728f30f97a97a649622c8cb0_2689_src.c" using 398364virt/193968res/3256shr/196900data kb, in 30usr/90sys/144real ms. Pass 4: compiled C into "stap_f5b7f67a728f30f97a97a649622c8cb0_2689.ko" in 10490usr/1940sys/14306real ms. Pass 5: starting run. read performed Pass 5: run completed in 10usr/30sys/329real ms.
下載工具包:openresty/openresty-systemtap-toolkit,該工具包便是用 perl 生成 stap 探測腳本並運行的腳本,若是是要抓 Lua 級別的狀況,使用工具 ngx-sample-lua-bt。linux
下載工具包:brendangregg/FlameGraph,該工具包中包含多個火焰圖生成工具,其中,stackcollapse-stap.pl 纔是爲 SystemTap 抓取的棧信息的生成工具。nginx
# ps -ef | grep nginx root 1118 1 0 09:53 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf root 5693 10721 0 16:02 pts/1 00:00:00 grep --color=auto nginx root 6682 1118 0 11:15 ? 00:00:21 nginx: worker process
參數 -p 表示要抓取的進程id,-t是探測的時間,單位是秒,-u表示抓取用戶空間,對應的-k表示內核空間,探測結果輸出到 tmp.bt:git
# ./sample-bt -p 6682 -t 20 -u > tmp.bt
# cd xxx/FlameGraph/ # ./stackcollapse-stap.pl flame.bt > flame.cbt # ./flamegraph.pl flame.cbt > flame.svg
用瀏覽器打開生成的火焰圖 flame.svg 以下圖:
github