OProfile在Andorid上使用以及PC分析环境

来源:互联网 发布:手机桌面软件 知乎 编辑:程序博客网 时间:2024/05/22 06:04

转载

OProfile作为一个Linux的工具,可以分析kernel和应用的性能。因此如何将OProfile应用于Android对于发现并解决Android的性能问题具有很重要的意义。本文以下将介绍如何在Android上应用OProfile。

 

一、设备准备

      一个能运行Android系统的设备:作为运行Android的设备。

      一个装有Linux系统(最好是Ubuntu)的PC机:与Android系统相连,作为Host。

 

二、软件准备

      PC机准备:

      1、安装编译OProfile所需的库

           sudo apt-get install binutils-dev

           sudo apt-get install libpopt-dev3

 

      2、解压OProfile Helper。假设PC上Android code的目录为 android。

           cd  android/

           tar xvfz oprofile.tar.gz

           cd oprofile

 

      3、下载OProfile

           wget http://prdownloads.sourceforge.net/oprofile/oprofile-0.9.6.tar.gz

 

      4、解压缩OProfile,并编译

           tar xvfz oprofile-0.9.6.tar.gz

           cd oprofile-0.9.6

           ./configure

           make

 

      5、建立OProfile所需的目录

           export OPR_DIR=android/oprofile/oprofile-0.9.6/host

           mkdir -p $OPR_DIR/bin

           mkdir -p $OPR_DIR/abi

           mkdir -p $OPR_DIR/arm

           cp android/oprofile/arm_abi $OPR_DIR/abi

           cp $OPR_DIR/../libabi/opimport $OPR_DIR/bin

           cp $OPR_DIR/../pp/opreport $OPR_DIR/bin

           cp -r $OPR_DIR/../events/arm/* $OPR_DIR/arm          

     

       6、将OProfile加入Android编译系统

           copy -r  $OPR_DIR/* /demodroid/prebuilt/linux-x86/oprofile
          

 

       7、将编译好的Androd系统放到可以运行Android的设备上。

 

三、用OProfile测试

       1、启动adb shell

            adb remount

            adb shell

 

       2、配置OProfile

            opcontrol --setup

            oprofiled --session-dir=/data/oprofile --no-vmlinux -e CPU_CYCLES

            opcontrol和oprofiled在/system/xbin目录下

 

            如果正确执行,将输出:

            Using 2.6+ OProfile kernel interface.

            Reading module info.

            Using log file /data/oprofile/samples/oprofiled.log
            如果没有正确执行,则输出:

            Cannot create directory /dev/oprofile: File exists

            do_setup failed#

            这说明,在设备上运行的Android系统不支持OProfile,这时需要重新flash一个支持OProfile的Android系统。

 

       3、运行OProfile进行测试

            opcontrol --start

            …

            Run your application

            …

            opcontrol --stop

 

       4、OProfile的数据会被保存在/data/oprofile目录下面。可以通过下面的命令来或者其他的信息

            opcontrol --status

            opcontrol --help

            oprofiled --help

 

       5、由于OProfile会累积上次的数据,所以每次运行OProfile时,应该先清除累积的数据。

            opcontrol --shutdown

            opcontrol --reset

 

       6、在主机解析数据

            export OPR_DIR=android/oprofile/oprofile-0.9.6/host

            cd android/oprofile

            python -E opimport_pull -r /tmp/oprofile     

 

 

注:为了能让Android系统支持OProfile,还需要对kernel做一些配置。在内核编译时,对OProfile相关配置如下:

           CONFIG_PROFILING=y
           CONFIG_OPROFILE=y
           CONFIG_HAVE_OPROFILE=y
           修改内核源码 ./arch/arm/oprofile/common.c
           line 171: 
           case ARM_PERF_PMU_ID_CA9:
                       return "arm/armv7-ca9";  //此位置设置相应的硬件类型。
         
           编译后,内核将支持OPRFILE

原创粉丝点击