blob: 73df8ff5ceca23e61a7ade8f1c310ab554f95672 [file] [log] [blame] [view]
andybonsad92aa32015-08-31 02:27:441# Profiling Content Shell on Android
andybons3322f762015-08-24 21:37:092
andybonsad92aa32015-08-31 02:27:443Below are the instructions for setting up profiling for Content Shell on
4Android. This will let you generate profiles for ContentShell. This will require
5linux, building an userdebug Android build, and wiping the device.
6
7[TOC]
andybons3322f762015-08-24 21:37:098
9## Prepare your device.
10
andybonsad92aa32015-08-31 02:27:4411You need an Android 4.2+ device (Galaxy Nexus, Nexus 4, 7, 10, etc.) which you
12don’t mind erasing all data, rooting, and installing a userdebug build on.
andybons3322f762015-08-24 21:37:0913
andybonsad92aa32015-08-31 02:27:4414## Get and build `content_shell_apk` for Android
andybons3322f762015-08-24 21:37:0915
Andrew Grieveb747e712017-11-23 16:58:3116More detailed insturctions in [android_build_instructions.md](android_build_instructions.md).
andybonsad92aa32015-08-31 02:27:4417
Andrew Grieveb747e712017-11-23 16:58:3118```shell
19ninja -C out/Release content_shell_apk
20```
andybons3322f762015-08-24 21:37:0921
22## Setup the physical device
23
Andrew Grieveb747e712017-11-23 16:58:3124Plug in your device. Make sure you can talk to your device, try:
25
26```shell
27third_party/android_tools/sdk/platform-tools/adb shell ls
28```
andybons3322f762015-08-24 21:37:0929
30## Root your device and install a userdebug build
31
andybonsad92aa32015-08-31 02:27:44321. This may require building your own version of Android:
33 http://source.android.com/source/building-devices.html
341. A build that works is: `manta / android-4.2.2_r1` or
35 `master / full_manta-userdebug`.
andybons3322f762015-08-24 21:37:0936
37## Root your device
andybonsad92aa32015-08-31 02:27:4438
391. Run `adb root`. Every time you connect your device you’ll want to run this.
401. If adb is not available, make sure to run `. build/android/envsetup.sh`
41
42If you get the error `error: device offline`, you may need to become a developer
43on your device before Linux will see it. On Jellybean 4.2.1 and above this
44requires going to “about phone” or “about tablet” and clicking the build number
457 times:
46http://androidmuscle.com/how-to-enable-usb-debugging-developer-options-on-nexus-4-and-android-4-2-devices/
andybons3322f762015-08-24 21:37:0947
jbroman349e3d72016-05-10 19:15:1748## Enable profiling
49
50Rebuild `content_shell_apk` with profiling enabled.
51
jbroman349e3d72016-05-10 19:15:1752With GN:
53
54 gn args out/Profiling
55 # add "enable_profiling = true"
56 ninja -C out/Profiling content_shell_apk
57 export CHROMIUM_OUTPUT_DIR="$PWD/out/Profiling"
58
andybons3322f762015-08-24 21:37:0959## Run a Telemetry perf profiler
60
andybonsad92aa32015-08-31 02:27:4461You can run any Telemetry benchmark with `--profiler=perf`, and it will:
andybons3322f762015-08-24 21:37:0962
andybonsad92aa32015-08-31 02:27:44631. Download `perf` and `perfhost`
jbroman349e3d72016-05-10 19:15:17642. Install on your device
653. Run the test
664. Setup symlinks to work with the `--symfs` parameter
andybons3322f762015-08-24 21:37:0967
68You can also run "manual" tests with Telemetry, more information here:
xiaoyin.l1003c0b2016-12-06 02:51:1769https://www.chromium.org/developers/telemetry/profiling#TOC-Manual-Profiling---Android
andybons3322f762015-08-24 21:37:0970
andybonsad92aa32015-08-31 02:27:4471The following steps describe building `perf`, which is no longer necessary if
72you use Telemetry.
andybons3322f762015-08-24 21:37:0973
jbroman349e3d72016-05-10 19:15:1774## Use `adb_profile_chrome`
75
76Even if you're not running a Telemetry test, you can use Catapult to
77automatically push binaries and pull the profile data for you.
78
79 build/android/adb_profile_chrome --browser=content_shell --perf
80
81While you still have to build, install and launch the APK yourself, Catapult
82will take care of creating the symfs etc. (i.e. you can skip the "not needed for
83Telemetry" steps below).
84
andybonsad92aa32015-08-31 02:27:4485## Install `/system/bin/perf` on your device (not needed for Telemetry)
andybons3322f762015-08-24 21:37:0986
qyearsleyc0dc6f42016-12-02 22:13:3987 # From inside the Android source tree (not inside Chromium)
andybonsad92aa32015-08-31 02:27:4488 mmm external/linux-tools-perf/
89 adb remount # (allows you to write to the system image)
90 adb sync
91 adb shell perf top # check that perf can get samples (don’t expect symbols)
andybons3322f762015-08-24 21:37:0992
Andrew Grieveb747e712017-11-23 16:58:3193## Install and Run ContentShell
andybonsad92aa32015-08-31 02:27:4494
95Install with the following:
96
Andrew Grieveb747e712017-11-23 16:58:3197 out/Release/bin/content_shell_apk run
andybons3322f762015-08-24 21:37:0998
Andrew Grieveb747e712017-11-23 16:58:3199If `content_shell` “stopped unexpectedly” use `adb logcat` to debug.
andybonsad92aa32015-08-31 02:27:44100
101## Setup a `symbols` directory with symbols from your build (not needed for Telemetry)
102
1031. Figure out exactly what path `content_shell_apk` (or chrome, etc) installs
104 to.
105 * On the device, navigate ContentShell to about:crash
andybons3322f762015-08-24 21:37:09106
107
andybonsad92aa32015-08-31 02:27:44108 adb logcat | grep libcontent_shell_content_view.so
109
110You should find a path that’s something like
111`/data/app-lib/org.chromium.content_shell-1/libcontent_shell_content_view.so`
112
1131. Make a symbols directory
114 ```
115 mkdir symbols (this guide assumes you put this next to src/)
116 ```
1171. Make a symlink from your symbols directory to your un-stripped
118 `content_shell`.
119
120 ```
121 # Use whatever path in app-lib you got above
122 mkdir -p symbols/data/app-lib/org.chromium.content_shell-1
123 ln -s `pwd`/src/out/Release/lib/libcontent_shell_content_view.so \
124 `pwd`/symbols/data/app-lib/org.chromium.content_shell-1
125 ```
126
127## Install `perfhost_linux` locally (not needed for Telemetry)
128
129Note: modern versions of perf may also be able to process the perf.data files
130from the device.
131
1321. `perfhost_linux` can be built from:
133 https://android.googlesource.com/platform/external/linux-tools-perf/.
1341. Place `perfhost_linux` next to symbols, src, etc.
135
136 chmod a+x perfhost_linux
andybons3322f762015-08-24 21:37:09137
138## Actually record a profile on the device!
andybonsad92aa32015-08-31 02:27:44139
140Run the following:
141
Andrew Grieveb747e712017-11-23 16:58:31142 out/Release/content_shell_apk ps (look for the pid of the sandboxed_process)
andybonsad92aa32015-08-31 02:27:44143 adb shell perf record -g -p 12345 sleep 5
144 adb pull /data/perf.data
145
andybons3322f762015-08-24 21:37:09146## Create the report
andybonsad92aa32015-08-31 02:27:44147
1481. Run the following:
149
150 ```
151 ./perfhost_linux report -g -i perf.data --symfs symbols/
152 ```
153
1541. If you don’t see chromium/webkit symbols, make sure that you built/pushed
155 Release, and that the symlink you created to the .so is valid!
andybons3322f762015-08-24 21:37:09156
157## Add symbols for the kernel
andybonsad92aa32015-08-31 02:27:44158
1591. By default, /proc/kallsyms returns 0 for all symbols, to fix this, set
160 `/proc/sys/kernel/kptr_restrict` to `0`:
161
162 ```
163 adb shell echo “0” > /proc/sys/kernel/kptr_restrict
164 ```
165
1661. See http://lwn.net/Articles/420403/ for explanation of what this does.
167
168 ```
169 adb pull /proc/kallsyms symbols/kallsyms
170 ```
171
1721. Now add --kallsyms to your perfhost\_linux command:
173 ```
174 ./perfhost_linux report -g -i perf.data --symfs symbols/ \
175 --kallsyms=symbols/kallsyms
176 ```