一 准备
查看内核版本
uname -a
下载内核开发补丁
http://debuginfo.centos.org/6/x86_64/ CentOS系统可以从链接里找自己对应内核版本的补丁
以我虚拟机威力需要下载如下三个包
kernel-debug-debuginfo-2.6.32-573.el6.x86_64.rpm
kernel-debuginfo-2.6.32-573.el6.x86_64.rpm
kernel-debuginfo-common-x86_64-2.6.32-573.el6.x86_64.rpm
安装
1.装rpm包
rpm -ivh * yum install systemtap
2.安装openresty
重新编译openresty,打开debug选项
3.下载Flame-Graphic生成包
二. 使用
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 performedPass 5: run completed in 20usr/30sys/354real ms.
2. 画图
#!/bin/bashpid=$1t=$2filepath=$(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.svgbash /opt/flamegraph/make_svg.sh 29857 60 # 执行脚本,指定nginx其中一个线程pid,和脚本执行时间
参考链接: