一、簡介
oPRofile是linux平臺上的一個功能強大的性能分析工具,支持兩種采樣(sampling)方式:基于事件的采樣(eventbased)和基于時間的采樣(timebased),它可以工作在不同的體系結(jié)構(gòu)上,包括MipS、ARM、IA32、IA64和AMD。
二、安裝
1)打開內(nèi)核OPROFILE選項,否則運行oProfile將提示:
[root@localhost oprofile-0.9.6]# opcontrol --init FATAL: Module oprofile not found. FATAL: Module oprofile not found. Kernel doesn't support oprofile
[root@localhost ~]# cd /usr/src/linux-2.6.37.2 [root@localhost linux-2.6.37.2]# vi .config
如下:
CONFIG_PROFILING=y CONFIG_X86_LOCAL_APIC=y CONFIG_X86_IO_APIC=y CONFIG_PCI_IOAPIC=y
3)編譯內(nèi)核并重啟機器
http://www.linuxidc.com/Linux/2014-10/108768.htm
4)下載源碼,編譯安裝
wget http://cznic.dl.sourceforge.net/project/oprofile/oprofile/oprofile-1.0.0/oprofile-1.0.0.tar.gz
tar -zxvf oprofile-1.0.0.tar.gzcd oprofile-1.0.0./configuremakemake install
三、工具集
ophelp: 列出所有支持的事件。opcontrol: 設(shè)置需要收集的事件。opreport: 對結(jié)果進行統(tǒng)計輸出。opannaotate:產(chǎn)生帶注釋的源/匯編文件,源語言級的注釋需要編譯源文件時的支持。opstack: 產(chǎn)生調(diào)用圖profile,但要求x86/2.6的平臺,并且linux2.6安裝了call-graph patchopgprof: 產(chǎn)生如gprof相似的結(jié)果。oparchive: 將所有的原始數(shù)據(jù)文件收集打包,可以到另一臺機器上進行分析。op_import: 將采樣的數(shù)據(jù)庫文件從另一種abi轉(zhuǎn)化成本地格式。
四、使用步驟
1)啟動檢測
modprobe oprofile timer=1 opcontrol --no-vmlinuxopcontrol --separate=kernelopcontrol --init opcontrol --reset opcontrol –start
2)運行程序
運行測試程序
3)停止檢測
opcontrol --dumpopcontrol --stopopcontrol --shutdownopcontrol --deinit
4)檢測結(jié)果
opreportopreport -l ./testopannotate --source ./test
五、oprofile實例
1)應(yīng)用程序性能測試
http://www.CUOXin.com/bangerlee/archive/2012/08/30/2659435.html
2)內(nèi)核模塊性能測試
http://www.oenhan.com/oprofile-cpu-analysis
六、常見問題
1)oprofile抓不到數(shù)據(jù)
http://blog.csdn.net/cybertan/article/details/8015611
參考:http://blog.chinaunix.net/uid-21768364-id-186057.html
http://www.CUOXin.com/bangerlee/archive/2012/08/30/2659435.html
http://www.oenhan.com/oprofile-cpu-analysis
新聞熱點
疑難解答
圖片精選