Primiano Tucci | b808373 | 2018-04-09 15:38:37 +0100 | [diff] [blame] | 1 | # Perfetto build instructions |
Primiano Tucci | 8f266ad | 2018-01-15 16:52:38 +0000 | [diff] [blame] | 2 | |
Primiano Tucci | b808373 | 2018-04-09 15:38:37 +0100 | [diff] [blame] | 3 | The source of truth for the Perfetto codebase currently lives in AOSP: |
| 4 | https://android.googlesource.com/platform/external/perfetto/ |
| 5 | |
| 6 | Perfetto can be built both from the Android tree (AOSP) and standalone. |
| 7 | Standalone builds are meant only for local testing and are not shipped. |
Primiano Tucci | 8f266ad | 2018-01-15 16:52:38 +0000 | [diff] [blame] | 8 | Due to the reduced dependencies they are faster to iterate on and the |
| 9 | suggested way to work on Perfetto. |
| 10 | |
Primiano Tucci | 8f266ad | 2018-01-15 16:52:38 +0000 | [diff] [blame] | 11 | Get the code |
| 12 | ------------ |
Primiano Tucci | b808373 | 2018-04-09 15:38:37 +0100 | [diff] [blame] | 13 | **Standalone checkout**: |
Primiano Tucci | 8f266ad | 2018-01-15 16:52:38 +0000 | [diff] [blame] | 14 | ``` |
Primiano Tucci | b808373 | 2018-04-09 15:38:37 +0100 | [diff] [blame] | 15 | $ git clone https://android.googlesource.com/platform/external/perfetto/ |
Primiano Tucci | 8f266ad | 2018-01-15 16:52:38 +0000 | [diff] [blame] | 16 | ``` |
| 17 | |
Primiano Tucci | b808373 | 2018-04-09 15:38:37 +0100 | [diff] [blame] | 18 | **Android tree**: |
| 19 | Perfetto lives in `external/perfetto` in the AOSP tree. |
| 20 | |
| 21 | |
| 22 | Prerequisites |
| 23 | ------------- |
| 24 | **Standalone checkout**: |
| 25 | All dependent libraries are self-hosted and pulled through: |
| 26 | ``` |
Hector Dearman | 4763d92 | 2018-05-23 10:12:03 +0100 | [diff] [blame] | 27 | $ tools/install-build-deps [--no-android] [--ui] |
Primiano Tucci | b808373 | 2018-04-09 15:38:37 +0100 | [diff] [blame] | 28 | ``` |
| 29 | |
| 30 | **Android tree**: |
| 31 | See https://source.android.com/setup |
| 32 | |
| 33 | |
| 34 | Building |
| 35 | -------- |
| 36 | **Standalone checkout**: |
Primiano Tucci | 8f266ad | 2018-01-15 16:52:38 +0000 | [diff] [blame] | 37 | If you are a chromium developer and have depot_tools installed you can avoid |
| 38 | the `tools/` prefix below and just use gn/ninja from depot_tools. |
| 39 | |
Primiano Tucci | 8f266ad | 2018-01-15 16:52:38 +0000 | [diff] [blame] | 40 | `$ tools/gn args out/android` to generate build files and enter in the editor: |
| 41 | |
| 42 | ``` |
Primiano Tucci | b808373 | 2018-04-09 15:38:37 +0100 | [diff] [blame] | 43 | target_os = "android" # Only when building for Android |
| 44 | target_cpu = "arm" / "arm64" / "x64" # Only when building for Android |
| 45 | is_debug = true / false |
Primiano Tucci | 8f266ad | 2018-01-15 16:52:38 +0000 | [diff] [blame] | 46 | ``` |
| 47 | |
| 48 | (See the [Build Configurations](#build-configurations) section below for more) |
| 49 | |
| 50 | ``` |
Primiano Tucci | b808373 | 2018-04-09 15:38:37 +0100 | [diff] [blame] | 51 | $ tools/ninja -C out/android |
Primiano Tucci | 8f266ad | 2018-01-15 16:52:38 +0000 | [diff] [blame] | 52 | ``` |
| 53 | |
Hector Dearman | 4763d92 | 2018-05-23 10:12:03 +0100 | [diff] [blame] | 54 | To build the UI (remember to run `tools/install-build-deps --ui` first): |
| 55 | |
| 56 | ``` |
| 57 | $ tools/ninja -C out/android ui |
| 58 | ``` |
| 59 | |
Primiano Tucci | b808373 | 2018-04-09 15:38:37 +0100 | [diff] [blame] | 60 | **Android tree**: |
Primiano Tucci | 8f266ad | 2018-01-15 16:52:38 +0000 | [diff] [blame] | 61 | `$ mmma external/perfetto` |
| 62 | or |
Primiano Tucci | b808373 | 2018-04-09 15:38:37 +0100 | [diff] [blame] | 63 | `$ m perfetto traced traced_probes` |
Primiano Tucci | 8f266ad | 2018-01-15 16:52:38 +0000 | [diff] [blame] | 64 | |
| 65 | This will generate artifacts `out/target/product/XXX/system/`. |
| 66 | Executables and shared libraries are stripped by default by the Android build |
Primiano Tucci | b808373 | 2018-04-09 15:38:37 +0100 | [diff] [blame] | 67 | system. The unstripped artifacts are kept into `out/target/product/XXX/symbols`. |
Primiano Tucci | 8f266ad | 2018-01-15 16:52:38 +0000 | [diff] [blame] | 68 | |
Primiano Tucci | b808373 | 2018-04-09 15:38:37 +0100 | [diff] [blame] | 69 | Build files |
| 70 | ----------- |
Primiano Tucci | 8f266ad | 2018-01-15 16:52:38 +0000 | [diff] [blame] | 71 | The source of truth of our build file is in the BUILD.gn files, which are based on [GN][gn-quickstart]. |
| 72 | The Android build file ([Android.bp](../Android.bp)) is autogenerated from the GN files |
| 73 | through `tools/gen_android_bp`, which needs to be invoked whenever a change |
Primiano Tucci | b808373 | 2018-04-09 15:38:37 +0100 | [diff] [blame] | 74 | touches GN files or introduces new ones. |
Primiano Tucci | 8f266ad | 2018-01-15 16:52:38 +0000 | [diff] [blame] | 75 | A presubmit check checks that the Android.bp is consistent with GN files when |
Primiano Tucci | b808373 | 2018-04-09 15:38:37 +0100 | [diff] [blame] | 76 | submitting a CL through `git cl upload`. |
Primiano Tucci | 8f266ad | 2018-01-15 16:52:38 +0000 | [diff] [blame] | 77 | The generator has a whitelist of root targets that will be translated into the |
| 78 | Android.bp file. If you are adding a new target, add a new entry to the |
| 79 | `default_targets` variable inside [tools/gen_android_bp](../tools/gen_android_bp). |
| 80 | |
| 81 | |
Primiano Tucci | b808373 | 2018-04-09 15:38:37 +0100 | [diff] [blame] | 82 | Supported platforms |
| 83 | ------------------- |
| 84 | **Linux desktop** (Debian Rodete): |
| 85 | - Hermetic clang + libcxx toolchain (both following chromium's revisions) |
| 86 | - GCC-7 and libstdc++ 6 |
| 87 | |
| 88 | **Android**: |
| 89 | - Android's NDK r15c (using NDK's libcxx) |
| 90 | - AOSP's in-tree clang (using in-tree libcxx) |
| 91 | |
| 92 | **Mac**: |
| 93 | - XCode 9 / clang (currently maintained best-effort). |
| 94 | |
| 95 | |
| 96 | |
| 97 | Build configurations |
| 98 | -------------------- |
| 99 | *** aside |
| 100 | `tools/build_all_configs.py` can be used to generate out/XXX folders for most of |
| 101 | the supported configurations. |
| 102 | *** |
| 103 | |
Primiano Tucci | 8f266ad | 2018-01-15 16:52:38 +0000 | [diff] [blame] | 104 | The following [GN args][gn-quickstart] are supported: |
| 105 | |
| 106 | `target_os = "android" | "linux" | "mac"`: |
| 107 | Defaults to the current host, set "android" to build for Android. |
| 108 | |
| 109 | `target_cpu = "arm" | "arm64" | "x86" | "x64"`: |
| 110 | Defaults to `"arm"` when `target_os` == `"android"`, `"x64"` when targeting the |
| 111 | host. 32-bit host builds are not supported. |
| 112 | |
| 113 | `is_debug = true | false`: |
| 114 | Toggles Debug (default) / Release mode. |
| 115 | |
| 116 | `is_clang = true | false`: |
Primiano Tucci | b808373 | 2018-04-09 15:38:37 +0100 | [diff] [blame] | 117 | Use Clang (default: true) or GCC (false). |
| 118 | On Linux, by default it uses the self-hosted clang (see `is_hermetic_clang`). |
| 119 | On Android, by default it uses clang from the NDK (in `buildtools/ndk`). |
| 120 | On Mac, by default it uses the system version of clang (requires Xcode). |
Primiano Tucci | 8f266ad | 2018-01-15 16:52:38 +0000 | [diff] [blame] | 121 | |
Florian Mayer | ea4fcdb | 2018-01-16 16:56:55 +0000 | [diff] [blame] | 122 | `is_hermetic_clang = true | false`: |
| 123 | Use bundled toolchain from `buildtools/` rather than system-wide one. |
| 124 | |
Primiano Tucci | 8f266ad | 2018-01-15 16:52:38 +0000 | [diff] [blame] | 125 | `cc = "gcc" / cxx = "g++"`: |
| 126 | Uses a different compiler binary (default: autodetected depending on is_clang). |
| 127 | |
| 128 | `is_asan = true`: |
| 129 | Enables [Address Sanitizer](https://github.com/google/sanitizers/wiki/AddressSanitizer) |
| 130 | |
| 131 | `is_lsan = true`: |
| 132 | Enables [Leak Sanitizer](https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer) |
| 133 | (Linux/Mac only) |
| 134 | |
| 135 | `is_msan = true`: |
| 136 | Enables [Memory Sanitizer](https://github.com/google/sanitizers/wiki/MemorySanitizer) |
| 137 | (Linux only) |
| 138 | |
| 139 | `is_tsan = true`: |
| 140 | Enables [Thread Sanitizer](https://github.com/google/sanitizers/wiki/ThreadSanitizerCppManual) |
| 141 | (Linux/Mac only) |
| 142 | |
| 143 | `is_ubsan = true`: |
| 144 | Enables [Undefined Behavior Sanitizer](https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html) |
| 145 | |
| 146 | |
Tom Bridgwater | c6b2cf8 | 2018-08-16 12:49:50 -0700 | [diff] [blame] | 147 | [gn-quickstart]: https://gn.googlesource.com/gn/+/master/docs/quick_start.md |