2010年9月20日 星期一

How to use oprofile on embedded system for Android

The detailed steps are referred from http://www.omappedia.org/wiki/Android_Debugging#OProfile
Here, I just write down the steps for my developing environment.
My developing environment is an Android platform on embedded system. So, I have a host machine and a target machine which is an embedded system with ARM based processor.

On host machine:
1. build a linux kernel enabling oprofile
2. edit $MYDROID/external/oprofile/opimport_pull (for instance $MYDROID = ~/sk886x/source/skydroid1.6/platform/) as below
Remove the python version number from the first line eg. change
      #!/usr/bin/python2.4 -E
  to
      #!/usr/bin/python -E

  Append the following lines at the end of the file to generate cpuloads.txt and callgraph.png for further analysis 
      os.system(oprofile_event_dir + "/bin/opreport --session-dir=. >> cpuloads.txt") 
      os.system(oprofile_event_dir + "/bin/opreport --session-dir=. -p $OUT/symbols -l -t 0.1 >> cpuloads.txt") 
      os.system(oprofile_event_dir + "/bin/opreport -cg --session-dir=. -p $OUT/symbols > callgraph.txt") 
      os.system("cat callgraph.txt | gprof2dot.py -s -w -f oprofile -n 0.1 -e 0.1 | dot -Tpng -o callgraph.png")  

On target machine

3. turn on busybox
# busybox ash
4. make a dummy linux vmlinux
# echo 0 > /vmlinux
5. If you see "Cannot create directory /dev/oprofile: File exists do_setup failed#", it means that, OProfile is not built in the Kernel.
# opcontrol --setup
6.
# busybox grep " _text" /proc/kallsyms 
c0023000 T _text          
# busybox grep " _etext" /proc/kallsyms 
c054e000 A _etext 
7.
# opcontrol --vmlinux=/vmlinux --kernel-range=0xc0023000,0xc054e000 --event=CPU_CYCLES:64
8.
# echo 16 > /dev/oprofile/backtrace_depth
9. check the configuration status
# opcontrol --status
10. start oprofile
opcontrol --start

11. Run your program for analyzing the performance

12. Stop oprofile
opcontrol --stop

On host machine
13.
$ cd $MYDROID 
$ source build/envsetup.sh 
$ setpaths 
$ export ADBHOST=
14.
$ mkdir ~/oprofilepackage && cd ~/oprofilepackage 
$ tar xvjf 
$ cd $MYDROID
$ source build/envsetup.sh 
$ sed -i -e 's_$(call inherit-product, frameworks/base/data/sounds/OriginalAudio.mk)_#$(call inherit-product, frameworks/base/data/sounds/OriginalAudio.mk)_g' build/target/product/AndroidProducts.mk
$ setpaths
$ export MYDROID=${PWD}
$ ln -s $MYDROID/out/target/product/sk886x $MYDROID/out/target/product/generic
15. Set soft links of vmlinux and target program, for example mplayer
$ ln -s /path/to/linux/kernel/soruce/folder/vmlinux $OUT/symbols/vmlinux 
$ ln -s /path/to/mplayer/source/folder/mplayer $OUT/sybmols/system/bin/mplayer
16. pull the oprofile result to host machine and generate the analysis report
#MYDROID/external/oprofile/opimport_pull /path/to/new/folder/to/store/dump/and/results/

Then you can see cpuloads.txt in /path/to/new/folder/to/store/dump/and/results/

沒有留言:

張貼留言