xref: /OK3568_Linux_fs/kernel/tools/perf/Documentation/android.txt (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593SmuzhiyunHow to compile perf for Android
2*4882a593Smuzhiyun=========================================
3*4882a593Smuzhiyun
4*4882a593SmuzhiyunI. Set the Android NDK environment
5*4882a593Smuzhiyun------------------------------------------------
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun(a). Use the Android NDK
8*4882a593Smuzhiyun------------------------------------------------
9*4882a593Smuzhiyun1. You need to download and install the Android Native Development Kit (NDK).
10*4882a593SmuzhiyunSet the NDK variable to point to the path where you installed the NDK:
11*4882a593Smuzhiyun  export NDK=/path/to/android-ndk
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun2. Set cross-compiling environment variables for NDK toolchain and sysroot.
14*4882a593SmuzhiyunFor arm:
15*4882a593Smuzhiyun  export NDK_TOOLCHAIN=${NDK}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-
16*4882a593Smuzhiyun  export NDK_SYSROOT=${NDK}/platforms/android-24/arch-arm
17*4882a593SmuzhiyunFor x86:
18*4882a593Smuzhiyun  export NDK_TOOLCHAIN=${NDK}/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-
19*4882a593Smuzhiyun  export NDK_SYSROOT=${NDK}/platforms/android-24/arch-x86
20*4882a593Smuzhiyun
21*4882a593SmuzhiyunThis method is only tested for Android NDK versions Revision 11b and later.
22*4882a593Smuzhiyunperf uses some bionic enhancements that are not included in prior NDK versions.
23*4882a593SmuzhiyunYou can use method (b) described below instead.
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun(b). Use the Android source tree
26*4882a593Smuzhiyun-----------------------------------------------
27*4882a593Smuzhiyun1. Download the master branch of the Android source tree.
28*4882a593SmuzhiyunSet the environment for the target you want using:
29*4882a593Smuzhiyun  source build/envsetup.sh
30*4882a593Smuzhiyun  lunch
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun2. Build your own NDK sysroot to contain latest bionic changes and set the
33*4882a593SmuzhiyunNDK sysroot environment variable.
34*4882a593Smuzhiyun  cd ${ANDROID_BUILD_TOP}/ndk
35*4882a593SmuzhiyunFor arm:
36*4882a593Smuzhiyun  ./build/tools/build-ndk-sysroot.sh --abi=arm
37*4882a593Smuzhiyun  export NDK_SYSROOT=${ANDROID_BUILD_TOP}/ndk/build/platforms/android-3/arch-arm
38*4882a593SmuzhiyunFor x86:
39*4882a593Smuzhiyun  ./build/tools/build-ndk-sysroot.sh --abi=x86
40*4882a593Smuzhiyun  export NDK_SYSROOT=${ANDROID_BUILD_TOP}/ndk/build/platforms/android-3/arch-x86
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun3. Set the NDK toolchain environment variable.
43*4882a593SmuzhiyunFor arm:
44*4882a593Smuzhiyun  export NDK_TOOLCHAIN=${ANDROID_TOOLCHAIN}/arm-linux-androideabi-
45*4882a593SmuzhiyunFor x86:
46*4882a593Smuzhiyun  export NDK_TOOLCHAIN=${ANDROID_TOOLCHAIN}/i686-linux-android-
47*4882a593Smuzhiyun
48*4882a593SmuzhiyunII. Compile perf for Android
49*4882a593Smuzhiyun------------------------------------------------
50*4882a593SmuzhiyunYou need to run make with the NDK toolchain and sysroot defined above:
51*4882a593SmuzhiyunFor arm:
52*4882a593Smuzhiyun  make WERROR=0 ARCH=arm CROSS_COMPILE=${NDK_TOOLCHAIN} EXTRA_CFLAGS="-pie --sysroot=${NDK_SYSROOT}"
53*4882a593SmuzhiyunFor x86:
54*4882a593Smuzhiyun  make WERROR=0 ARCH=x86 CROSS_COMPILE=${NDK_TOOLCHAIN} EXTRA_CFLAGS="-pie --sysroot=${NDK_SYSROOT}"
55*4882a593Smuzhiyun
56*4882a593SmuzhiyunIII. Install perf
57*4882a593Smuzhiyun-----------------------------------------------
58*4882a593SmuzhiyunYou need to connect to your Android device/emulator using adb.
59*4882a593SmuzhiyunInstall perf using:
60*4882a593Smuzhiyun  adb push perf /data/perf
61*4882a593Smuzhiyun
62*4882a593SmuzhiyunIf you also want to use perf-archive you need busybox tools for Android.
63*4882a593SmuzhiyunFor installing perf-archive, you first need to replace #!/bin/bash with #!/system/bin/sh:
64*4882a593Smuzhiyun  sed 's/#!\/bin\/bash/#!\/system\/bin\/sh/g' perf-archive >> /tmp/perf-archive
65*4882a593Smuzhiyun  chmod +x /tmp/perf-archive
66*4882a593Smuzhiyun  adb push /tmp/perf-archive /data/perf-archive
67*4882a593Smuzhiyun
68*4882a593SmuzhiyunIV. Environment settings for running perf
69*4882a593Smuzhiyun------------------------------------------------
70*4882a593SmuzhiyunSome perf features need environment variables to run properly.
71*4882a593SmuzhiyunYou need to set these before running perf on the target:
72*4882a593Smuzhiyun  adb shell
73*4882a593Smuzhiyun  # PERF_PAGER=cat
74*4882a593Smuzhiyun
75*4882a593SmuzhiyunIV. Run perf
76*4882a593Smuzhiyun------------------------------------------------
77*4882a593SmuzhiyunRun perf on your device/emulator to which you previously connected using adb:
78*4882a593Smuzhiyun  # ./data/perf
79