xref: /linux/tools/perf/Documentation/android.txt (revision cd69ef88a7cbe5ad404454ed8f491e6b16b4e86f)
17747e2f4SIrina TirdeaHow to compile perf for Android
27747e2f4SIrina Tirdea=========================================
37747e2f4SIrina Tirdea
47747e2f4SIrina TirdeaI. Set the Android NDK environment
57747e2f4SIrina Tirdea------------------------------------------------
67747e2f4SIrina Tirdea
77747e2f4SIrina Tirdea(a). Use the Android NDK
87747e2f4SIrina Tirdea------------------------------------------------
97747e2f4SIrina Tirdea1. You need to download and install the Android Native Development Kit (NDK).
107747e2f4SIrina TirdeaSet the NDK variable to point to the path where you installed the NDK:
117747e2f4SIrina Tirdea  export NDK=/path/to/android-ndk
127747e2f4SIrina Tirdea
137747e2f4SIrina Tirdea2. Set cross-compiling environment variables for NDK toolchain and sysroot.
147747e2f4SIrina TirdeaFor arm:
157747e2f4SIrina Tirdea  export NDK_TOOLCHAIN=${NDK}/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-
167747e2f4SIrina Tirdea  export NDK_SYSROOT=${NDK}/platforms/android-9/arch-arm
177747e2f4SIrina TirdeaFor x86:
187747e2f4SIrina Tirdea  export NDK_TOOLCHAIN=${NDK}/toolchains/x86-4.6/prebuilt/linux-x86/bin/i686-linux-android-
197747e2f4SIrina Tirdea  export NDK_SYSROOT=${NDK}/platforms/android-9/arch-x86
207747e2f4SIrina Tirdea
217747e2f4SIrina TirdeaThis method is not working for Android NDK versions up to Revision 8b.
227747e2f4SIrina Tirdeaperf uses some bionic enhancements that are not included in these NDK versions.
237747e2f4SIrina TirdeaYou can use method (b) described below instead.
247747e2f4SIrina Tirdea
257747e2f4SIrina Tirdea(b). Use the Android source tree
267747e2f4SIrina Tirdea-----------------------------------------------
277747e2f4SIrina Tirdea1. Download the master branch of the Android source tree.
287747e2f4SIrina TirdeaSet the environment for the target you want using:
297747e2f4SIrina Tirdea  source build/envsetup.sh
307747e2f4SIrina Tirdea  lunch
317747e2f4SIrina Tirdea
327747e2f4SIrina Tirdea2. Build your own NDK sysroot to contain latest bionic changes and set the
337747e2f4SIrina TirdeaNDK sysroot environment variable.
347747e2f4SIrina Tirdea  cd ${ANDROID_BUILD_TOP}/ndk
357747e2f4SIrina TirdeaFor arm:
367747e2f4SIrina Tirdea  ./build/tools/build-ndk-sysroot.sh --abi=arm
377747e2f4SIrina Tirdea  export NDK_SYSROOT=${ANDROID_BUILD_TOP}/ndk/build/platforms/android-3/arch-arm
387747e2f4SIrina TirdeaFor x86:
397747e2f4SIrina Tirdea  ./build/tools/build-ndk-sysroot.sh --abi=x86
407747e2f4SIrina Tirdea  export NDK_SYSROOT=${ANDROID_BUILD_TOP}/ndk/build/platforms/android-3/arch-x86
417747e2f4SIrina Tirdea
427747e2f4SIrina Tirdea3. Set the NDK toolchain environment variable.
437747e2f4SIrina TirdeaFor arm:
447747e2f4SIrina Tirdea  export NDK_TOOLCHAIN=${ANDROID_TOOLCHAIN}/arm-linux-androideabi-
457747e2f4SIrina TirdeaFor x86:
467747e2f4SIrina Tirdea  export NDK_TOOLCHAIN=${ANDROID_TOOLCHAIN}/i686-linux-android-
477747e2f4SIrina Tirdea
487747e2f4SIrina TirdeaII. Compile perf for Android
497747e2f4SIrina Tirdea------------------------------------------------
507747e2f4SIrina TirdeaYou need to run make with the NDK toolchain and sysroot defined above:
51*cd69ef88SJoonsoo KimFor arm:
52*cd69ef88SJoonsoo Kim  make ARCH=arm CROSS_COMPILE=${NDK_TOOLCHAIN} CFLAGS="--sysroot=${NDK_SYSROOT}"
53*cd69ef88SJoonsoo KimFor x86:
54*cd69ef88SJoonsoo Kim  make ARCH=x86 CROSS_COMPILE=${NDK_TOOLCHAIN} CFLAGS="--sysroot=${NDK_SYSROOT}"
557747e2f4SIrina Tirdea
567747e2f4SIrina TirdeaIII. Install perf
577747e2f4SIrina Tirdea-----------------------------------------------
587747e2f4SIrina TirdeaYou need to connect to your Android device/emulator using adb.
597747e2f4SIrina TirdeaInstall perf using:
607747e2f4SIrina Tirdea  adb push perf /data/perf
617747e2f4SIrina Tirdea
627747e2f4SIrina TirdeaIf you also want to use perf-archive you need busybox tools for Android.
637747e2f4SIrina TirdeaFor installing perf-archive, you first need to replace #!/bin/bash with #!/system/bin/sh:
647747e2f4SIrina Tirdea  sed 's/#!\/bin\/bash/#!\/system\/bin\/sh/g' perf-archive >> /tmp/perf-archive
657747e2f4SIrina Tirdea  chmod +x /tmp/perf-archive
667747e2f4SIrina Tirdea  adb push /tmp/perf-archive /data/perf-archive
677747e2f4SIrina Tirdea
687747e2f4SIrina TirdeaIV. Environment settings for running perf
697747e2f4SIrina Tirdea------------------------------------------------
707747e2f4SIrina TirdeaSome perf features need environment variables to run properly.
717747e2f4SIrina TirdeaYou need to set these before running perf on the target:
727747e2f4SIrina Tirdea  adb shell
737747e2f4SIrina Tirdea  # PERF_PAGER=cat
747747e2f4SIrina Tirdea
757747e2f4SIrina TirdeaIV. Run perf
767747e2f4SIrina Tirdea------------------------------------------------
777747e2f4SIrina TirdeaRun perf on your device/emulator to which you previously connected using adb:
787747e2f4SIrina Tirdea  # ./data/perf
79