现在的位置: 首页 > 综合 > 正文

Oprofile 移植到Android

2013年09月12日 ⁄ 综合 ⁄ 共 2405字 ⁄ 字号 评论关闭
Oprofile 移植

工具的编译参考
http://blog.csdn.net/louieuser/article/details/6152175

工具使用:
1.创建一个AVD,启动模拟器时,用我们编译好的kernel替换SDK自带的kernel
C:\Users\maricoliu>emulator @android2.3 -partition-size 300 -kernel ~\kernel-qemu

注:由于要向系统中push我们的程序,请分配足够的大小,否则会出现no space left on device错误,用-partition-size指定大小

2.安装busybox,Oprofile
将我们编译好的busybox和Oprofile装入模拟器
进入adb shell中,创建两个文件夹
#mkdir /data/busybox
#mkdir /data/oprofile
在控制台执行如下命令:
C:\Users\maricoliu>adb push ~\busybox /data/busybox/
Oprofile工具只要将以op开头的文件装入模拟器就可以:
C:\Users\maricoliu>adb push ~\oprofile\opcontrol /data/oprofile/
C:\Users\maricoliu>adb push ~\oprofile\opannotate /data/oprofile/
……(其余不再列出)
回到shell中,安装busybox,增加Oprofile文件的执行权限
#cd /data/busybox
#chmod 777 busybox
#./busybox –install busybox
#cd /data/oprofile
#chmod 777 op*

3.运行Oprofile
#export PATH=$PATH:/data/busybox
#export PATH=$PATH:/data/oprofile
# mount -o remount rw /
# mount -o rw,remount -t yaffs2 /dev/mtdblock3 /system
#ln -s /proc/mounts /etc/mtab  (建立一个软连接,后面有说明)
# opcontrol --init     //初始化,只需运行一次
# opcontrol --setup --callgraph=2 --session-dir=/result/ --no-vmlinux
# opcontrol --start
opcontrol --start
Using 2.6+ OProfile kernel interface.
Using log file /result/samples/oprofiled.log
Daemon started.
Profiler running.
# opcontrol --status
opcontrol --status
Daemon running: pid 773
Separate options: none
vmlinux file: none
Image filter: none
Call-graph depth: 2

运行你的程序

# opcontrol --dump   //收集采样数据
# opcontrol --stop //停止profiler
Stopping profiling.
#opreport --session-dir=/result/       //查看报告

遇到的问题:
1.出现错误 :

test: not found
id: not found
test: not found
grep: not found
test: not found
grep: not found
test: not found
…………

这是由于 Android 提供的命令过于精简,因此需要移植 busybox ,来运行 opcontrol 。按照上面的步骤安装busybox后,任然出现此错误,google后得知,要修改 opcontrol 文件如下:

BINDIR =”/data/busybox”
PATH 中加入 /data/busybox
查看opcontrol源码后发下未加入/data/busybox,现以加入

2.出现错误
./opcontrol --init
grep: /etc/mtab: No such file or directory
grep: /etc/mtab: No such file or directory
Kernel support not available, missing opcontrol --init as root

# touch /etc/mtab
# ./opcontrol  --init
Kernel support not available, missing opcontrol --init as root ?

通过对 opcontrol 的分析发现它是通过对执行" grep oprofile /proc/modules >/dev/null " 的返回值为判断条件还进行操作的,开始由于 mtab 文件里没有 oprofile 的相关信息,所以要执行 "mount -t oprofilefs nodev /dev/oprofile >/dev/null" 而linux 标准文件系统在执行了此命令之后将会与之相关的 mount 信息写入 /etc/mtab 中,而执行了umount 之后相关信息将从/etc/mtab文件中删除,而通过相关的操作之后发busybox系统中的
mtab 文件并无任何改变,通过google 之后知道原来新的busybox 使用 /proc/mounts 代替了 /etc/mtab,故在/etc 下建一个指 /proc/mounts 名为 mtab 的链接就绕过这个问题    

# ln –s /proc/mounts /etc/mtab
可能会遇到link failed file exists错误,请确保/etc/目录下面没有mtab文件,有的话删除

 
工具在本人csdn上传资源中。

抱歉!评论已关闭.