tree: 972744279a9fa28122c24aebb6b307b4974cd9c4 [path history] [tgz]
  1. CppApi/
  2. data/
  3. etm/
  4. JavaApi/
  5. lbr/
  6. SimpleperfExampleCpp/
  7. SimpleperfExampleJava/
  8. SimpleperfExampleKotlin/
  9. sysfs/
  10. aggregatable_perf1.data
  11. aggregatable_perf2.data
  12. base.vdex
  13. comm_change.cpp
  14. cpp_api-debuggable.apk
  15. cpp_api-profileable.apk
  16. cpp_api.apk
  17. debug_unwind_report.txt
  18. debug_unwind_small_map_range.data
  19. display_bitmaps.proto_data
  20. DisplayBitmaps.apk
  21. DisplayBitmapsTest.apk
  22. elf
  23. elf_file_source.cpp
  24. elf_with_mini_debug_info
  25. EndlessTunnel.apk
  26. etm_test_loop.cpp
  27. function_fork.cpp
  28. function_indirect_recursive.cpp
  29. function_pthread.cpp
  30. function_recursive.cpp
  31. generated_by_linux_perf.data
  32. has_embedded_native_libs_apk_perf.data
  33. invalid_perf.data
  34. java_api-debuggable.apk
  35. java_api-profileable.apk
  36. java_api.apk
  37. kallsyms
  38. libc.so
  39. libsgmainso-6.4.36.so
  40. one_function.cpp
  41. perf.data
  42. perf_b.data
  43. perf_display_bitmaps.data
  44. perf_display_bitmaps.header.perf-script
  45. perf_display_bitmaps.perf-script
  46. perf_display_bitmaps.RenderThread.perf-script
  47. perf_display_bitmaps.UiThread.perf-script
  48. perf_for_build_id_check.data
  49. perf_g_fp.data
  50. perf_merge1.data
  51. perf_merge2.data
  52. perf_need_proguard_mapping.data
  53. perf_no_unwind.data
  54. perf_sched_stat_runtime.data
  55. perf_test_max_stack_and_percent_limit.data
  56. perf_test_vmlinux.data
  57. perf_unwind_embedded_lib_in_apk.data
  58. perf_with_add_counter.data
  59. perf_with_arm_regs.data
  60. perf_with_big_trace_data.data
  61. perf_with_callchain_record.data
  62. perf_with_failed_unwinding_debug_info.data
  63. perf_with_generic_git_symbols.data
  64. perf_with_interpreter_frames.data
  65. perf_with_interpreter_frames.gecko.json
  66. perf_with_ip_zero_in_callchain.data
  67. perf_with_jit_symbol.data
  68. perf_with_jit_symbol.foldedstack
  69. perf_with_jit_symbol.foldedstack_addrs
  70. perf_with_jit_symbol.foldedstack_with_kernel
  71. perf_with_jit_symbol.foldedstack_with_pid
  72. perf_with_jit_symbol.foldedstack_with_tid
  73. perf_with_jit_symbol.gecko.json
  74. perf_with_kernel_symbol.data
  75. perf_with_kernel_symbols_available_false.data
  76. perf_with_kernel_symbols_available_true.data
  77. perf_with_kmem_slab_callgraph.data
  78. perf_with_long_callchain.data
  79. perf_with_meta_info.data
  80. perf_with_mini_debug_info.data
  81. perf_with_multiple_pids_and_tids.data
  82. perf_with_symbols.data
  83. perf_with_symbols_for_nonzero_minvaddr_dso.data
  84. perf_with_trace_offcpu.data
  85. perf_with_trace_offcpu_v2.data
  86. perf_with_tracepoint_event.data
  87. perf_with_tracepoint_event.gecko.json
  88. perf_with_tracepoint_event_dynamic_field.data
  89. perf_with_two_event_types.data
  90. perf_with_two_event_types.foldedstack
  91. perf_with_two_event_types.foldedstack_cpu_clock
  92. proguard_mapping.txt
  93. README.md
  94. run_and_sleep.cpp
  95. runtest.conf
  96. runtest.py
  97. runtest_two_functions_arm64_perf.data
  98. simpleperf_runtest_two_functions_arm
  99. simpleperf_runtest_two_functions_arm64
  100. simpleperf_runtest_two_functions_arm64_without_debug_info
  101. simpleperf_runtest_two_functions_x86
  102. simpleperf_runtest_two_functions_x86_64
  103. two_functions.cpp
  104. two_process_perf.data
  105. vmlinux
  106. wrong_ip_callchain_perf.data
