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 oprofile
2)编辑内核配置文件:.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=y
3)编译内核并重启机器
 
http://www.linuxboy.net/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.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

相关内容