Improving Ninja’s “-d explain” output

69 views
Skip to first unread message

David Rothlisberger

unread,
Feb 24, 2022, 11:30:22 AMFeb 24
to ninja-build

Ninja’s “-d explain” command-line option is supposed to explain what caused a build target to be re-built, but it’s next to useless in a large build: It says what’s dirty but it’s hard to relate which dirty input caused which output to be re-built. At the beginning of your build you get pages & pages of “these things are dirty” and then it starts the actual build. Also, this “explain” output is printed before ninja has realised that a lot of those things aren’t actually dirty (thanks to “restat”).

I wrote pull request #2067 to make the explain output more useful. I have been using this for 6 weeks now and it works well. The implementation is dead simple: Instead of printing the explain string immediately, the EXPLAIN macro saves it to a map, and we print it later. So Ninja will use a bit more memory, but only if you use -d explain.

The pull request has a unit test with a comparison of the output before & after my patch. For a real world example, at my company's build system a no-op build prints 1,800 lines of explain output; with my patch it's 93 lines (from only the rules that are run before restat prunes everything else away). See a sample of that build output at https://david.rothlis.net/ninja-explain/

Cheers,
Dave R.

Reply all
Reply to author
Forward
0 new messages