Linux oprofile命令
一、簡介 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 oprofile2)編輯核心設定檔:.config,將其中的# CONFIG_OPROFILE is not set改為CONFIG_OPROFILE=m(或者y)[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=y3)編譯核心並重啟機器 http://www.linuxidc.com/Linux/2014-10/108768.htm4)下載源碼,編譯安裝 wget http://cznic.dl.sourceforge.net/project/oprofile/oprofile/oprofile-1.0.0/oprofile-1.0.0.tar.gztar -zxvf oprofile-1.0.0.tar.gzcd oprofile-1.0.0./configuremakemake install 三、工具集 ophelp: 列出所有支援的事件。opcontrol: 設定需要收集的事件。opreport: 對結果進行統計輸出。opannaotate:產生帶注釋的源/彙編檔案,源語言級的注釋需要編譯源檔案時的支援。opstack: 產生調用圖profile,但要求x86/2.6的平台,並且linux2.6安裝了call-graph patchopgprof: 產生如gprof相似的結果。oparchive: 將所有的未經處理資料檔案收集打包,可以到另一台機器上進行分析。op_import: 將採樣的資料庫檔案從另一種abi轉化成本地格式。 四、使用步驟 1)啟動檢測 modprobe oprofile timer=1 opcontrol --no-vmlinuxopcontrol --separate=kernelopcontrol --init opcontrol --reset opcontrol –start2)運行程式 運行測試程式3)停止檢測 opcontrol --dumpopcontrol --stopopcontrol --shutdownopcontrol --deinit4)檢測結果 opreportopreport -l ./testopannotate --source ./test