一 准备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