Back to home page

OSCL-LXR

 
 

    


0001 How to compile perf for Android
0002 =========================================
0003 
0004 I. Set the Android NDK environment
0005 ------------------------------------------------
0006 
0007 (a). Use the Android NDK
0008 ------------------------------------------------
0009 1. You need to download and install the Android Native Development Kit (NDK).
0010 Set the NDK variable to point to the path where you installed the NDK:
0011   export NDK=/path/to/android-ndk
0012 
0013 2. Set cross-compiling environment variables for NDK toolchain and sysroot.
0014 For arm:
0015   export NDK_TOOLCHAIN=${NDK}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-
0016   export NDK_SYSROOT=${NDK}/platforms/android-24/arch-arm
0017 For x86:
0018   export NDK_TOOLCHAIN=${NDK}/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-
0019   export NDK_SYSROOT=${NDK}/platforms/android-24/arch-x86
0020 
0021 This method is only tested for Android NDK versions Revision 11b and later.
0022 perf uses some bionic enhancements that are not included in prior NDK versions.
0023 You can use method (b) described below instead.
0024 
0025 (b). Use the Android source tree
0026 -----------------------------------------------
0027 1. Download the master branch of the Android source tree.
0028 Set the environment for the target you want using:
0029   source build/envsetup.sh
0030   lunch
0031 
0032 2. Build your own NDK sysroot to contain latest bionic changes and set the
0033 NDK sysroot environment variable.
0034   cd ${ANDROID_BUILD_TOP}/ndk
0035 For arm:
0036   ./build/tools/build-ndk-sysroot.sh --abi=arm
0037   export NDK_SYSROOT=${ANDROID_BUILD_TOP}/ndk/build/platforms/android-3/arch-arm
0038 For x86:
0039   ./build/tools/build-ndk-sysroot.sh --abi=x86
0040   export NDK_SYSROOT=${ANDROID_BUILD_TOP}/ndk/build/platforms/android-3/arch-x86
0041 
0042 3. Set the NDK toolchain environment variable.
0043 For arm:
0044   export NDK_TOOLCHAIN=${ANDROID_TOOLCHAIN}/arm-linux-androideabi-
0045 For x86:
0046   export NDK_TOOLCHAIN=${ANDROID_TOOLCHAIN}/i686-linux-android-
0047 
0048 II. Compile perf for Android
0049 ------------------------------------------------
0050 You need to run make with the NDK toolchain and sysroot defined above:
0051 For arm:
0052   make WERROR=0 ARCH=arm CROSS_COMPILE=${NDK_TOOLCHAIN} EXTRA_CFLAGS="-pie --sysroot=${NDK_SYSROOT}"
0053 For x86:
0054   make WERROR=0 ARCH=x86 CROSS_COMPILE=${NDK_TOOLCHAIN} EXTRA_CFLAGS="-pie --sysroot=${NDK_SYSROOT}"
0055 
0056 III. Install perf
0057 -----------------------------------------------
0058 You need to connect to your Android device/emulator using adb.
0059 Install perf using:
0060   adb push perf /data/perf
0061 
0062 If you also want to use perf-archive you need busybox tools for Android.
0063 For installing perf-archive, you first need to replace #!/bin/bash with #!/system/bin/sh:
0064   sed 's/#!\/bin\/bash/#!\/system\/bin\/sh/g' perf-archive >> /tmp/perf-archive
0065   chmod +x /tmp/perf-archive
0066   adb push /tmp/perf-archive /data/perf-archive
0067 
0068 IV. Environment settings for running perf
0069 ------------------------------------------------
0070 Some perf features need environment variables to run properly.
0071 You need to set these before running perf on the target:
0072   adb shell
0073   # PERF_PAGER=cat
0074 
0075 IV. Run perf
0076 ------------------------------------------------
0077 Run perf on your device/emulator to which you previously connected using adb:
0078   # ./data/perf