test/testdata/README.md

Examples of using simpleperf to profile Android applications

Table of Contents

Introduction

Simpleperf is a native profiler used on Android platform. It can be used to profile Android applications. Its documentation is here. Instructions of preparing your Android application for profiling are here. This directory is to show examples of using simpleperf to profile Android applications. The meaning of each directory is as below:

../scripts/                  -- contain simpleperf binaries and scripts.
SimpleperfExampleJava/       -- contains an Android Studio project using only Java code.
SimpleperfExampleCpp/        -- contains an Android Studio project using both Java and C++ code.
SimpleperfExampleKotlin/     -- contains an Android Studio project using Kotlin code.
CppApi/                      -- contains an Android Studio project using c++ app_api to record.
JavaApi/                     -- contains an Android Studio project using Java app_api to record.

It can be downloaded as below:

$ git clone https://android.googlesource.com/platform/system/extras
$ cd extras/simpleperf/demo

The testing environment:

Android Studio 3.2
test device: Android O (Google Pixel 2)
test device: Android N (Google Nexus 6P)
Please make sure your device having Android version >= N.

Profile a Java application

Android Studio project: SimpleExampleJava

steps:

  1. Build and install the application:
# Open SimpleperfExampleJava project with Android Studio,
# and build this project successfully, otherwise the `./gradlew` command below will fail.
$ cd SimpleperfExampleJava

# Build and install a debuggable app. We can also build and install a released app on Android >= Q.
# On windows, use "gradlew" instead.
$ ./gradlew clean assemble
$ adb install -r app/build/outputs/apk/debug/app-debug.apk
  1. Record profiling data:
$ cd ../../scripts/
# app_profiler.py collects profiling data in perf.data, and binaries on device in binary_cache/.
$ python app_profiler.py -p simpleperf.example.java
  1. Show profiling data:
# report_html.py generates profiling result in report.html.
$ python report_html.py --add_source_code --source_dirs ../demo --add_disassembly

Profile a Java/C++ application

Android Studio project: SimpleExampleCpp

steps:

  1. Build and install the application:
# Open SimpleperfExampleCpp project with Android Studio,
# and build this project sucessfully, otherwise the `./gradlew` command below will fail.
$ cd SimpleperfExampleCpp

# On windows, use "gradlew" instead.
$ ./gradlew clean assemble
$ adb install -r app/build/outputs/apk/debug/app-debug.apk
  1. Record profiling data:
$ cd ../../scripts/
# app_profiler.py collects profiling data in perf.data, and binaries on device in binary_cache/.
$ python app_profiler.py -p simpleperf.example.cpp -lib app/build
  1. Show profiling data:
# report_html.py generates profiling result in report.html.
$ python report_html.py --add_source_code --source_dirs ../demo --add_disassembly

Profile a Kotlin application

Android Studio project: SimpleExampleKotlin

steps:

  1. Build and install the application:
# Open SimpleperfExampleKotlin project with Android Studio,
# and build this project sucessfully, otherwise the `./gradlew` command below will fail.
$ cd SimpleperfExampleKotlin

# Build and install a debuggable app. We can also build and install a released app on Android >= Q.
# On windows, use "gradlew" instead.
$ ./gradlew clean assemble
$ adb install -r app/build/outputs/apk/debug/app-debug.apk
  1. Record profiling data:
$ cd ../../scripts/
# app_profiler.py collects profiling data in perf.data, and binaries on device in binary_cache/.
$ python app_profiler.py -p simpleperf.example.kotlin
  1. Show profiling data:
# report_html.py generates profiling result in report.html.
$ python report_html.py --add_source_code --source_dirs ../demo --add_disassembly

Profile via app_api

Android Studio project: CppApi and JavaApi

steps:

  1. Build and install the application:
# Open CppApi project with Android Studio,
# and build this project sucessfully, otherwise the `./gradlew` command below will fail.
$ cd CppApi

# On windows, use "gradlew" instead.
$ ./gradlew clean assemble
$ adb install -r app/build/outputs/apk/debug/app-debug.apk
  1. Prepare recording environment.
$ cd ../../scripts/
$ python api_profiler.py prepare
  1. Run the CppApi app.
# launch the app via cmdline, can also launch it on device.
# A profiling file is generated each time running the app.
$ adb shell am start simpleperf.demo.cpp_api/.MainActivity
  1. Collect profiling data.
$ python api_profiler.py collect -p simpleperf.demo.cpp_api
  1. Report profiling data.
$ python report_html.py -i simpleperf_data/* --aggregate-by-thread-name