一 準備html
查看內核版本nginx
uname -a
下載內核開發補丁git
http://debuginfo.centos.org/6/x86_64/ CentOS系統能夠從連接裏找本身對應內核版本的補丁github
以我虛擬機威力須要下載以下三個包shell
kernel-debug-debuginfo-2.6.32-573.el6.x86_64.rpmcentos
kernel-debuginfo-2.6.32-573.el6.x86_64.rpmbash
kernel-debuginfo-common-x86_64-2.6.32-573.el6.x86_64.rpmsvg
安裝測試
1.裝rpm包lua
rpm -ivh * yum install systemtap
2.安裝openresty
從新編譯openresty,打開debug選項
3.下載Flame-Graphic生成包
https://github.com/brendangregg/FlameGraph
二. 使用
1.測試systemtap是否安裝成功
# stap -v -e 'probe vfs.read {printf("read performed\n"); exit()}' Pass 1: parsed user script and 103 library script(s) using 201628virt/29508res/3144shr/26860data kb, in 10usr/190sys/219real ms. Pass 2: analyzed script: 1 probe(s), 1 function(s), 3 embed(s), 0 global(s) using 296120virt/124876res/4120shr/121352data kb, in 660usr/1020sys/1889real ms. Pass 3: translated to C into "/tmp/stapffFP7E/stap_82c0f95e47d351a956e1587c4dd4cee1_1459_src.c" using 296120virt/125204res/4448shr/121352data kb, in 10usr/50sys/56real ms. Pass 4: compiled C into "stap_82c0f95e47d351a956e1587c4dd4cee1_1459.ko" in 620usr/620sys/1379real ms. Pass 5: starting run. read performed Pass 5: run completed in 20usr/30sys/354real ms.
2. 畫圖
#!/bin/bash pid=$1 t=$2 filepath=$(cd "$(dirname "$0")"; pwd) echo ${filepath} cd ${filepath} ./nginx-systemtap-toolkit-master/ngx-sample-lua-bt -p ${pid} --luajit20 -t ${t} > result/tmp.bt ./nginx-systemtap-toolkit-master/fix-lua-bt result/tmp.bt > result/flame.bt ./FlameGraph-master/stackcollapse-stap.pl result/flame.bt > result/flame.cbt ./FlameGraph-master/flamegraph.pl result/flame.cbt > result/flame.svg bash /opt/flamegraph/make_svg.sh 29857 60 # 執行腳本,指定nginx其中一個線程pid,和腳本執行時間
參考連接:https://moonbingbing.gitbooks.io/openresty-best-practices/content/flame_graph/install.html