Oprofile安装与使用探索

本文分别尝试了oprofile在x86平台和龙芯平台上的安装

 

一:oprofile的安装与配置(intel+ubuntu12.04)

I. Oprofile 安装

    Oprofile 包含在 Linux 2.6 版本的内核中,是用于 Linux 的若干种评测和性能监控工具中的一种。 也可从官方网站下载源码进行编译安装;具体安装步骤:

1. ./configure –with-kernel-support

    注:在编译过程中,这一步出现的问题是:

( 1 )缺少 libiberty.h 头文件 ; ( 2 )缺少 popt ;

    libiberty.h 头文件在 binutils-devel package 中,需要下载这个包进行安装;也可通过用 sudo apt-get install binutil-dev进行包安装。 Popt 存在 libpopt-devel package 中,同样需要进行下载安装; sudo apt-get install libpopt-dev;

 2. make

 3. make install

II. linux内核的编译(linux-2.6.27)

 1 将下载的内核放在 /usr/src 目录下;进行解压: tar -jxvf linux-source-2.6.27.tar.bz2;

  2 接下来对内核进行配置: make menuconfig

   这时候会跳出图形化的界面,需在General Setup 中的 Local version – append to kernel release 是可以自己 定制自己喜欢的内核名字; Load an Alternate Configuration File 此选项可以引用系统中的配置文件,我这里选的是/usr/src/linux-source-2.6.27/arch/x86/configs/下的一个

   注意: 这里面有一个Virtualization选项,最好把它勾掉,不然可能在后面出现 错误: 重复的成员‘padding’

3 make

 这里会出现很多问题:

(1)缺少一些包比如libncurses-dev等

  这个apt-get install 就可以了:sudo  apt-get install build-essential kernel-package  libncurses5-dev

(2)gcc: 错误: elf_i386:没有那个文件或目录

   原因是 gcc 4.6 不再支持 linker-style 架构。讲 arch/x86/vdso/Makefile 中, 将以 VDSO_LDFLAGS_vdso.lds 开头所在行的 “-m elf_x86_64″ 替换为 “-m64″。 将以 VDSO_LDFLAGS_vdso32.lds 开头所在行的 “-m elf_x86″ 替换为 “-m32″。

4  make modules_install 安装配置中选定的模块。
5  make install
6  检查是否生成 initrd 镜像文件,在 ubuntu 下并没有生成,需要在 /boot 下面使用命令:mkinitramfs -o initrd.img.2.6.27.18 生成镜像文件。

III oprofile 使用

   oprofile需要在root权限下使用

具体流程:

opcontrol –init
opcontrol –no-vmlinux   //(不用检测评测内核  ,如果需要:opcontrol –vmlinux=/src/urc/linux-2.6.27/vmlinux)

opcontrol –setup  –event=CPU_CLK_UNHALTED:10000:0  设置计数器事件

//其实这里面的event还有很多,可以根据opcontrol -l命令查看,这个设置一次就可以了

opcontrol –reset

opcontrol –start

/*这里面可能会出问题:Error: counter 0 not available nmi_watchdog using this resource ?   解决办法:opcontrol –deinit ,echo 0 > /proc/sys/kernel/watchdog,opcontrol –init  */

./bin/test  执行你的程序

opcontrol –dump 把收集到的数据写入文件

opcontrol –stop 停止profiling

opcontrol -h 关闭守护进程oprofiled

opcontrol –shutdown 停止oprofiled

opcontrol –deinit 卸载模块

得到性能数据之后,可以使用opreport, opstack, opgprof, opannotate几个工具进行分析
opreport  -l ./bin/test -o test.log   显示出分析结果

opannotate –source ./bin/test  分析源码

IV Oprofile一些命令

1  opcontrol –separate=<choice>

    <choice> 可以是以下之一:none — 不要分离档案(默认),library — 为库生成每个应用程序的档案,kernel — 为内核和内核模块生成每个应用程序的档案,all — 为库生成每个应用程序的档案,为内核和内核模块生成每个应用程序的档案

2  opcontrol –status  查看目前的设置

V 其他

 

二:oprofile的安装与配置(loongson3A+debian6.0.3+linux2.6.36.3)

    在龙芯上安装oprofile比较的麻烦,这里推荐一种比较简单的方法

I 下载最新的3A内核

release版本http://www.loongson.cn/dev/ftp/kernel/release/3A_1way/bin/

将下载的vmlinux20XX…替换掉/boot/vmlinux  (这里你最好对以前的vmliux进行备份以备不测)

重启,你的系统的内核就已经更新了

注:这是一种简单的方式,你也可以下载内核源码包,自行编译,但是那样要求一些编译环境还需要修改一些东西,比较的麻烦,不适合新手

II 下载oprofile

   这里的oprofile是从http://www.loongson.cn/dev/ftp/toolchain/oprofile/oprofile3asrc.tar.gz下载下来

III 编译oprofile

进入oprofile目录下

1.配置:./configure –with-kernel-support –disable-werror

–prefix=/usr/oprofile

2 make

   这时候可能会出现上面一样的缺失包的情况,装上就可以了

3 make install

 

这样,就在longson3A上编译成功,可以按照上面在X86上的使用方法使用oprofile

 

 

相关参考:

http://www.loongson.cn/dev/wiki/Oprofile%E6%80%A7%E8%83%BD%E5%88%86%E6%9E%90%E5%B7%A5%E5%85%B7

2  http://blog.csdn.net/yili_xie/article/details/4925648

posted @ 2013-06-17 17:06  sosohu  阅读(1661)  评论(2编辑  收藏  举报