Skip to main content
There are three ways you can get information about compile times:
  1. Using time ninja install instead of ninja install to time it overall
  2. Reading ninja’s log files to get a per-file compile time
  3. 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 named ninjatracing 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

1

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.
ninja clean
ccache --clear
2

Execute ninja

ninja
The log will be written to .ninja_log in the current directory by default.
3

Convert the log to JSON

Call ninjatracing from the directory you called ninja from:
ninjatracing .ninja_log > trace.json
4

Visualize the results

You can then drag-and-drop the file onto Speedscope or any other compatible flamegraph visualizer.
The resulting flamegraph will help you identify which files take the longest to compile, making them prime targets for optimization.

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.
Clang also supports -ftime-report, but the output format may differ.

How to enable

To add the flag, edit the CMakeLists.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.
Enabling these flags will produce a lot of output and may significantly slow down the compilation process. Use sparingly and only when profiling specific compilation issues.

Build docs developers (and LLMs) love