openresty flamegraph samples

安装依赖systemtap

https://blog.csdn.net/u011944141/article/details/89512116

下载火焰图绘制相关工具

cd /opt
sudo git clone https://github.com/openresty/nginx-systemtap-toolkit.git
sudo git clone https://github.com/brendangregg/FlameGraph.git

运行案例

创建 stap_test.sh

#!/bin/bash
 
pid=$(ps aux | grep 'nginx'| grep -v 'root' | grep -v 'grep' | awk '{print $2}' |head -n 1)
sudo /opt/nginx-systemtap-toolkit/sample-bt -p ${pid} -t 60 -u > ~/a.bt
 
sudo /opt/FlameGraph/stackcollapse-stap.pl ~/a.bt > ~/a.cbt
 
sudo /opt/FlameGraph/flamegraph.pl ~/a.cbt > ~/a.svg

创建 stap_test_curl.sh (模拟访问)

  #!/bin/bash
     
    for i in {1..60}
    do
        curl http://test.jinbo.com
        curl http://test.jinbo.com/test_time
        curl http://test.qunar.com/test_ctx
        ...(多来些)
    done

或者使用ab 压测也可以

执行脚本

  • 先执行stap_test.sh,再运行 stap_test_curl.sh
  • 运行结束后,当前目录生成了 a.bt 、a.ct、a.svg
  • 浏览器打开a.svg,如下
    在这里插入图片描述
    点击某个区域的时候自动会打开,比如说点击 :ngx_procss_events_and_times上的第一个元素:ngx_event_expire_timers 如下:
    在这里插入图片描述

火焰图说明

  • Y轴表示调用栈,一个框代表一个函数,每一层都是一个函数或多个函数。调用栈越深,火焰图越高,顶部是正在执行的函数,下边都是它的父函数。
  • X轴表示采样数。从左到右不代表时间,而是所有的调用栈合并后,按字母顺序排列的。X轴占据的宽度越宽,就表示它调用次数多,或者表示耗时较多。
  • 框的颜色没有任何意义。
  • 火焰图看顶层的那个函数占据的宽度最大。
  • 子函数的宽度决定着父函数的执行宽度。
  • “平顶”则表示该函数可能存在性能问题。

其他文档

http://www.brendangregg.com/flamegraphs.html
http://www.ruanyifeng.com/blog/2017/09/flame-graph.html
https://github.com/openresty/openresty-systemtap-toolkit
https://github.com/brendangregg/FlameGraph

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值