天天看點

Android移植oprofile性能監測工具

Android移植oprofile性能監測工具

關于oprofile的移植,在Ubuntu Server 10.04平台上交叉編譯,移植到Android,經過實踐,以下是交叉編譯的正确步驟,不保證在其他環境中能正确運作,以下是編譯環境:

build: Ubuntu Server 10.04

host: Android-2.2r2

cross compiler: mips-linux-gnu-gcc  version:4.3.2

cpu: mips

交叉編譯oprofile,依賴(popt,binutils);

1.Download Open Source:

  popt-1.14.tar.gz

  binutils-2.21.tar.gz

  oprofile-0.9.6.tar.gz

2.Building environment

  重要:

  touch env.sh

  vi env.sh

  内容如下:

  export PATH=/home/gzshun/share/mips-4.3/bin:$PATH  ##修改為自己的工具鍊路徑

  export CC="mips-linux-gnu-gcc -EL"

  export CXX="mips-linux-gnu-g++ -EL"

  export CFLAGS=-static

  export CXXFLAGS=-static

  export CPPFLAGS=-static

  source env.sh

3.Building popt-1.14.tar.gz

  tar zxvf popt-1.14.tar.gz

  cd popt-1.14

  ac_cv_va_copy=yes ./configure --with-kernel-support --host=mips-linux-gnu --prefix=/home/gzshun/popt

  make

  make install

以下是靜态編譯:

4.Building binutils-2.21.tar.gz

  tar zxvf binutils-2.21.tar.gz

  cd binutils-2.21

  ./configure --with-kernel-support --host=mips-linux-gnu --prefix=/home/gzshun/binutils --enable-shared

  make configure-host

  make LDFLAGS="-all-static"

  make install

5.Building oprofile-0.9.6.tar.gz

  tar zxvf oprofile-0.9.6.tar.gz

  cd oprofile-0.9.6

  ./configure --with-kernel-support --host=mips-linux-gnu --prefix=/home/gzshun/oprofile/ --with-extra-libs=/home/gzshun/popt/lib/ --with-extra-includes=/home/gzshun/popt/include/ --with-binutils=/home/gzshun/binutils

  make LDFLAGS="-all-static -L/home/gzshun/binutils/lib -Xlinker -R -Xlinker /home/gzshun/binutils/lib  -L/home/gzshun/popt/lib/"

  make install

6.添加核心oprofile子產品

  General setup  --->

    [*] Profiling support (EXPERIMENTAL)

    <*> OProfile system profiling (EXPERIMENTAL)

  将oprofile子產品編進核心,也可以程式設計子產品

開發闆性能測試篇:

1.注意

  a.在ubuntu編譯oprofile的生成路徑是:/home/gzshun/oprofile,是以在開發闆也需要建立相應的路徑

    mkdir -p /home/gzshun/

    将生成的oprofile目錄拷貝到開發闆/home/gzshun/目錄下

    ##原因:在ubuntu環境下編譯,oprofile會按照原本在ubuntu的路徑尋找需要的lib庫。(生成目錄自己定)

  b.修改oprofile/bin/opcontrol第1968行,将/usr/bin修改為/bin

  c.在Android系統中的/etc目錄下建立mtab檔案,并添加内容:nodev /dev/oprofile oprofilefs rw 0 0

  d.在開發闆設定oprofile的環境變量,必須放在PATH的前面,因為原Android系統也存在2個指令。

  e.oprofile生成報告的預設位址是:/var/lib/oprofile

2.性能測試

##Android沒有核心,是以需要從虛拟位址去引用vmlinux

  grep "_stext" /proc/kallsyms  --> result: 84000400 T _stext  ##擷取vmlinux虛拟的起始位址

  grep "_etext" /proc/kallsyms  --> result: 84342a18 A _etext  ##擷取vmlinux虛拟的結束位址

  opcontrol --init  --> 提示錯誤,挂載oprofilefs即可

  mount -t oprofilefs nodev /dev/oprofile  ##挂載oprofile需要的裝置資訊

  opcontrol --init   ##初始化

  opcontrol --reset  ##清空上次保留下來的資訊

  echo 0 > /data/vmlinux ##生成一個虛拟的vmlinux

  opcontrol --callgraph=2 --vmlinux=/data/vmlinux --kernel-range=0x84000400,0x84342a18 ##起始位址,結束位址, 跟蹤核心

  或者 opcontrol --setup --callgraph=2 --no-vmlinux ##不跟蹤 核心

  opcontrol --setup --event=CYCLES:7500:0:0:1  ##事件采樣

  opcontrol --start  ##開始測試性能

  opcontrol --status ##檢視狀态

  .....等待時間,測試

  opcontrol --dump  ##将測試性能資訊寫入磁盤。

  opreport  ##列印報告

  opcontrol --stop ##停止檢測

  opcontrol --shutdown  ##關閉檢測守護程序

  opcontrol --deinit  ##解除安裝oprofile核心子產品

opreport出來的一個例子:

分析:

Samples 采樣到的次數 

% 占的百分比

Symbol name 函數名

[email protected]:/# opreport 

Overflow stats not available

CPU: MIPS 24K, speed 0 MHz (estimated)

Counted CYCLES events (Cycles) with a unit mask of 0x00 (No unit mask) count 7500

      CYCLES:7500|

  samples|      %|

------------------

   132594 18.2787 opreport

   103155 14.2204 libdvm.so

    96514 13.3049 libc.so

    88463 12.1950 libskia.so

    79213 10.9199 app_process

              CYCLES:7500|

          samples|      %|

        ------------------

            79213 100.000 [heap] (tgid:1444 range:0x83000-0x401000)

    77023 10.6180 oprofiled

    57865  7.9770 libcutils.so

    19547  2.6946 busybox

    17571  2.4222 libwebcore.so

    13223  1.8229 libplayback.so

     9490  1.3082 libdisplay.so

     3906  0.5385 libbinder.so

     3816  0.5261 libutils.so

     3374  0.4651 ophelp

     3373  0.4650 libandroid_runtime.so

     2069  0.2852 libcore.so

     1816  0.2503 libz.so

     1648  0.2272 libsqlite.so

     1342  0.1850 dalvik-jit-code-cache (deleted)

     1141  0.1573 vmlinux

     1110  0.1530 libui.so

      975  0.1344 libsurfaceflinger.so

      840  0.1158 libGLES_android.so

      711  0.0980 libhw.so

      604  0.0833 example_display

      591  0.0815 libpixelflinger.so

      528  0.0728 libsurfaceflinger_client.so

      522  0.0720 linker

      494  0.0681 libicuuc.so

      467  0.0644 libdcchd_android.so

      293  0.0404 libnativehelper.so

      169  0.0233 libm.so

      158  0.0218 uinput

      132  0.0182 gralloc.smp86xx.so

      117  0.0161 libicui18n.so

       98  0.0135 copybit.smp86xx.so

       75  0.0103 libstdc++.so

       58  0.0080 libEGL.so

       58  0.0080 libhardware.so

       57  0.0079 libGLESv1_CM.so

       46  0.0063 librmlibplay_default_plugin.so

       35  0.0048 opjitconv

       32  0.0044 libandroid_servers.so

       22  0.0030 libhardware_legacy.so

       15  0.0021 liblog.so

       11  0.0015 servicemanager

       10  0.0014 libmedia.so

        9  0.0012 adbd

        8  0.0011 logwrapper

        5 6.9e-04 libmediaplayerservice.so

        4 5.5e-04 libmedia_jni.so

        3 4.1e-04 libsysutils.so

        1 1.4e-04 init

        1 1.4e-04 libemoji.so