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

steps:

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

# On windows, use "gradlew" instead.
$ ./gradlew clean assemble
$ adb install -r app/build/outputs/apk/app-profiling.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 com.example.simpleperf.simpleperfexamplepurejava
  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: SimpleExampleOfKotlin

steps:

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

# On windows, use "gradlew" instead.
$ ./gradlew clean assemble
$ adb install -r app/build/outputs/apk/profiling/app-profiling.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 com.example.simpleperf.simpleperfexampleofkotlin
  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