您的位置:首页 > 运维架构 > Linux

linux 性能测评 火焰图

2016-01-21 15:47 441 查看
System介绍:

主要用于诊断性能问题

systemtap介绍文章:https://www.ibm.com/developerworks/cn/linux/l-systemtap/

官网:https://sourceware.org/systemtap/

 

火焰图介绍:

火焰图将systemtap搜集到的数据以直观的方式显示出来

这里是火焰图的介绍:http://www.brendangregg.com/FlameGraphs/cpuflamegraphs.html

 

 

一:systemtap在centos 6的安装,由于修改了内核,所以中间需要重启系统

参考文档:http://www.emsperformance.net/2013/02/27/installing-systemtap-on-centos-6/

摘抄其中的关键点:

cd /etc/yum.repos.d/

vi CentOs-Debuginfo.repo,修改enabled=1

yum --disablerepo="*"--enablerepo="centosplus" install kernel.x86_64

yum install kernel-debuginfo.x86_64

reboot

yum --disablerepo="*"--enablerepo="centosplus" install kernel-devel.x86_64

最后执行stap -v -e 'probe vfs.read {printf("read performed\n");exit()}'

看到Success就成功了,否则会报错

 

二:如何使用systemtap收集数据

1:创建脚本,文件名以.stp结尾,比如ngx.stp, 我在附件中也放了一份,内容如下:

global s;

global quit = 0;

probe timer.profile {

    if (pid() == target()) {

        if (quit) {

           foreach ([u] in s) {

               print_ustack(u);

               printf("\t%d\n", @count(s[u]));

           }

           exit();

        } else {

           s[ubacktrace()] <<< 1;

        }

    }

}

probe timer.s(100) {

    quit = 1

}

上面的probe timer.s(100)是收集时间,可以根据需要修改

 

2:按以下方式执行:

stap --ldd -d/home/heda/AdResearch/syswin-AdResearch/server/src/session --all-modules -DMAXMAPENTRIES=10240 -D MAXACTION=2000000 -D MAXSKIPPED=10000000 -D MAXTRACE=100-D MAXSTRINGLEN=4096 -DSTP_NO_OVERLOAD -D MAXBACKTRACE=100 -x 12641 ngx.stp--vp 0001 >
ngx.out

其中-d后面是要捕捉的执行文件绝对路径,-x后面是可执行文件当前运行实例的进程id

 

三、使用火焰图转换工具

1:下载火焰图转换脚本文件

下载地址在:https://github.com/brendangregg/FlameGraph

2:按以下命令转换捕捉结果到svg文件

perl stackcollapse-stap.pl ngx.out > ngx.out2

perl flamegraph.pl ngx.out2 > ngx.svg

3:最后将svg文件以浏览器方式打开就可以了

 

其他

1:一个有关火焰图讨论组:https://groups.google.com/forum/#!topic/openresty/-kREoKtJwJA

2:systemtap的其它应用:http://csrd.aliapp.com/?p=893
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: