1 # Examples of using simpleperf to profile Android applications
5 - [Introduction](#introduction)
6 - [Profiling Java application](#profiling-java-application)
7 - [Profiling Java/C++ application](#profiling-javac-application)
11 Simpleperf is a native profiler used on Android platform. It can be used to profile Android
12 applications. It's document is at [here](https://android.googlesource.com/platform/system/extras/+/master/simpleperf/README.md).
13 Instructions of preparing your Android application for profiling are [here](https://android.googlesource.com/platform/system/extras/+/master/simpleperf/README.md#Android-application-profiling).
14 This directory is to show examples of using simpleperf to profile Android applications. The
15 meaning of each directory is as below:
17 ../scripts/ -- contain simpleperf binaries and scripts.
18 SimpleperfExamplePureJava/ -- contains an Android Studio project using only Java code.
19 SimpleperfExampleWithNative/ -- contains an Android Studio project using both Java and C++ code.
21 It can be downloaded as below:
23 $ git clone https://android.googlesource.com/platform/system/extras
24 $ cd extras/simpleperf/demo
26 ## Profiling Java application
28 Android Studio project: SimpleExamplePureJava
29 test device: Android O (Google Pixel XL)
30 test device: Android N (Google Nexus 5X)
33 1. Build and install app:
35 # Open SimpleperfExamplesPureJava project with Android Studio,
36 # and build this project sucessfully, otherwise the `./gradlew` command below will fail.
37 $ cd SimpleperfExamplePureJava
39 # On windows, use "gradlew" instead.
40 $ ./gradlew clean assemble
41 $ adb install -r app/build/outputs/apk/app-profiling.apk
44 2. Record profiling data:
47 $ gvim app_profiler.config
48 change app_package_name line to: app_package_name = "com.example.simpleperf.simpleperfexamplepurejava"
49 $ python app_profiler.py
50 It runs the application and collects profiling data in perf.data, binaries on device in binary_cache/.
53 3. Show profiling data:
55 a. show call graph in txt mode
56 # On windows, use "bin\windows\x86\simpleperf" instead.
57 $ bin/linux/x86_64/simpleperf report -g | more
58 If on other hosts, use corresponding simpleperf binary.
59 b. show call graph in gui mode
61 c. show samples in source code
62 $ gvim annotate.config
63 change source_dirs line to: source_dirs = ["../demo/SimpleperfExamplePureJava"]
65 $ gvim annotated_files/java/com/example/simpleperf/simpleperfexamplepurejava/MainActivity.java
66 check the annoated source file MainActivity.java.
69 ## Profiling Java/C++ application
71 Android Studio project: SimpleExampleWithNative
72 test device: Android O (Google Pixel XL)
73 test device: Android N (Google Nexus 5X)
76 1. Build and install app:
78 # Open SimpleperfExamplesPureJava project with Android Studio,
79 # and build this project sucessfully, otherwise the `./gradlew` command below will fail.
80 $ cd SimpleperfExampleWithNative
82 # On windows, use "gradlew" instead.
83 $ ./gradlew clean assemble
84 $ adb install -r app/build/outputs/apk/app-profiling.apk
87 2. Record profiling data:
90 $ gvim app_profiler.config
91 change app_package_name line to: app_package_name = "com.example.simpleperf.simpleperfexamplewithnative"
92 $ python app_profiler.py
93 It runs the application and collects profiling data in perf.data, binaries on device in binary_cache/.
96 3. Show profiling data:
98 a. show call graph in txt mode
99 # On windows, use "bin\windows\x86\simpleperf" instead.
100 $ bin/linux/x86_64/simpleperf report -g | more
101 If on other hosts, use corresponding simpleperf binary.
102 b. show call graph in gui mode
103 $ python report.py -g
104 c. show samples in source code
105 $ gvim annotate.config
106 change source_dirs line to: source_dirs = ["../demo/SimpleperfExampleWithNative"]
108 $ find . -name "native-lib.cpp" | xargs gvim
109 check the annoated source file native-lib.cpp.