Android Performance Testing Tool-oprofile

Source: Internet
Author: User

How can I test the performance of Android applications? Traceview can be used at the Java level, but so is developed with ndk. What if traceview cannot be tracked? Asked the Google guru, the answer is oprofile! Oprofile is the next low-cost global performance monitoring tool for Linux systems. It uses dedicated Performance Monitoring Hardware included in the processor (if there is no performance monitoring hardware, it uses a timer-based alternative) to collect performance-related data samples. It obtains information about the kernel and executable files on the system, such as when the memory is referenced, the number of L2 cache requests, and the number of hardware interruptions received. Oprofile has the following features: l you do not need to re-compile the source code. Without source code and analysis, even debugging information (-G option to GCC) is not required. L insert only one module into the kernel. L analysis of all code running on the system (except for code with interruptions disabled) l the additional overhead of the system is small, and the oprofile will increase the overhead by 1%-8% (depending on the sampling frequency) l compatible with all 2.2, 2.4, and 2.6 kernels and can run on the SMP system. l supports mainstream CPU architectures, including x86, arm, avr32, MIPS, PowerPC, and other oprofiles, the following conditions must be met: 1. the kernel must support 2. to port the oprofile to the ARM platform is the whole process of transplantation: first, the oprofile porting to the Cross-compilation tool is as follows: the library used by the arm-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2 is as follows: popt-1.14.tar.gz binutils-2.21.tar.gzoprofile-0.9.6.tar.gz $ tar xvfz arm-2010.09-50-arm-none-lin Ux-gnueabi-i686-pc-linux-gnu.tar.bz2-C ~ /Modify ~ /. Bashrc, add export path =$ {path}:/home/louieli/ARM-2010.09/bin $ tar zxvf popt-1.14.tar.gz $ CD popt-1.14 $ ac_cv_va_copy = yes. /configure -- With-kernel-support -- Host = arm-None-Linux-gnueabi -- prefix =/home/louieli/work/popt $ make install $ tar zxvf binutils-2.21.tar.gz $ cd binutils-2.21/$. /configure -- With-kernel-support -- Host = arm-None-Linux-gnueabi -- prefix =/home/louieli/work/binutils -- enable-S Hared $ make ldflags = "-All-static" may cause the following error: fig. Find the makefile of the error file, remove-werror $ make install $ tar zxvf oprofile-0.9.6.tar.gz $ CD oprofile-0.9.6/$. /configure -- With-kernel-support -- Host = arm-None-Linux-gnueabi -- prefix =/home/louieli/work/oprofile/-- With-extra-libs =/home/ louieli/work/popt/lib/-- With-extra-nodes des =/home/louieli/work/popt/include/-- With-binutils =/home/L Ouieli/work/binutils $ make ldflags = "-All-static-L/home/louieli/work/binutils/lib-xlinker-r-xlinker/home/louieli/work/binutils /lib-L/home/louieli/work/popt/lib/"$ make install run the file command, all the oprofile files we need have become static link files that can be run on Android. install. SH: Bourne-again shell script text executableopannotate: Elf 32-bit LSB executable, arm, Version 1 (sysv), statically linked, for GNU/Linux 2.6.16, not strippedo Parchive: Elf 32-bit LSB executable, arm, Version 1 (sysv), statically linked, for GNU/Linux 2.6.16, not strippedopcontrol: A/system/bin/sh script text executableopgprof: elf 32-bit LSB executable, arm, Version 1 (sysv), statically linked, for GNU/Linux 2.6.16, not strippedophelp: Elf 32-bit LSB executable, arm, version 1 (sysv), statically linked, for GNU/Linux 2.6.16, not strippedopimport: elf 32-bit LSB executable, arm, Version 1 (sysv), statically linked, for GNU/Linux 2.6.16, not strippedopjitconv: Elf 32-bit LSB executable, arm, version 1 (sysv), statically linked, for GNU/Linux 2.6.16, not strippedopreport: Elf 32-bit LSB executable, arm, Version 1 (sysv), statically linked, for GNU/Linux 2.6.16, not strippedoprofiled: Elf 32-bit LSB executable, arm, Version 1 (sysv), statically Li Nked, for GNU/Linux 2.6.16, not stripped 2. Compile Linux kernel image a) prepare a prebuilt project in the android code tree of the Cross-compilation toolchain, it includes the cross-compilation tools required for Kernel compilation. B) set the environment variable $ Emacs ~ /. Add the following two rows to bashrc: Export Path = $ path :~ /Android/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/binexport arch = arm save after synchronization changes: $ source ~ /. Bashrcc) Get the appropriate kernel source code $ Cd ~ /Android get the kernel source code repository $ git clone git: // android.git.kernel.org/kernel/common.git kernel $ CD kernel $ git branch shows * Android-2.6.27 indicates that you are on the branch of Android-2.6.27, it is also kernel/Common. the default main branch of git. Show all head branches: $ git branch-a display * android-2.6.27remotes/ORIGIN/head-> origin/android-2.6.27remotes/ORIGIN/android-2.6.25remotes/ORIGIN/android-2.6.27remotes/ORIGIN/android-2.6.29remotes/ORIGIN/android-goldfish-2.6.27remotes/ORIGIN/Android-goldfish- 2.6.29 select the latest Android-goldfish-2.6.29, here, goldfish is the CPU simulated by the android simulator. $ Git checkout-B Android-goldfish-2.6.29 origin/Android-goldfish-2.6.29 $ git branch show Android-2.6.27 * Android-goldfish-2.6.29 we have worked on the Android-goldfish-2.6.29 Branch. D) set the cross-compilation parameter to open the MAKEFILE file in the kernel directory and point cross_compile to the arm-Eabi compiler cross_compile in the prebuilt just downloaded? = Arm-Eabi-set ldflags_build_id = $ (patsubst-wl $ (comma) %, %,/$ (call LD-option,-wl $ (comma) -Build-ID,) Comment out this line and add an empty ldflags_build_id definition, as shown below: ldflags_build_id = e) Compile the kernel image $ Cd ~ /Android/kernel $ make goldfish_defconfig $ make menuconfig modify the Kernel configuration as follows: General setup ---> [*] profiling support (experimental) [] Activate markers [*] oprofile system profiling (experimental) this is to compile the oprofile directly into the kernel. Alternatively, you can choose [m] oprofile system profiling (experimental) to generate an oprofile in the arch/ARM/oprofile folder. ko, oprofile. ko needs to be loaded with insmod. $ Make f) Test the generated kernel image $ emulator-AVD myavd-kernel ~ /Android/kernel/ARCH/ARM/boot/zimage 3. oprofile usage in Android simulator 1. take a look at the opcontrol parameter # opcontrolopcontrol: 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 data collection-D/-- dump flush the collected profiling data-T/-- 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 PR Ofiles 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 image (for xen only) -- active-domains = <list> list Domains in profiling SESSION (for xen only) (List contains domain IDs separated by commas) 2. use methods to load the previously compiled oprofile and busybox into the simulator and execute install in the oprofile directory. sh load oprofile into the simulator ADB push busybox/data/busybox $ ADB shell // enter the simulator 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/ /This sentence is very important, if this clause does not exist, the following error occurs: # opcontrol -- init Cat: Can't open '/dev/oprofile/cpu_type ': no such file or directoryunable to open cpu_type file for readingmake Sure You Have Done opcontrol -- initcpu_type 'unset' is not validyou shoshould upgrade oprofile or force the US E of Timer mode # opcontrol -- init // initialization, run # opcontrol -- setup -- callgraph = 2 -- session-Dir =/data/first -- no-vmlinuxusing 2.6 + oprofile kernel interface. using Log File/data/First/samples/oprofiled. logdaemon started. profiler running. # opcontrol -- statusdaemon running: PID 637 separate options: nonevmlinux file: noneimage filter: nonecall-graph depth: 2 # opcontrol -- start // start profilerusing 2.6 + OP Rofile kernel interface. using log file/var/lib/oprofile/samples/oprofiled. logdaemon started. profiler running. #/data/test // run our program (my test program uses this command to compile arm-None-Linux-gnueabi-gcc-g-o test. c-static-fno-omit-frame-pointer) in CIN ain bin ain CIN bin ain a # opcontrol -- dump // collect sample data # opcontrol -- stop // stop profilerstopping profiling. # opreport -- session-Dir =/data/first-L/data/test // view the report CPU: CPU with timer interrupt, speed 0 MHz (estimated) profiling through timer interruptsamples % symbol name11291 79.9589 a1129 7.9952 b853 6.0406 main848 6.0052 C now we can optimize our program based on the oprofile output. If anyone wants to give it a try, you must use Linux. This porting environment is very important. I used to waste a lot of time on the testing machine (win7 + cygwin. We have a packaged tool for you to download. Here, kernel-qemu is the previously compiled kernel. Replace kernel-qemu In the android SDK. Good luck!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.