1*7747e2f4SIrina TirdeaHow to compile perf for Android 2*7747e2f4SIrina Tirdea========================================= 3*7747e2f4SIrina Tirdea 4*7747e2f4SIrina TirdeaI. Set the Android NDK environment 5*7747e2f4SIrina Tirdea------------------------------------------------ 6*7747e2f4SIrina Tirdea 7*7747e2f4SIrina Tirdea(a). Use the Android NDK 8*7747e2f4SIrina Tirdea------------------------------------------------ 9*7747e2f4SIrina Tirdea1. You need to download and install the Android Native Development Kit (NDK). 10*7747e2f4SIrina TirdeaSet the NDK variable to point to the path where you installed the NDK: 11*7747e2f4SIrina Tirdea export NDK=/path/to/android-ndk 12*7747e2f4SIrina Tirdea 13*7747e2f4SIrina Tirdea2. Set cross-compiling environment variables for NDK toolchain and sysroot. 14*7747e2f4SIrina TirdeaFor arm: 15*7747e2f4SIrina Tirdea export NDK_TOOLCHAIN=${NDK}/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi- 16*7747e2f4SIrina Tirdea export NDK_SYSROOT=${NDK}/platforms/android-9/arch-arm 17*7747e2f4SIrina TirdeaFor x86: 18*7747e2f4SIrina Tirdea export NDK_TOOLCHAIN=${NDK}/toolchains/x86-4.6/prebuilt/linux-x86/bin/i686-linux-android- 19*7747e2f4SIrina Tirdea export NDK_SYSROOT=${NDK}/platforms/android-9/arch-x86 20*7747e2f4SIrina Tirdea 21*7747e2f4SIrina TirdeaThis method is not working for Android NDK versions up to Revision 8b. 22*7747e2f4SIrina Tirdeaperf uses some bionic enhancements that are not included in these NDK versions. 23*7747e2f4SIrina TirdeaYou can use method (b) described below instead. 24*7747e2f4SIrina Tirdea 25*7747e2f4SIrina Tirdea(b). Use the Android source tree 26*7747e2f4SIrina Tirdea----------------------------------------------- 27*7747e2f4SIrina Tirdea1. Download the master branch of the Android source tree. 28*7747e2f4SIrina TirdeaSet the environment for the target you want using: 29*7747e2f4SIrina Tirdea source build/envsetup.sh 30*7747e2f4SIrina Tirdea lunch 31*7747e2f4SIrina Tirdea 32*7747e2f4SIrina Tirdea2. Build your own NDK sysroot to contain latest bionic changes and set the 33*7747e2f4SIrina TirdeaNDK sysroot environment variable. 34*7747e2f4SIrina Tirdea cd ${ANDROID_BUILD_TOP}/ndk 35*7747e2f4SIrina TirdeaFor arm: 36*7747e2f4SIrina Tirdea ./build/tools/build-ndk-sysroot.sh --abi=arm 37*7747e2f4SIrina Tirdea export NDK_SYSROOT=${ANDROID_BUILD_TOP}/ndk/build/platforms/android-3/arch-arm 38*7747e2f4SIrina TirdeaFor x86: 39*7747e2f4SIrina Tirdea ./build/tools/build-ndk-sysroot.sh --abi=x86 40*7747e2f4SIrina Tirdea export NDK_SYSROOT=${ANDROID_BUILD_TOP}/ndk/build/platforms/android-3/arch-x86 41*7747e2f4SIrina Tirdea 42*7747e2f4SIrina Tirdea3. Set the NDK toolchain environment variable. 43*7747e2f4SIrina TirdeaFor arm: 44*7747e2f4SIrina Tirdea export NDK_TOOLCHAIN=${ANDROID_TOOLCHAIN}/arm-linux-androideabi- 45*7747e2f4SIrina TirdeaFor x86: 46*7747e2f4SIrina Tirdea export NDK_TOOLCHAIN=${ANDROID_TOOLCHAIN}/i686-linux-android- 47*7747e2f4SIrina Tirdea 48*7747e2f4SIrina TirdeaII. Compile perf for Android 49*7747e2f4SIrina Tirdea------------------------------------------------ 50*7747e2f4SIrina TirdeaYou need to run make with the NDK toolchain and sysroot defined above: 51*7747e2f4SIrina Tirdea make CROSS_COMPILE=${NDK_TOOLCHAIN} CFLAGS="--sysroot=${NDK_SYSROOT}" 52*7747e2f4SIrina Tirdea 53*7747e2f4SIrina TirdeaIII. Install perf 54*7747e2f4SIrina Tirdea----------------------------------------------- 55*7747e2f4SIrina TirdeaYou need to connect to your Android device/emulator using adb. 56*7747e2f4SIrina TirdeaInstall perf using: 57*7747e2f4SIrina Tirdea adb push perf /data/perf 58*7747e2f4SIrina Tirdea 59*7747e2f4SIrina TirdeaIf you also want to use perf-archive you need busybox tools for Android. 60*7747e2f4SIrina TirdeaFor installing perf-archive, you first need to replace #!/bin/bash with #!/system/bin/sh: 61*7747e2f4SIrina Tirdea sed 's/#!\/bin\/bash/#!\/system\/bin\/sh/g' perf-archive >> /tmp/perf-archive 62*7747e2f4SIrina Tirdea chmod +x /tmp/perf-archive 63*7747e2f4SIrina Tirdea adb push /tmp/perf-archive /data/perf-archive 64*7747e2f4SIrina Tirdea 65*7747e2f4SIrina TirdeaIV. Environment settings for running perf 66*7747e2f4SIrina Tirdea------------------------------------------------ 67*7747e2f4SIrina TirdeaSome perf features need environment variables to run properly. 68*7747e2f4SIrina TirdeaYou need to set these before running perf on the target: 69*7747e2f4SIrina Tirdea adb shell 70*7747e2f4SIrina Tirdea # PERF_PAGER=cat 71*7747e2f4SIrina Tirdea 72*7747e2f4SIrina TirdeaIV. Run perf 73*7747e2f4SIrina Tirdea------------------------------------------------ 74*7747e2f4SIrina TirdeaRun perf on your device/emulator to which you previously connected using adb: 75*7747e2f4SIrina Tirdea # ./data/perf 76