- Using
time ninja installinstead ofninja installto time it overall - Reading ninja’s log files to get a per-file compile time
- Enabling GCC or Clang flags to get a more detailed per-file breakdown of times for compiler passes within a file
Ninja log files
Ninja produces a handy log file that includes a per-cpp-file compilation time. This is useful for discovering which files take the most time, and so are good targets for speeding up the overall build time. A python3 script namedninjatracing converts the ninja log file into a JSON format that’s readable by several profile viewers.
Prerequisites
ninjatracing is available on GitHub.
It requires python3, available at python. You can either create the symlink yourself, or just modify the ninjatracing file to say python3 instead of python.
You also need to make sure
ninjatracing is marked as executable, and available from your PATH (or somewhere convenient where you can manually call it from).Usage
Clean the build
First, we need to clean the build (and
ccache if present) to make sure every file gets compiled and gives a meaningful time reading.Visualize the results
You can then drag-and-drop the file onto Speedscope or any other compatible flamegraph visualizer.
GCC/Clang compiler flags
Adding the-ftime-report flag to GCC will cause it to output a breakdown for each file it compiles.
Example output
Depending on whether you understand the internals of the compiler, this may or may not be helpful to you! Generally, this is not recommended unless you’re doing deep compiler optimization work.
-ftime-report, but the output format may differ.
How to enable
To add the flag, edit theCMakeLists.txt in the ladybird root directory, and add add_compile_options(-ftime-report) to the list of compile options that start around line 220.
Additionally, you can add -ftime-report-details for even more detailed output.