Linux下的应用程序性能分析 总结

Linux下的应用程序性能分析,根据内核程序和应用程序的不同,下文分两类进行描述。

我们侧重的是应用级别的程序,推荐google perf tool/kcachegrind组合

一、和内核有关的工具

既可以处理内核,又可以处理应用的程序,但安装需要对内核代码有处理,所以有些麻烦

(一)Perf

#1 必须在root下编译

# perf

pushd /usr/src

bzip2 -d linux-source-2.6.32.tar.bz2

tar -xvf linux-source-2.6.32.tar -C .

popd

pushd /usr/src/linux-source-2.6.32/tools/perf

make

make install

popd

cp -f /root/bin/perf /usr/bin/.

perf --version

Perf -- Linux下的系统性能调优工具

http://www.ibm.com/developerworks/cn/linux/l-cn-perf1/

http://www.ibm.com/developerworks/cn/linux/l-cn-perf2/

wps_clip_image-32340

(二)Oprofile

oprofile 在 Linux 上分两部分,一个是内核模块 (oprofile.ko) ,一个为用户空间的守护进程 (oprofiled) 。前者负责访问性能计数器或者注册基于时间采样的函数 ( 使用 register_timer_hook 注册之,使时钟中断处理程序最后执行 profile_tick 时可以访问之 ) ,并采样置于内核的缓冲区内。后者在后台运行,负责从内核空间收集数据,写入文件。

http://blog.csdn.net/yili_xie/article/details/4925648

http://www.ibm.com/developerworks/cn/linux/l-oprof/

wps_clip_image-17881

(三)LTTNG

http://lttng.org/

The LTTng project aims at providing highly efficient tracing tools for Linux. Its tracers help tracking down performance issues and debugging problems involving multiple concurrent processes and threads. Tracing across multiple systems is also possible.

Apart from LTTng's kernel tracer and userspace tracer, viewing and analysis tools are part of the project. The LTTV viewer permits to analyze and show traces, both in text format and graphically.

二、应用工具

(一)Gprof (kprof)

主要的步骤:

1.在程序编译时选择-g -pg选项,插入必要的信息

2.运行程序后输出gmon.out信息

3.查看gmon.out,可以看到相关的信息

这个的效果不太好

http://blog.csdn.net/stanjiang2010/article/details/5655143

wps_clip_image-11839

(二)google perf tool (kcachegrind)

#gperftools-2.1 说明文档说明了在64下的问题

tar -xzvf libunwind-1.1.tar.gz  -C .

#libunwind 0.99 1.0.1 编译错误

pushd libunwind-1.1

./configure --prefix=/usr

make

make install

popd

rm -r -f libunwind-1.1

#gperftools-2.1

tar -xzvf gperftools-2.1.tar.gz  -C .

pushd gperftools-2.1

./configure --prefix=/usr

make

make install

popd

rm -r -f gperftools-2.1

程序中插入性能的信息

ProfilerStart("demo.prof");

benchPasrer = boost::make_shared<antlr::AntlrMSSQLParser>();

for(int i=0; i< 1000; i++){

demo();

}

ProfilerStop();

查看

pprof –text  demo demo.prof --lines

pprof --text demo demo.prof --functions

和kcachegrind 整合在一起,图形查看

% pprof –callgrind demo demo.prof > demo.callgrind

% kcachegrind demo.callgrind

wps_clip_image-5469

https://code.google.com/p/gperftools/

http://www.road2stat.com/cn/r/rprofiling.html

(三)Valgrind

http://valgrind.org/

http://www.cnblogs.com/2018/p/3228174.html

http://www.cnblogs.com/2018/p/3230736.html

 

详细资料参考

http://ajsm5iagih.l6.yunpan.cn/lk/Qn2w6bg4BgZqU  工具_Linux程序性能剖析.doc

posted @ 2013-10-21 16:25  2012  阅读(4758)  评论(0编辑  收藏  举报