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/
(二)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/
(三)LTTNG
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
(二)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
https://code.google.com/p/gperftools/
http://www.road2stat.com/cn/r/rprofiling.html
(三)Valgrind
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