三、Oprofile在android模拟器中的使用
1.先看一下opcontrol的参数
# opcontrol
opcontrol: usage:
-l/--list-events list event types and unit masks
-?/--help this message
-v/--version show version
--init loads the oprofile module and oprofilefs
--setup give setup arguments (may be omitted)
--status show configuration
--start-daemon start daemon without starting profiling
-s/--start start data collection
-d/--dump flush the collected profiling data
-t/--stop stop data collection
-h/--shutdown stop data collection and kill daemon
-V/--verbose[=all,sfile,arcs,samples,module,misc,ext]
be verbose in the daemon log
--reset clears out data from current session
--save=name save data from current session to session_name
--deinit unload the oprofile module and oprofilefs
-e/--event=eventspec
Choose an event. May be specified multiple times. Of the form
"default" or "name:count:unitmask:kernel:user", where :
name: event name, e.g. CPU_CLK_UNHALTED or RTC_INTERRUPTS
count: reset counter value e.g. 100000
unitmask: hardware unit mask e.g. 0x0f
kernel: whether to profile kernel: 0 or 1
user: whether to profile userspace: 0 or 1
-p/--separate=type,[types]
Separate profiles as follows :
none: no profile separation
library: separate shared library profiles per-application
kernel: same as library, plus kernel profiles
thread: per-thread/process profiles
cpu: per CPU profiles
all: all of the above
-c/--callgraph=#depth enable callgraph sample collection with a maximum depth.
Use 0 to disable callgraph profiling.
--session-dir=dir place sample database in dir instead of
default location (/var/lib/oprofile)
-i/--image=name[,names] list of binaries to profile (default is "all")
--vmlinux=file vmlinux kernel image
--no-vmlinux no kernel image (vmlinux) available
--kernel-range=start,end kernel range vma address in hexadecimal
--buffer-size=num kernel buffer size in sample units
--buffer-watershed kernel buffer watershed in sample units (2.6 only=
--cpu-buffer-size=num per-cpu buffer size in units (2.6 only)
--note-table-size kernel notes buffer size in notes units (2.4 only)
--xen Xen image (for Xen only)
--active-domains= List of domains in profiling session (for Xen only)
(list contains domain ids separated by commas)
2.使用方法
将我们之前编译好的oprofile和busybox装入模拟器
执行oprofile目录中的install.sh 将oprofile装入模拟器
adb push busybox /data/busybox
$adb shell //进入模拟器shell
#chmod 777 /data/busybox
# /data/busybox --install /data/busybox
#export PATH=/data/busybox:$PATH:/data/oprofile
# mount -o remount rw /
# mount -o rw,remount -t yaffs2 /dev/mtdblock3 /system
# touch /etc/mtab
# echo nodev /dev/oprofile oprofilefs rw 0 0>/etc/mtab
# mkdir /dev/oprofile
# mount -t oprofilefs nodev /dev/oprofile //这一句很重要,没有这一句会出现下面的错误
# 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
# opcontrol --init //初始化,只需运行一次
# opcontrol --setup --callgraph=2 --session-dir=/data/first --no-vmlinux
Using 2.6+ OProfile kernel interface.
Using log file /data/first/samples/oprofiled.log
Daemon started.
Profiler running.
# opcontrol --status
Daemon running: pid 637
Separate options: none
vmlinux file: none
Image filter: none
Call-graph depth: 2
# opcontrol --start //启动profiler
Using 2.6+ OProfile kernel interface.
Using log file /var/lib/oprofile/samples/oprofiled.log
Daemon started.
Profiler running.
# /data/test/test //运行我们的程序 ( 我的测试程序通过这条指令编译arm-none-linux-gnueabi-gcc -g -o test test.c -static -fno-omit-frame-pointer)
in c
in a
in b
in a
in c
in b
in a
in a
# opcontrol --dump //收集采样数据
# opcontrol --stop //停止profiler
Stopping profiling.
#opreport --session-dir=/data/first -l /data/test/test //查看报告
CPU: CPU with timer interrupt, speed 0 MHz (estimated)
Profiling through timer interrupt
samples % symbol name
11291 79.9589 a
1129 7.9952 b
853 6.0406 main
848 6.0052 c
现在我们就可以根据oprofile的输出对我们的程序进行优化了。
如果有哪位同学也想试一把的话,一定要用linux。这种移植环境很重要,我之前就在测试机(win7+cygwin)上浪费了很多时间。这里有打包好的工具,大家可以下载。其中kernel-qemu就是我们之前编译好的内核,替换掉Android SDK中的kernel-qemu就行了。祝各位好运!
文章来源于领测软件测试网 https://www.ltesting.net/