Linux下的應用程序性能分析 總結

Linux下的應用程序性能分析,根據內核程序和應用程序的不一樣,下文分兩類進行描述。html

咱們側重的是應用級別的程序,推薦google perf tool/kcachegrind組合linux

1、和內核有關的工具

既能夠處理內核,又能夠處理應用的程序,但安裝須要對內核代碼有處理,因此有些麻煩函數

(一)Perf

#1 必須在root下編譯工具

# perf性能

pushd /usr/srcgoogle

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

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

popddebug

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

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.

2、應用工具

(一)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

相關文章
相關標籤/搜索