zoukankan      html  css  js  c++  java
  • 火焰图工具 SystemTap

    1. 安装 SystemTap

    1. 首先安装内核开发包和调试包:
    # rpm -ivh kernel-debuginfo-common-($version).rpm
    # rpm -ivh kernel-debuginfo-($version).rpm
    # rpm -ivh kernel-devel-($version).rpm
    

    其中 $version 使用 linux 命令 uname -a 查看,需要保证内核版本和上述开发包版本一致才能使用 systemtap。

    centos 7 的 debuginfo 相关 rpm 包可以在如下链接下载:debuginfo.centos.org/7/x86_64
    kernel-devel-uanme-r 的 rpm 在该链接中下载:kernel-devel-uname-r

    2. 安装 systemtap
    # yum install -y systemtap
    # ...
    # 测试systemtap安装成功否:
    # stap -v -e 'probe vfs.read {printf("read performed
    "); exit()}'
    
    # 出现如下信息表示安装成功:
    Pass 1: parsed user script and 472 library scripts using 239992virt/41844res/3436shr/38528data kb, in 430usr/30sys/618real ms.
    Pass 2: analyzed script: 1 probe, 1 function, 7 embeds, 0 globals using 398364virt/193628res/2916shr/196900data kb, in 2940usr/1090sys/5956real ms.
    Pass 3: translated to C into "/tmp/stapxURoCZ/stap_f5b7f67a728f30f97a97a649622c8cb0_2689_src.c" using 398364virt/193968res/3256shr/196900data kb, in 30usr/90sys/144real ms.
    Pass 4: compiled C into "stap_f5b7f67a728f30f97a97a649622c8cb0_2689.ko" in 10490usr/1940sys/14306real ms.
    Pass 5: starting run.
    read performed
    Pass 5: run completed in 10usr/30sys/329real ms.
    

    2. 火焰图绘制

    下载工具包:openresty/openresty-systemtap-toolkit,该工具包即是用 perl 生成 stap 探测脚本并运行的脚本,如果是要抓 Lua 级别的情况,使用工具 ngx-sample-lua-bt。

    下载工具包:brendangregg/FlameGraph,该工具包中包含多个火焰图生成工具,其中,stackcollapse-stap.pl 才是为 SystemTap 抓取的栈信息的生成工具。

    2.1 抓取 C 级别的运行状态

    1. 首先获取 nginx worker 进程的 pid
    # ps -ef | grep nginx
    root      1118     1  0 09:53 ?        00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
    root      5693 10721  0 16:02 pts/1    00:00:00 grep --color=auto nginx
    root      6682  1118  0 11:15 ?        00:00:21 nginx: worker process
    
    2. 执行如下指令

    参数 -p 表示要抓取的进程id,-t是探测的时间,单位是秒,-u表示抓取用户空间,对应的-k表示内核空间,探测结果输出到 tmp.bt:

    # ./sample-bt -p 6682 -t 20 -u > tmp.bt
    
    3. 生成火焰图:
    # cd xxx/FlameGraph/
    # ./stackcollapse-stap.pl flame.bt > flame.cbt
    # ./flamegraph.pl flame.cbt > flame.svg
    

    用浏览器打开生成的火焰图 flame.svg 如下图:

  • 相关阅读:
    装饰器函数(一)
    面向对象的初阶复习
    内置函数/反射/内置方法(单例类面)
    property特殊属性/类方法/静态方法
    多态/封装
    接口类抽象类
    初始继承之顺序/深度优先及广度优先
    类涉及的空间关系及组合(可变项地址面)
    <head></head>
    让IE6 IE7 IE8 IE9 IE10 IE11支持Bootstrap的解决方法
  • 原文地址:https://www.cnblogs.com/jimodetiantang/p/9675888.html
Copyright © 2011-2022 走看看