一、簡介
oProfile是Linux平台上的一個功能強大的性能分析工具,支持兩種采樣(sampling)方式:基於事件的采樣(eventbased)和基於時間的采樣(timebased),它可以工作在不同的體系結構上,包括MIPS、ARM、IA32、IA64和AMD。
二、安裝
1)打開內核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)編譯內核並重啟機器
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.gz cd oprofile-1.0.0 ./configure make make install
三、工具集
ophelp: 列出所有支持的事件。 opcontrol: 設置需要收集的事件。 opreport: 對結果進行統計輸出。 opannaotate:產生帶注釋的源/匯編文件,源語言級的注釋需要編譯源文件時的支持。 opstack: 產生調用圖profile,但要求x86/2.6的平台,並且linux2.6安裝了call-graph patch opgprof: 產生如gprof相似的結果。 oparchive: 將所有的原始數據文件收集打包,可以到另一台機器上進行分析。 op_import: 將采樣的數據庫文件從另一種abi轉化成本地格式。
四、使用步驟
1)啟動檢測
modprobe oprofile timer=1 opcontrol --no-vmlinux opcontrol --separate=kernelopcontrol --init opcontrol --reset opcontrol –start
2)運行程序
運行測試程序
3)停止檢測
opcontrol --dump opcontrol --stop opcontrol --shutdown opcontrol --deinit
4)檢測結果
opreport opreport -l ./test opannotate --source ./test
五、oprofile實例
1)應用程序性能測試
2)內核模塊性能測試
六、常見問題
1)oprofile抓不到數據