• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Debugging Slow Builds
2
3Did you know that Ninja writes a log to disk after each build?
4
5To see what kinds of files took the longest for your previous build:
6
7```sh
8cd out/Default
9# Lives in depot_tools:
10post_build_ninja_summary.py
11```
12
13You can also set `NINJA_SUMMARIZE_BUILD=1` to have this command run
14after each `autoninja` invocation (also runs ninja with `-d stats`).
15
16To generate a Chrome trace of your most recent build:
17
18```sh
19git clone https://github.com/nico/ninjatracing
20ninjatracing/ninjatracing out/Default/.ninja_log > trace.json
21# Then open in https://ui.perfetto.dev/
22```
23
24## Slow Bot Builds
25
26Our bots run `ninjatracing` and `post_build_ninja_summary.py` as well.
27
28Find the trace at: `postprocess_for_goma > upload_log > ninja_log`:
29
30 * _".ninja_log in table format (full)"_ is for `post_build_ninja_summary.py`.
31 * _"trace viewer (sort_by_end)"_ is for `ninjatracing`.
32
33## Advanced(ish) Tips
34
35* Use `gn gen --tracelog trace.json` to create a trace for `gn gen`.
36* Many Android templates make use of
37  [`md5_check.py`](https://cs.chromium.org/chromium/src/build/android/gyp/util/md5_check.py)
38  to optimize incremental builds.
39  * Set `PRINT_BUILD_EXPLANATIONS=1` to have these commands log which inputs
40    changed.
41* If you suspect files are being rebuilt unnecessarily during incremental
42  builds:
43  * Use `ninja -n -d explain` to figure out why ninja thinks a target is dirty.
44  * Ensure actions are taking advantage of ninja's `restat=1` feature by not
45    updating timestamps on outputs when their contents do not change.
46    * E.g. by using [`build_utils.AtomicOutput()`]
47
48[`build_utils.AtomicOutput()`]: https://source.chromium.org/search?q=symbol:AtomicOutput%20f:build
49