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

相关内容

    暂无相关文章