您的位置:首页 > 运维架构

RHCA教程:rh442-2 Kernel层面的性能微调工具--Oprofile

2011-07-19 22:47 302 查看
Kernel层面的性能微调工具--Oprofile

一、用途及关键特性

1、非侵入式,无需重新编译系统.

2、Kernel层面的Profile, All code is profiled.

3、利用硬件计数器.低overhead.

二、安装

1. 硬件要求:IA-32、IA-64、AMD64、PowerPC

[align=center][/align]
#如果处理器是其他处理器,否则oprofile无法采集到数据

2. 首先需要安装内核扩展包kernel-debuginfo

[root@station8 ~]#rpm -i kernel-debuginfo-common-2.6.18-194.el5.rpm

[root@station8 ~]#rpm -i kernel-debuginfo-2.6.18-194.el5.rpm

#kernel-debug和kernel-debuginfo是两个不同的软件包,kernel-debug是kernel调试代码,kernel-debuginfo是扩展内核代码

#安装好的vmlinux在这里: /usr/lib/debug/lib/modules/2.6.18-194.el5/vmlinux

3. Oprofile安装

[root@station8 ~]# yum install oprofile.i386

[root@station8 ~]# yum install oprofile-gui.i386

三、Oprofile设置

1、设置观察事件:

opcontrol --setup --event=name:count:unitmask:kernel:user --event=xxxx

常用的事件有以下几种:

CPU_CLK_UNHALTED: CPU执行时间

LLC_MISSES: 末级Cache miss

DTLB_MISSES: 数据TLB miss准备我们的程序

[root@station8 ~]# opcontrol --setup --event CPU_CLK_UNHALTED:6000:0:0:1

#我们的程序,包括内核驱动都需要有符号信息:

#查看内核的导出的符号信息:cat /proc/kallsyms

2、初始化Oprofile

[root@station8 ~]#opcontrol --init

#加载oprofile内核模块

[root@station8 ~]#opcontrol --setup --no-vmlinux

#我们对内核的取样没兴趣,如不收件内核信息,可这样设置

[root@station8 ~]#opcontrol --setup --vmlinux=/usr/lib/debug/lib/modules/(uname –r)/vmlinux

#我们需要内核的取样,如需收件内核信息,需设置内核

四、采样数据

1、清除上一次采样到的数据

[root@station8 ~]#opcontrol --reset

2、启动oprofiled守护程序,从内核中采集数据

[root@station8 ~]#pcontrol --start

3、运行要采集其信息的应用程序

[root@station8 ~]#vim /root/ex1.c #测试程序

#include <string.h>

const char* find_str(const char* s, int l){

const char* e = s+l;

while(s <e) {

if(*s == '<') return s;

s++;

}

}

int main(int argc, char* argv[]) {

char*s = argv[1];

int i, l;

if(argc ==1) return -1;

l=strlen(s);

for(i = 0; i < 100000000; i++) find_str(s, l);

return 0;

}

[root@station8 ~]#gcc /root/ex1.c -o /root/ex1

#编译程序

[root@station8 ~]#time ./ex1 helloworld

3.143u 0.001s 0:03.14 100.0% 0+0k 0+0io 0pf+0w

#运行程序,time是计算运行程序的时间

4、中途收集采样数据

[root@station8 ~]#opcontrol –dump

#默认采集数据存放在/var/lib/oprofile/samples/下

5、关闭守护程序, 同时准备好采样的数据

[root@station8 ~]#opcontrol --stop或

[root@station8 ~]#opcontrol --shutdown

五、采样报告

[root@station8 ~]#opreport --long-filenames

#系统级别的

[root@station8 ~]#opreport image:ex1 –l

#模块级别的

[root@station8 ~]#opannotate image:ex1 –s

#源码级别的

六、最常用的命令

opcontrol --init

opcontrol --setup --no-vmlinux

opcontrol --status

opcontrol --start

opcontrol --dump

opcontrol --shutdown

opcontrol --reset

opreport --long-filenames

opreport image:filename -l

opannotate image:filename -s

转自:http://www.linuxidc.com/Linux/2011-05/35746.htm
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: