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文件,有的话删除

更多相关文章

  1. GitHub 标星 2.5K+!教你通过玩游戏的方式学习 VIM!
  2. 如何在后台运行Linux命令?
  3. 一款常用的 Squid 日志分析工具
  4. No.11 使用firewall配置的防火墙策略的生效模式
  5. GitHub 标星 8K+!一款开源替代 ls 的工具你值得拥有!
  6. RHEL 6 下 DHCP+TFTP+FTP+PXE+Kickstart 实现无人值守安装
  7. Linux 环境下实战 Rsync 备份工具及配置 rsync+inotify 实时同步
  8. android上代码去执行"su"命令
  9. Android文件系统编译出错记录

随机推荐

  1. Android读取本地TXT文件
  2. eoe 特刊汇总
  3. Android USB通讯(完整版)
  4. android之布局xml各种控件属性详解
  5. Android学习笔记(9)————Android的三
  6. Android Testing Point
  7. Android Wifi的使用
  8. android JNI dev
  9. Android UI控件详解-GridView(网格视图)
  10. Cheatsheet: 2013 07.21 ~ 07.31