Name |
Date |
Size |
#Lines |
LOC |
||
---|---|---|---|---|---|---|
.. | - | - | ||||
CppApi/ | 03-May-2024 | - | 857 | 693 | ||
JavaApi/ | 03-May-2024 | - | 767 | 633 | ||
SimpleperfExampleCpp/ | 03-May-2024 | - | 1,045 | 867 | ||
SimpleperfExampleJava/ | 03-May-2024 | - | 1,082 | 889 | ||
SimpleperfExampleKotlin/ | 03-May-2024 | - | 927 | 761 | ||
.clang-format | D | 03-May-2024 | 214 | 8 | 5 | |
README.md | D | 03-May-2024 | 5.5 KiB | 185 | 135 |
README.md
1# Examples of using simpleperf to profile Android applications 2 3## Table of Contents 4 5- [Examples of using simpleperf to profile Android applications](#examples-of-using-simpleperf-to-profile-android-applications) 6 - [Table of Contents](#table-of-contents) 7 - [Introduction](#introduction) 8 - [Profile a Java application](#profile-a-java-application) 9 - [Profile a Java/C++ application](#profile-a-javac-application) 10 - [Profile a Kotlin application](#profile-a-kotlin-application) 11- [Profile via app_api](#profile-via-app_api) 12 13## Introduction 14 15Simpleperf is a native profiler used on Android platform. It can be used to profile Android 16applications. Its documentation is [here](https://android.googlesource.com/platform/system/extras/+/master/simpleperf/doc/README.md). 17Instructions of preparing your Android application for profiling are [here](https://android.googlesource.com/platform/system/extras/+/master/simpleperf/doc/README.md#Android-application-profiling). 18This directory is to show examples of using simpleperf to profile Android applications. The 19meaning of each directory is as below: 20 21 ../scripts/ -- contain simpleperf binaries and scripts. 22 SimpleperfExampleJava/ -- contains an Android Studio project using only Java code. 23 SimpleperfExampleCpp/ -- contains an Android Studio project using both Java and C++ code. 24 SimpleperfExampleKotlin/ -- contains an Android Studio project using Kotlin code. 25 CppApi/ -- contains an Android Studio project using c++ app_api to record. 26 JavaApi/ -- contains an Android Studio project using Java app_api to record. 27 28It can be downloaded as below: 29 30```sh 31$ git clone https://android.googlesource.com/platform/system/extras 32$ cd extras/simpleperf/demo 33``` 34 35The testing environment: 36 37``` 38Android Studio 3.2 39test device: Android O (Google Pixel 2) 40test device: Android N (Google Nexus 6P) 41Please make sure your device having Android version >= N. 42``` 43 44## Profile a Java application 45 46Android Studio project: SimpleExampleJava 47 48steps: 491. Build and install the application: 50 51```sh 52# Open SimpleperfExampleJava project with Android Studio, 53# and build this project successfully, otherwise the `./gradlew` command below will fail. 54$ cd SimpleperfExampleJava 55 56# Build and install a debuggable app. We can also build and install a released app on Android >= Q. 57# On windows, use "gradlew" instead. 58$ ./gradlew clean assemble 59$ adb install -r app/build/outputs/apk/debug/app-debug.apk 60``` 61 622. Record profiling data: 63 64```sh 65$ cd ../../scripts/ 66# app_profiler.py collects profiling data in perf.data, and binaries on device in binary_cache/. 67$ python app_profiler.py -p simpleperf.example.java 68``` 69 703. Show profiling data: 71 72```sh 73# report_html.py generates profiling result in report.html. 74$ python report_html.py --add_source_code --source_dirs ../demo --add_disassembly 75``` 76 77## Profile a Java/C++ application 78 79Android Studio project: SimpleExampleCpp 80 81steps: 821. Build and install the application: 83 84```sh 85# Open SimpleperfExampleCpp project with Android Studio, 86# and build this project sucessfully, otherwise the `./gradlew` command below will fail. 87$ cd SimpleperfExampleCpp 88 89# On windows, use "gradlew" instead. 90$ ./gradlew clean assemble 91$ adb install -r app/build/outputs/apk/debug/app-debug.apk 92``` 93 942. Record profiling data: 95 96```sh 97$ cd ../../scripts/ 98# app_profiler.py collects profiling data in perf.data, and binaries on device in binary_cache/. 99$ python app_profiler.py -p simpleperf.example.cpp -lib app/build 100``` 101 1023. Show profiling data: 103 104```sh 105# report_html.py generates profiling result in report.html. 106$ python report_html.py --add_source_code --source_dirs ../demo --add_disassembly 107``` 108 109## Profile a Kotlin application 110 111Android Studio project: SimpleExampleKotlin 112 113steps: 1141. Build and install the application: 115 116```sh 117# Open SimpleperfExampleKotlin project with Android Studio, 118# and build this project sucessfully, otherwise the `./gradlew` command below will fail. 119$ cd SimpleperfExampleKotlin 120 121# Build and install a debuggable app. We can also build and install a released app on Android >= Q. 122# On windows, use "gradlew" instead. 123$ ./gradlew clean assemble 124$ adb install -r app/build/outputs/apk/debug/app-debug.apk 125``` 126 1272. Record profiling data: 128 129```sh 130$ cd ../../scripts/ 131# app_profiler.py collects profiling data in perf.data, and binaries on device in binary_cache/. 132$ python app_profiler.py -p simpleperf.example.kotlin 133``` 134 1353. Show profiling data: 136 137```sh 138# report_html.py generates profiling result in report.html. 139$ python report_html.py --add_source_code --source_dirs ../demo --add_disassembly 140``` 141 142# Profile via app_api 143 144Android Studio project: CppApi and JavaApi 145 146steps: 1471. Build and install the application: 148 149```sh 150# Open CppApi project with Android Studio, 151# and build this project sucessfully, otherwise the `./gradlew` command below will fail. 152$ cd CppApi 153 154# On windows, use "gradlew" instead. 155$ ./gradlew clean assemble 156$ adb install -r app/build/outputs/apk/debug/app-debug.apk 157``` 158 1592. Prepare recording environment. 160 161```sh 162$ cd ../../scripts/ 163$ python api_profiler.py prepare 164``` 165 1663. Run the CppApi app. 167 168```sh 169# launch the app via cmdline, can also launch it on device. 170# A profiling file is generated each time running the app. 171$ adb shell am start simpleperf.demo.cpp_api/.MainActivity 172``` 173 1744. Collect profiling data. 175 176```sh 177$ python api_profiler.py collect -p simpleperf.demo.cpp_api 178``` 179 1805. Report profiling data. 181 182```sh 183$ python report_html.py -i simpleperf_data/* --aggregate-by-thread-name 184``` 185