Linux下的應用程序性能分析,根據內核程序和應用程序的不一樣,下文分兩類進行描述。html
咱們側重的是應用級別的程序,推薦google perf tool/kcachegrind組合linux
既能夠處理內核,又能夠處理應用的程序,但安裝須要對內核代碼有處理,因此有些麻煩函數
#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/
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/
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.
主要的步驟:
1.在程序編譯時選擇-g -pg選項,插入必要的信息
2.運行程序後輸出gmon.out信息
3.查看gmon.out,能夠看到相關的信息
這個的效果不太好
http://blog.csdn.net/stanjiang2010/article/details/5655143
#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
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