andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 1 | # Profiling Content Shell on Android |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 2 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 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] |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 8 | |
| 9 | ## Prepare your device. |
| 10 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 11 | You need an Android 4.2+ device (Galaxy Nexus, Nexus 4, 7, 10, etc.) which you |
| 12 | don’t mind erasing all data, rooting, and installing a userdebug build on. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 13 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 14 | ## Get and build `content_shell_apk` for Android |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 15 | |
Andrew Grieve | b747e71 | 2017-11-23 16:58:31 | [diff] [blame] | 16 | More detailed insturctions in [android_build_instructions.md](android_build_instructions.md). |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 17 | |
Andrew Grieve | b747e71 | 2017-11-23 16:58:31 | [diff] [blame] | 18 | ```shell |
| 19 | ninja -C out/Release content_shell_apk |
| 20 | ``` |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 21 | |
| 22 | ## Setup the physical device |
| 23 | |
Andrew Grieve | b747e71 | 2017-11-23 16:58:31 | [diff] [blame] | 24 | Plug in your device. Make sure you can talk to your device, try: |
| 25 | |
| 26 | ```shell |
| 27 | third_party/android_tools/sdk/platform-tools/adb shell ls |
| 28 | ``` |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 29 | |
| 30 | ## Root your device and install a userdebug build |
| 31 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 32 | 1. This may require building your own version of Android: |
| 33 | http://source.android.com/source/building-devices.html |
| 34 | 1. A build that works is: `manta / android-4.2.2_r1` or |
| 35 | `master / full_manta-userdebug`. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 36 | |
| 37 | ## Root your device |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 38 | |
| 39 | 1. Run `adb root`. Every time you connect your device you’ll want to run this. |
| 40 | 1. If adb is not available, make sure to run `. build/android/envsetup.sh` |
| 41 | |
| 42 | If you get the error `error: device offline`, you may need to become a developer |
| 43 | on your device before Linux will see it. On Jellybean 4.2.1 and above this |
| 44 | requires going to “about phone” or “about tablet” and clicking the build number |
| 45 | 7 times: |
| 46 | http://androidmuscle.com/how-to-enable-usb-debugging-developer-options-on-nexus-4-and-android-4-2-devices/ |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 47 | |
jbroman | 349e3d7 | 2016-05-10 19:15:17 | [diff] [blame] | 48 | ## Enable profiling |
| 49 | |
| 50 | Rebuild `content_shell_apk` with profiling enabled. |
| 51 | |
jbroman | 349e3d7 | 2016-05-10 19:15:17 | [diff] [blame] | 52 | With 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 | |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 59 | ## Run a Telemetry perf profiler |
| 60 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 61 | You can run any Telemetry benchmark with `--profiler=perf`, and it will: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 62 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 63 | 1. Download `perf` and `perfhost` |
jbroman | 349e3d7 | 2016-05-10 19:15:17 | [diff] [blame] | 64 | 2. Install on your device |
| 65 | 3. Run the test |
| 66 | 4. Setup symlinks to work with the `--symfs` parameter |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 67 | |
| 68 | You can also run "manual" tests with Telemetry, more information here: |
xiaoyin.l | 1003c0b | 2016-12-06 02:51:17 | [diff] [blame] | 69 | https://www.chromium.org/developers/telemetry/profiling#TOC-Manual-Profiling---Android |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 70 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 71 | The following steps describe building `perf`, which is no longer necessary if |
| 72 | you use Telemetry. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 73 | |
jbroman | 349e3d7 | 2016-05-10 19:15:17 | [diff] [blame] | 74 | ## Use `adb_profile_chrome` |
| 75 | |
| 76 | Even if you're not running a Telemetry test, you can use Catapult to |
| 77 | automatically push binaries and pull the profile data for you. |
| 78 | |
| 79 | build/android/adb_profile_chrome --browser=content_shell --perf |
| 80 | |
| 81 | While you still have to build, install and launch the APK yourself, Catapult |
| 82 | will take care of creating the symfs etc. (i.e. you can skip the "not needed for |
| 83 | Telemetry" steps below). |
| 84 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 85 | ## Install `/system/bin/perf` on your device (not needed for Telemetry) |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 86 | |
qyearsley | c0dc6f4 | 2016-12-02 22:13:39 | [diff] [blame] | 87 | # From inside the Android source tree (not inside Chromium) |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 88 | 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) |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 92 | |
Andrew Grieve | b747e71 | 2017-11-23 16:58:31 | [diff] [blame] | 93 | ## Install and Run ContentShell |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 94 | |
| 95 | Install with the following: |
| 96 | |
Andrew Grieve | b747e71 | 2017-11-23 16:58:31 | [diff] [blame] | 97 | out/Release/bin/content_shell_apk run |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 98 | |
Andrew Grieve | b747e71 | 2017-11-23 16:58:31 | [diff] [blame] | 99 | If `content_shell` “stopped unexpectedly” use `adb logcat` to debug. |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 100 | |
| 101 | ## Setup a `symbols` directory with symbols from your build (not needed for Telemetry) |
| 102 | |
| 103 | 1. Figure out exactly what path `content_shell_apk` (or chrome, etc) installs |
| 104 | to. |
| 105 | * On the device, navigate ContentShell to about:crash |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 106 | |
| 107 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 108 | adb logcat | grep libcontent_shell_content_view.so |
| 109 | |
| 110 | You should find a path that’s something like |
| 111 | `/data/app-lib/org.chromium.content_shell-1/libcontent_shell_content_view.so` |
| 112 | |
| 113 | 1. Make a symbols directory |
| 114 | ``` |
| 115 | mkdir symbols (this guide assumes you put this next to src/) |
| 116 | ``` |
| 117 | 1. 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 | |
| 129 | Note: modern versions of perf may also be able to process the perf.data files |
| 130 | from the device. |
| 131 | |
| 132 | 1. `perfhost_linux` can be built from: |
| 133 | https://android.googlesource.com/platform/external/linux-tools-perf/. |
| 134 | 1. Place `perfhost_linux` next to symbols, src, etc. |
| 135 | |
| 136 | chmod a+x perfhost_linux |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 137 | |
| 138 | ## Actually record a profile on the device! |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 139 | |
| 140 | Run the following: |
| 141 | |
Andrew Grieve | b747e71 | 2017-11-23 16:58:31 | [diff] [blame] | 142 | out/Release/content_shell_apk ps (look for the pid of the sandboxed_process) |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 143 | adb shell perf record -g -p 12345 sleep 5 |
| 144 | adb pull /data/perf.data |
| 145 | |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 146 | ## Create the report |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 147 | |
| 148 | 1. Run the following: |
| 149 | |
| 150 | ``` |
| 151 | ./perfhost_linux report -g -i perf.data --symfs symbols/ |
| 152 | ``` |
| 153 | |
| 154 | 1. 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! |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 156 | |
| 157 | ## Add symbols for the kernel |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 158 | |
| 159 | 1. 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 | |
| 166 | 1. See http://lwn.net/Articles/420403/ for explanation of what this does. |
| 167 | |
| 168 | ``` |
| 169 | adb pull /proc/kallsyms symbols/kallsyms |
| 170 | ``` |
| 171 | |
| 172 | 1. Now add --kallsyms to your perfhost\_linux command: |
| 173 | ``` |
| 174 | ./perfhost_linux report -g -i perf.data --symfs symbols/ \ |
| 175 | --kallsyms=symbols/kallsyms |
| 176 | ``` |