OSDN Git Service

kernel.config: check console-ramoops-0
[android-x86/system-extras.git] / simpleperf / demo / README.md
1 # Examples of using simpleperf to profile Android applications
2
3 ## Table of Contents
4
5 - [Introduction](#introduction)
6 - [Profiling Java application](#profiling-java-application)
7 - [Profiling Java/C++ application](#profiling-javac-application)
8
9 ## Introduction
10
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:
16
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.
20
21 It can be downloaded as below:
22
23     $ git clone https://android.googlesource.com/platform/system/extras
24     $ cd extras/simpleperf/demo
25
26 ## Profiling Java application
27
28     Android Studio project: SimpleExamplePureJava
29     test device: Android O (Google Pixel XL)
30     test device: Android N (Google Nexus 5X)
31
32 steps:
33 1. Build and install app:
34 ```
35 # Open SimpleperfExamplesPureJava project with Android Studio,
36 # and build this project sucessfully, otherwise the `./gradlew` command below will fail.
37 $ cd SimpleperfExamplePureJava
38
39 # On windows, use "gradlew" instead.
40 $ ./gradlew clean assemble
41 $ adb install -r app/build/outputs/apk/app-profiling.apk
42 ```
43
44 2. Record profiling data:
45 ```
46 $ cd ../../scripts/
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/.
51 ```
52
53 3. Show profiling data:
54 ```
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
60     $ python report.py -g
61 c. show samples in source code
62     $ gvim annotate.config
63         change source_dirs line to: source_dirs = ["../demo/SimpleperfExamplePureJava"]
64     $ python annotate.py
65     $ gvim annotated_files/java/com/example/simpleperf/simpleperfexamplepurejava/MainActivity.java
66         check the annoated source file MainActivity.java.
67 ```
68
69 ## Profiling Java/C++ application
70
71     Android Studio project: SimpleExampleWithNative
72     test device: Android O (Google Pixel XL)
73     test device: Android N (Google Nexus 5X)
74
75 steps:
76 1. Build and install app:
77 ```
78 # Open SimpleperfExamplesPureJava project with Android Studio,
79 # and build this project sucessfully, otherwise the `./gradlew` command below will fail.
80 $ cd SimpleperfExampleWithNative
81
82 # On windows, use "gradlew" instead.
83 $ ./gradlew clean assemble
84 $ adb install -r app/build/outputs/apk/app-profiling.apk
85 ```
86
87 2. Record profiling data:
88 ```
89 $ cd ../../scripts/
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/.
94 ```
95
96 3. Show profiling data:
97 ```
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"]
107     $ python annotate.py
108     $ find . -name "native-lib.cpp" | xargs gvim
109         check the annoated source file native-lib.cpp.
110 ```