openrestry 火焰图

1. 安装前的准备

  • 1.1 确定/etc/yum.repos.d/CentOS-Debuginfo.repo是否存在.

如果不存在,则创建,并写入如下内容

# CentOS-Debug.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#

# All debug packages from all the various CentOS-7 releases
# are merged into a single repo, split by BaseArch
#
# Note: packages in the debuginfo repo are currently not signed
#

[base-debuginfo]
name=CentOS-7 - Debuginfo
baseurl=http://debuginfo.centos.org/7/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Debug-7
enabled=1
#

  • 1.2 创建完成之后,执行下面命令安装
yum makecache
yum --enablerepo=base-debuginfo makecache
yum --enablerepo=base-debuginfo install -y kernel-debuginfo-$(uname -r)
yum install kernel-devel

  • 1.3 如果未安装成功,则去 https://oss.oracle.com/el6/debuginfo/ 和 http://debuginfo.centos.org/7/x86_64/ 网站下载

2. 安装SystemTAP依赖的内核模块

  • 运行下面命令stap-prep,防止以后遗漏依赖的RPM:

  • 检查工作状态, 执行 sudo stap -v -e ‘probe vfs.read {printf(“read performed\n”); exit()}’

Pass 1: parsed user script and 112 library script(s) using 206696virt/34388res/3172shr/31636data kb, in 150usr/10sys/160real ms.
Pass 2: analyzed script: 1 probe(s), 1 function(s), 4 embed(s), 0 global(s) using 303176virt/131936res/4196shr/128116data kb, in 810usr/170sys/985real ms.
Pass 3: using cached /root/.systemtap/cache/8c/stap_8c663b631dd63f195036468facfcc2d2_1625.c
Pass 4: using cached /root/.systemtap/cache/8c/stap_8c663b631dd63f195036468facfcc2d2_1625.ko
Pass 5: starting run.
read performed
Pass 5: run completed in 0usr/10sys/353real ms.

3. 安装SystemTAP

yum install -y systemtap systemtap-runtime

4. 源码编译OpenResty

  • 编译过程如下, 切记添加 "CCDEBUG=-g"
sudo make CCDEBUG=-g
sudo make install

5.开始抓取数据

sudo ./ngx-sample-lua-bt  -p 19674 -t 60 --luajit20 > a.bt

6. 生成火焰图

  • git clone https://github.com/brendangregg/FlameGraph
  • 用其中的stackcollapse-stap.pl和flamegraph.pl生成火焰图:
sudo ./stackcollapse-stap.pl a.bt > a.cbt
sudo ./flamegraph.pl a.cbt > a.svg
  • 用浏览器打开 a.svg,就可以看到效果了

openrestry 火焰图_第1张图片

火焰图的内容参考:

  1. 如何读懂火焰图?
  2. 火焰图性能分析

你可能感兴趣的:(lua,nginx)