Oprofile 移植到Android

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上傳資源中。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章