附录1:Oprofile移植到intel xscale pxa 255开发板

一、 相关资源

根据Oprofile的官方网站,可知需要安装的库。

Required libraries :These libraries are required : popt, bfd, liberty (debian users: libiberty is provided in binutils-dev package), dl, plus the standard C++ libraries.

源码包:

busybox-1.8.1.tar.bz2

Oprofile-0.9.4.tar.gz

Popt-1.7.tar.gz

Binutils-2.19.51.0.3.tar.bz2

linux-2.6.25-android-1.0_r1.tar.gz

(在本次实验,内核直接运用经过修改(可以移植)的源码文件)

编译工具:

arm-2009q1-203-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2

二、 详细步骤:

1)通过静态交叉编译生成Oprofile的一些相关命令

oparchive opgprof opimport opreport

opannotate opcontrol ophelp opjitconv oprofiled

在交叉编译之前需要做的一些工作:

(1)打开内核的Oprofile选项

通过make menuconfig=>general setup=>

[*] Profiling support (EXPERIMENTAL)

[ ]Activate markers [*] OProfile system profiling (EXPERIMENTAL)

(2)选择安装交叉编译链

选择codeSourcery里下的Sourcery G++ Lite 2009q1-203 for ARM GNU/Linux版(arm-2009q1-203-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2)。 修改~/.bashrc添加arm-none-linux-gnueabi的路径。

PATH=$PATH: /home/kasmile/mydir/work/arm-2009q1/bin/

(3)配置编译、链接参数

export CC=arm-none-linux-gnueabi-gcc

export CXX=arm-none-linux-gnueabi-g++

export CFLAGS=-static

export CXXFLAGS=-static

export CPPFLAGS=-staitc

2)交叉编译popt

$:tar xfz popt-1.7.tar.gz

$:cd popt-1.7

$:./configure --with-kernel-support --host=arm-none-linux-gnueabi --prefix=/work/popt/poptinstall/

$:make

$:make install

cp /work/popt/poptinstall/lib/* /home/kasmile/mydir/work/arm-2009q1/arm-none-linux-gnueabi/lib

cp /work/popt/poptinstall/include/* /home/kasmile/mydir/work/arm-2009q1/arm-none-linux-gnueabi/include

3)静态交叉编译binutils

$:tar jxf binutils-2.19.51.0.3.tar.bz2

$:cd binutils-2.19.51.0.3

$:./configure --with-kernel-support --host=arm-none-linux-gnueabi --prefix=/work/binutils/binutils-2.19-install-dir/

$:make

$:make install

Cp /work/binutils/binutils-2.19-install-dir/lib/* /home/kasmile/mydir/work/arm-2009q1/arm-none-linux-gnueabi/lib

Cp /work/binutils/binutils-2.19-install-dir/include/* /home/kasmile/mydir/work/arm-2009q1/arm-none-linux-gnueabi/include

4)静态交叉编译oprofile

$: tar zxf oprofile-0.9.4.tar.gz

$:cd oprofile-0.9.4

$:/configure --with-linux=/home/kasmile/mydir/work/kernel-xscale/ --with-kernel-support --host= arm-none-linux-gnueabi --prefix=/work/myOProfile

通过1)-4)操作,可在myoprofile/bin目录下查看到一些oprofile的工具。

kasmile@kasmile:bin$ file ophelp

ophelp: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.14, not stripped。

说明:

关于为何不能运用动态链接的可执行程序?见附录4

虽然在之前指定了static参数,但是编译出来的结果仍然是动态链接的。这个是因为Oprofile在链接库时运用到了libtool工具。对于如何通过对libtool文件的修改使其直接产生静态链接的文件,目前未进行研究,而是直接安装郑老师的巧妙方法,手动编译成静态。

具体方法如下:

就ophelp命令来讲:

kasmile@kasmile:oprofile-0.9.4$ cd utils/

kasmile@kasmile:utils$ ls

Makefile Makefile.am Makefile.in opcontrol ophelp ophelp.c ophelp.o

kasmile@kasmile:utils$ rm ophelp

kasmile@kasmile:utils$ cd ..

kasmile@kasmile:oprofile-0.9.4$ make

注:由于ophelp被删除,则它要重新生产,在make过程中可以查看相关生成指令。

arm-none-linux-gnueabi-gcc -W -Wall -fno-common -Wdeclaration-after-statement -o ophelp ophelp.o ../libop/libop.a ../libutil/libutil.a /work/popt/popinstall/lib/libpopt.a -liberty -ldl -Wl,--rpath -Wl,/work/popt/popinstall/lib -Wl,--rpath -Wl,/work/popt/popinstall/lib

kasmile@kasmile:oprofile-0.9.4$ cd utils/

kasmile@kasmile:utils$ rm ophelp

kasmile@kasmile:utils$ arm-none-linux-gnueabi-gcc -W -Wall -fno-common -Wdeclaration-after-statement -o ophelp ophelp.o ../libop/libop.a ../libutil/libutil.a /work/popt/popinstall/lib/libpopt.a -liberty -ldl -Wl,--rpath -Wl,/work/popt/popinstall/lib -Wl,--rpath -Wl,/work/popt/popinstall/lib –static

kasmile@kasmile:utils$ file ophelp

ophelp: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for GNU/Linux 2.6.14, not stripped

则ophelp为静态链接,不依赖库,可以直接在开发板上运行。其他Oprofile指令相应通过手动编译生成。除其中opcontrol为shell脚本,是源码包自带的。

5移植busybox

由于要运用oprofile工具,必须先运用opcontrol进行初始化工作。而opcontrol是个shell脚本。首先修改opcontrol文件。

#!/bin/sh=>#/system/bin/sh(android的linux文件结构不太相同)

把oprofile工具放在/data/myOprofile目录下。

Export PATH=$PATH:/data/myOprofile

$:./opcontrol –init (出现错误)

test: not found

id: not found

test: not found

grep: not found

test: not found

grep: not found

test: not found

test: not found

test: not found

…………

这是由于android提供的命令过于精简,因此需要移植busybox,来运行opcontrol。

通过下载busybox最新版本,进行交叉编译。(要在make menuconfig中选择静态链接)

把busybox 复制到/data/busybox/下。

$:cd /data/busybox

$:chmod +x busybox

$:export PATH=$PATH:/data/busybox/

$:./busybox -install

修改opcontrol文件:

BINDIR =”/data/busybox”

PATH中加入/data/busybox

6oprofile初始化

#opcontrol --init

cat: can't open '/dev/oprofile/cpu_type': No such file or directory

Unable to open cpu_type file for reading

Make sure you have done opcontrol --init

cpu_type 'unset' is not valid

you should upgrade oprofile or force the use of timer mode

解决方法:

#rm /etc/mtab

#touch /etc/mtab

#vi /etc/mtab

编辑以下内容:

nodev /dev/oprofile oprofilefs rw 0 0

重新执行:

#opcontrol --init

#

到此,oprofile移植成功。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值