android.txt 3.1 KB

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