OLD | NEW |
1 # Introduction | 1 # Profiling Content Shell on Android |
2 | 2 |
3 Below are the instructions for setting up profiling for Content Shell on Android
. This will let you generate profiles for ContentShell. This will require linux,
building an userdebug Android build, and wiping the device. | 3 Below are the instructions for setting up profiling for Content Shell on |
| 4 Android. This will let you generate profiles for ContentShell. This will require |
| 5 linux, building an userdebug Android build, and wiping the device. |
| 6 |
| 7 [TOC] |
4 | 8 |
5 ## Prepare your device. | 9 ## Prepare your device. |
6 | 10 |
7 You need an Android 4.2+ device (Galaxy Nexus, Nexus 4, 7, 10, etc.) which you d
on’t mind erasing all data, rooting, and installing a userdebug build on. | 11 You need an Android 4.2+ device (Galaxy Nexus, Nexus 4, 7, 10, etc.) which you |
8 | 12 don’t mind erasing all data, rooting, and installing a userdebug build on. |
9 ## Get and build content\_shell\_apk for Android | 13 |
10 (These instructions have been carefully distilled from http://code.google.com/p/
chromium/wiki/AndroidBuildInstructions) | 14 ## Get and build `content_shell_apk` for Android |
11 | 15 |
12 1. Get the code! You’ll want a second checkout as this will be android-specifi
c. You know the drill: http://dev.chromium.org/developers/how-tos/get-the-code | 16 (These instructions have been carefully distilled from the |
13 1. Append this to your .gclient file: `target_os = ['android']` | 17 [Android Build Instructions](android_build_instructions.md).) |
14 1. Create `chromium.gyp_env` next to your .gclient file: `echo "{ 'GYP_DEFINES
': 'OS=android', }" > chromium.gyp_env` | 18 |
15 1. (Note: All these scripts assume you’re using "bash" (default) as your shell
.) | 19 1. Get the code! You’ll want a second checkout as this will be |
16 1. Sync and runhooks (be careful not to run hooks on the first sync): | 20 android-specific. You know the drill: |
17 ``` | 21 http://dev.chromium.org/developers/how-tos/get-the-code |
18 gclient sync --nohooks | 22 1. Append this to your `.gclient` file: `target_os = ['android']` |
19 . build/android/envsetup.sh | 23 1. Create `chromium.gyp_env` next to your `.gclient` file: |
20 gclient runhooks | 24 `echo "{ 'GYP_DEFINES': 'OS=android', }" > chromium.gyp_env` |
21 ``` | 25 1. (Note: All these scripts assume you’re using "bash" (default) as your |
22 1. No need to install any API Keys. | 26 shell.) |
23 1. Install Oracle’s Java: http://goo.gl/uPRSq. Grab the appropriate x64 .bin f
ile, `chmod +x`, and then execute to extract. You then move that extracted tree
into /usr/lib/jvm/, rename it java-6-sun and set: | 27 1. Sync and runhooks (be careful not to run hooks on the first sync): |
24 ``` | 28 |
25 export JAVA_HOME=/usr/lib/jvm/java-6-sun | 29 ``` |
26 export ANDROID_JAVA_HOME=/usr/lib/jvm/java-6-sun | 30 gclient sync --nohooks |
27 ``` | 31 . build/android/envsetup.sh |
28 1. Type ‘`java -version`’ and make sure it says java version "1.6.0\_35” witho
ut any mention of openjdk before proceeding. | 32 gclient runhooks |
29 1. `sudo build/install-build-deps-android.sh` | 33 ``` |
30 1. Time to build! | 34 |
31 ``` | 35 1. No need to install any API Keys. |
32 ninja -C out/Release content_shell_apk | 36 1. Install Oracle’s Java: http://goo.gl/uPRSq. Grab the appropriate x64 .bin |
33 ``` | 37 file, `chmod +x`, and then execute to extract. You then move that extracted |
| 38 tree into /usr/lib/jvm/, rename it java-6-sun and set: |
| 39 |
| 40 ``` |
| 41 export JAVA_HOME=/usr/lib/jvm/java-6-sun |
| 42 export ANDROID_JAVA_HOME=/usr/lib/jvm/java-6-sun |
| 43 ``` |
| 44 |
| 45 1. Type ‘`java -version`’ and make sure it says java version `1.6.0_35` without |
| 46 any mention of openjdk before proceeding. |
| 47 1. `sudo build/install-build-deps-android.sh` |
| 48 1. Time to build! |
| 49 |
| 50 ``` |
| 51 ninja -C out/Release content_shell_apk |
| 52 ``` |
34 | 53 |
35 ## Setup the physical device | 54 ## Setup the physical device |
36 | 55 |
37 > Plug in your device. Make sure you can talk to your device, try "`adb shell ls
`" | 56 Plug in your device. Make sure you can talk to your device, try "`adb shell ls`" |
38 | 57 |
39 ## Root your device and install a userdebug build | 58 ## Root your device and install a userdebug build |
40 | 59 |
41 1. This may require building your own version of Android: http://source.androi
d.com/source/building-devices.html | 60 1. This may require building your own version of Android: |
42 1. A build that works is: manta / android-4.2.2\_r1 or master /» full\_ma
nta-userdebug. | 61 http://source.android.com/source/building-devices.html |
| 62 1. A build that works is: `manta / android-4.2.2_r1` or |
| 63 `master / full_manta-userdebug`. |
43 | 64 |
44 ## Root your device | 65 ## Root your device |
45 1. Run `adb root`. Every time you connect your device you’ll want to run this. | 66 |
46 1. If adb is not available, make sure to run “`. build/android/envsetup.sh`” | 67 1. Run `adb root`. Every time you connect your device you’ll want to run this. |
47 > If you get the error “error: device offline”, you may need to become a develo
per on your device before Linux will see it. On Jellybean 4.2.1 and above this r
equires going to “about phone” or “about tablet” and clicking the build number 7
times: http://androidmuscle.com/how-to-enable-usb-debugging-developer-options-o
n-nexus-4-and-android-4-2-devices/ | 68 1. If adb is not available, make sure to run `. build/android/envsetup.sh` |
| 69 |
| 70 If you get the error `error: device offline`, you may need to become a developer |
| 71 on your device before Linux will see it. On Jellybean 4.2.1 and above this |
| 72 requires going to “about phone” or “about tablet” and clicking the build number |
| 73 7 times: |
| 74 http://androidmuscle.com/how-to-enable-usb-debugging-developer-options-on-nexus-
4-and-android-4-2-devices/ |
48 | 75 |
49 ## Run a Telemetry perf profiler | 76 ## Run a Telemetry perf profiler |
50 | 77 |
51 You can run any Telemetry benchmark with --profiler=perf, and it will: | 78 You can run any Telemetry benchmark with `--profiler=perf`, and it will: |
52 1) Download "perf" and "perfhost" | 79 |
53 2) Install on your device | 80 1. Download `perf` and `perfhost` |
54 3) Run the test | 81 1. Install on your device |
55 4) Setup symlinks to work with the --symfs parameter | 82 1. Run the test |
56 | 83 1. Setup symlinks to work with the `--symfs` parameter |
57 | 84 |
58 You can also run "manual" tests with Telemetry, more information here: | 85 You can also run "manual" tests with Telemetry, more information here: |
59 http://www.chromium.org/developers/telemetry/profiling#TOC-Manual-Profiling---An
droid | 86 http://www.chromium.org/developers/telemetry/profiling#TOC-Manual-Profiling---An
droid |
60 | 87 |
61 The following steps describe building "perf", which is no longer necessary if yo
u use Telemetry. | 88 The following steps describe building `perf`, which is no longer necessary if |
62 | 89 you use Telemetry. |
63 | 90 |
64 ## Install /system/bin/perf on your device (not needed for Telemetry) | 91 ## Install `/system/bin/perf` on your device (not needed for Telemetry) |
65 | 92 |
66 ``` | 93 # From inside the android source tree (not inside Chromium) |
67 # From inside the android source tree (not inside Chromium) | 94 mmm external/linux-tools-perf/ |
68 mmm external/linux-tools-perf/ | 95 adb remount # (allows you to write to the system image) |
69 adb remount # (allows you to write to the system image) | 96 adb sync |
70 adb sync | 97 adb shell perf top # check that perf can get samples (don’t expect symbols) |
71 adb shell perf top # check that perf can get samples (don’t expect symbols) | |
72 ``` | |
73 | 98 |
74 ## Enable profiling | 99 ## Enable profiling |
75 > Rebuild content\_shell\_apk with profiling enabled | 100 |
76 ``` | 101 Rebuild `content_shell_apk` with profiling enabled |
77 export GYP_DEFINES="$GYP_DEFINES profiling=1" | 102 |
78 build/gyp_chromium | 103 export GYP_DEFINES="$GYP_DEFINES profiling=1" |
79 ninja -C out/Release content_shell_apk | 104 build/gyp_chromium |
80 ``` | 105 ninja -C out/Release content_shell_apk |
| 106 |
81 ## Install ContentShell | 107 ## Install ContentShell |
82 > Install with the following: | 108 |
83 ``` | 109 Install with the following: |
84 build/android/adb_install_apk.py --apk out/Release/apks/ContentShell.apk --apk_p
ackage org.chromium.content_shell | 110 |
85 ``` | 111 build/android/adb_install_apk.py \ |
| 112 --apk out/Release/apks/ContentShell.apk \ |
| 113 --apk_package org.chromium.content_shell |
86 | 114 |
87 ## Run ContentShell | 115 ## Run ContentShell |
88 > Run with the following: | 116 |
89 ``` | 117 Run with the following: |
90 ./build/android/adb_run_content_shell | 118 |
91 ``` | 119 ./build/android/adb_run_content_shell |
92 > If content\_shell “stopped unexpectedly” use “`adb logcat`” to debug. If you
see ResourceExtractor exceptions, a clean build is your solution. crbug.com/164
220 | 120 |
93 | 121 If `content_shell` “stopped unexpectedly” use `adb logcat` to debug. If you see |
94 ## Setup a “symbols” directory with symbols from your build (not needed for Tele
metry) | 122 ResourceExtractor exceptions, a clean build is your solution. |
95 1. Figure out exactly what path content\_shell\_apk (or chrome, etc) installs
to. | 123 https://crbug.com/164220 |
96 * On the device, navigate ContentShell to about:crash | 124 |
97 ``` | 125 ## Setup a `symbols` directory with symbols from your build (not needed for Tele
metry) |
98 adb logcat | grep libcontent_shell_content_view.so | 126 |
99 ``` | 127 1. Figure out exactly what path `content_shell_apk` (or chrome, etc) installs |
100 > > You should find a path that’s something like /data/app-lib/org.chromium.cont
ent\_shell-1/libcontent\_shell\_content\_view.so | 128 to. |
101 1. Make a symbols directory | 129 * On the device, navigate ContentShell to about:crash |
102 ``` | 130 |
103 mkdir symbols (this guide assumes you put this next to src/) | 131 |
104 ``` | 132 adb logcat | grep libcontent_shell_content_view.so |
105 1. Make a symlink from your symbols directory to your un-stripped content\_she
ll. | 133 |
106 ``` | 134 You should find a path that’s something like |
107 mkdir -p symbols/data/app-lib/org.chromium.content_shell-1 (or whatever path in
app-lib you got above) | 135 `/data/app-lib/org.chromium.content_shell-1/libcontent_shell_content_view.so` |
108 ln -s `pwd`/src/out/Release/lib/libcontent_shell_content_view.so `pwd`/symbols/d
ata/app-lib/org.chromium.content_shell-1 | 136 |
109 ``` | 137 1. Make a symbols directory |
110 | 138 ``` |
111 ## Install perfhost\_linux locally (not needed for Telemetry) | 139 mkdir symbols (this guide assumes you put this next to src/) |
112 | 140 ``` |
113 | 141 1. Make a symlink from your symbols directory to your un-stripped |
114 > Note: modern versions of perf may also be able to process the perf.data files
from the device. | 142 `content_shell`. |
115 1. perfhost\_linux can be built from: https://android.googlesource.com/platfor
m/external/linux-tools-perf/. | 143 |
116 1. Place perfhost\_linux next to symbols, src, etc. | 144 ``` |
117 ``` | 145 # Use whatever path in app-lib you got above |
118 chmod a+x perfhost_linux | 146 mkdir -p symbols/data/app-lib/org.chromium.content_shell-1 |
119 ``` | 147 ln -s `pwd`/src/out/Release/lib/libcontent_shell_content_view.so \ |
| 148 `pwd`/symbols/data/app-lib/org.chromium.content_shell-1 |
| 149 ``` |
| 150 |
| 151 ## Install `perfhost_linux` locally (not needed for Telemetry) |
| 152 |
| 153 Note: modern versions of perf may also be able to process the perf.data files |
| 154 from the device. |
| 155 |
| 156 1. `perfhost_linux` can be built from: |
| 157 https://android.googlesource.com/platform/external/linux-tools-perf/. |
| 158 1. Place `perfhost_linux` next to symbols, src, etc. |
| 159 |
| 160 chmod a+x perfhost_linux |
120 | 161 |
121 ## Actually record a profile on the device! | 162 ## Actually record a profile on the device! |
122 > Run the following: | 163 |
123 ``` | 164 Run the following: |
124 adb shell ps | grep content (look for the pid of the sandboxed_process) | 165 |
125 adb shell perf record -g -p 12345 sleep 5 | 166 adb shell ps | grep content (look for the pid of the sandboxed_process) |
126 adb pull /data/perf.data | 167 adb shell perf record -g -p 12345 sleep 5 |
127 ``` | 168 adb pull /data/perf.data |
| 169 |
128 | 170 |
129 ## Create the report | 171 ## Create the report |
130 1. Run the following: | 172 |
131 ``` | 173 1. Run the following: |
132 ./perfhost_linux report -g -i perf.data --symfs symbols/ | 174 |
133 ``` | 175 ``` |
134 1. If you don’t see chromium/webkit symbols, make sure that you built/pushed R
elease, and that the symlink you created to the .so is valid! | 176 ./perfhost_linux report -g -i perf.data --symfs symbols/ |
135 1. If you have symbols, but your callstacks are nonsense, make sure you ran bu
ild/gyp\_chromium after setting profiling=1, and rebuilt. | 177 ``` |
| 178 |
| 179 1. If you don’t see chromium/webkit symbols, make sure that you built/pushed |
| 180 Release, and that the symlink you created to the .so is valid! |
| 181 1. If you have symbols, but your callstacks are nonsense, make sure you ran |
| 182 `build/gyp_chromium` after setting `profiling=1`, and rebuilt. |
136 | 183 |
137 ## Add symbols for the kernel | 184 ## Add symbols for the kernel |
138 1. By default, /proc/kallsyms returns 0 for all symbols, to fix this, set “/pr
oc/sys/kernel/kptr\_restrict” to 0: | 185 |
139 ``` | 186 1. By default, /proc/kallsyms returns 0 for all symbols, to fix this, set |
140 adb shell echo “0” > /proc/sys/kernel/kptr_restrict | 187 `/proc/sys/kernel/kptr_restrict` to `0`: |
141 ``` | 188 |
142 1. See http://lwn.net/Articles/420403/ for explanation of what this does. | 189 ``` |
143 ``` | 190 adb shell echo “0” > /proc/sys/kernel/kptr_restrict |
144 adb pull /proc/kallsyms symbols/kallsyms | 191 ``` |
145 ``` | 192 |
146 1. Now add --kallsyms to your perfhost\_linux command: | 193 1. See http://lwn.net/Articles/420403/ for explanation of what this does. |
147 ``` | 194 |
148 ./perfhost_linux report -g -i perf.data --symfs symbols/ --kallsyms=symbols/kall
syms | 195 ``` |
149 ``` | 196 adb pull /proc/kallsyms symbols/kallsyms |
| 197 ``` |
| 198 |
| 199 1. Now add --kallsyms to your perfhost\_linux command: |
| 200 ``` |
| 201 ./perfhost_linux report -g -i perf.data --symfs symbols/ \ |
| 202 --kallsyms=symbols/kallsyms |
| 203 ``` |
OLD | NEW |