在龍芯1B上使用oprofile

1.下載Oprofile源碼
# git clonegit://git.printk.org/caiwanwei/oprofile-0.9.7  (裏面有對loongson 系統 cpu 的支持)
2.編譯Oprofile(可以在x86的機器上編譯,這裏爲是省去編譯依賴庫的問題選擇在2F上編譯)
# ./configure --prefix=/usr/oprofile
checking for kernel OProfile support... no
configure: error: no suitably configured kernel include treefound

# ./configure --with-kernel-support --prefix=/usr/oprofile
# make && make install
3.移植Oprofile 到 1B 的開發板上
a.把Oprofile 編譯生成的二進制文件(opcontrol opreport ...)複製到1B 文件系統的 /bin目錄下
b.把列出來的依賴庫複製到 1B 文件系統的 /lib 目錄下
# ldd /usr/oprofile/bin/opreport (在2F 上,查詢opreport的依賴庫)
c.把相關的配置文件(/usr/oprofile/share/oprofile/mips/loongson1)複製到/usr/oprofile/share下
d.在1B 文件系統中建 root 目錄,因爲Oprofile執行時設置的事件等相關信息會記錄在/root/.oprofile/daemonrc,(怎麼知道是放在 /root/.Oprofile目錄下呢,具體可通過執行 strace oprofile --init>& 1.log ,cat 1.log 來知曉)
4.調試Oprofile
# ./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 asroot

# 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 -sf /proc/mounts /etc/mtab
# ./opcontrol --init
cpu_type 'unset' is not valid
you should upgrade oprofile or force the use of timer mod

通提示可以知道是 cpu_type,Oprofile 不認識,解決辦法是修改內核或Oprofile 源碼
# cat /dev/oprofile/cpu_type  //查看 cpu_type
mips/ls232  

由於Oprofile 裏面已經添加了loongson1 的支持,這裏修改內核源碼

# vi arch/mips/oprofile/op_model_mipsxx.c
318    case CPU_LS232:
319        //op_model_mipsxx_ops.cpu_type = "mips/ls232";
320        op_model_mipsxx_ops.cpu_type ="mips/loongson1"; 

5.使用Oprofile
# opcontrol  --init
# opcontrol --reset
# opcontrol --no-vmlinux
# opcontrol --setup --separate=kernel--event=CPU_CLK_UNHALTED:50000:0:1:1
# opcontrol --start
Using 2.6+ OProfile kernel interface.
Using log file /var/lib/oprofile/samples/oprofiled.log
Daemon started.
Profiler running.
# ./example
# opcontrol  --shutdown
Stopping profiling.
Killing daemon.
# opreport -l ./example  //生成分析文件
發佈了22 篇原創文章 · 獲贊 2 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章