Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit c5e0e55

Browse files
authored
[Impeller] Update Android CPU profiling instructions. (#53437)
* Highlighting the section that says you can profile using a blank project. This saved me as I couldn't find the Profiler anywhere in the project for the Wondrous app. * Added a section that shows how you can mark a release app as debuggable. * Added tooltips for images. * Cleanups for readability (subjective).
1 parent 9407053 commit c5e0e55

File tree

1 file changed

+43
-20
lines changed

1 file changed

+43
-20
lines changed

impeller/docs/android_cpu_profile.md

+43-20
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,74 @@
22

33
Android devices have different performance characteristics than iOS devices, CPU traces frequently reveal surprising performance issues, such as https://github.com/flutter/engine/pull/48303 . This document describes the steps to capture an equivalent [flame graph](https://cacm.acm.org/magazines/2016/6/202665-the-flame-graph/abstract) on your local Android device.
44

5-
1. Build Local Engine with Symbols
5+
### Build Engine with Symbols
66

7-
Add the `--no-stripped` flag to the gn config when building the android engine.
7+
Add the `--no-stripped` flag to the `gn` config when building the android engine.
88

9-
Example config:
9+
Example:
1010

11-
`gn --no-lto --runtime-mode=profile --android --android-cpu=arm64 --no-stripped`
11+
```sh
12+
gn --no-lto --runtime-mode=profile --android --android-cpu=arm64 --no-stripped
13+
```
1214

13-
2. Configure Gradle to not remove strip sources
15+
### Configure Gradle to Not Strip Sources
1416

1517
In the flutter project file `android/app/build.gradle` , add the following line under the `android` block:
1618

19+
```gradle
20+
packagingOptions{
21+
doNotStrip "**/*.so"
22+
}
23+
```
24+
25+
### Mark the App as Debuggable
26+
27+
In case you are profiling a `--release` mode app, mark the app as debuggable by adding the following in the `application` tag of `AndroidManifest.xml`.
28+
29+
```xml
30+
android:debuggable="true"
1731
```
18-
packagingOptions{
19-
doNotStrip "**/*.so"
20-
}
32+
33+
### Run the App with a Locally Built Engine
34+
35+
`flutter run` the app with the local engine flags (`--local-engine`, `--local-engine-host`, `--local-engine-src-path`).
36+
37+
Example:
38+
39+
```sh
40+
flutter --local-engine android_profile_arm64 --local-engine-host host_profile_arm64 run --enable-impeller --profile
2141
```
2242

23-
3. `flutter run` the app with the local engine flags (`--local-engine`, `--local-engine-host`, `--local-engine-src-path`).
24-
4. Open Android Studio.
43+
### Launch Android Studio
44+
45+
Open Android Studio. You can create a new blank project if you don't have one already. You do not need to open the application project nor do you need to run the app via Android Studio.
2546

26-
You can create a new blank project if you don't have one already. You do not need to open the application project nor do you need to run the App through Android Studio. In fact, it's much easier if you do not do those things.
47+
> [!TIP]
48+
> Unless you are already a frequest user of Android Studio, it is recommended that you start with a blank project instead of opening the current project in Android Studio. The location of the various UI elements referenced below may change depending on Android Studio versions or project settings.
2749
28-
5. Open the Profiler Tab
50+
### Open the Profiler
2951

30-
Note: this may be in a different location depending on the exact version of Android Studio that you have installed.
52+
> [!IMPORTANT]
53+
> This may be in a different location or missing depending on the exact version of Android Studio that you have installed. Start a new Android Studio project if you can't find this link.
3154
32-
![Alt text](assets/android_profiling/image.png)
55+
![Open the Profiler](assets/android_profiling/image.png)
3356

34-
6. Start a New Session.
57+
### Start a New Profiling Session
3558

3659
Click the plus button to start a new session, then look for the attached devices, then finally the name of the application to profile. It usually takes a few seconds for the drop downs to populate. The IDE will warn about the build not being a release build, but this doesn't impact the C++ engine so ignore it.
3760

38-
![Alt text](assets/android_profiling/dropdown.png)
61+
![Start a new Profiling Session](assets/android_profiling/dropdown.png)
3962

40-
7. Take a CPU Profile
63+
### Capture a CPU Profile
4164

4265
Click on the CPU section of the chart highlighted below. This will open a side panel that allows you to select the type of profile. Choose "Callstack Sample Recording" and then hit "Record" to start the profile and "Stop" to end the profile
4366

44-
![Alt text](assets/android_profiling/where_do_i_click.png)
67+
![Capture a CPU Profile](assets/android_profiling/where_do_i_click.png)
4568

46-
8. Analyze Raster performance
69+
### Analyze Raster performance
4770

4871
Samples will be collected from all threads, but for analyzing the engine performance we really only care about the raster thread. Note that if you are benchmarking an application that uses platform views, _and_ that platform view uses Hybrid Composition, then the raster thread will be merged with the platform thread.
4972

5073
Select the raster thread by clicking on that area and then choose flame graph (or any of the other options). The flame graph can be navigated using `WASD` and the chart area expanded to make inspection easier.
5174

52-
![Alt text](assets/android_profiling/so_many_options.png)
75+
![Analyze Performance](assets/android_profiling/so_many_options.png)

0 commit comments

Comments
 (0)