Daniel's working notes

Profiling Bazel

Bazel have a tool to allow us profile our build. With this tool, we know build duration of each module so we could optimize it later.

Generate profiling files

Based on the documentation bazel writes JSON in the output base. We could use Chrome or Edge to open the json file. In Chrome, go to chrome://tracing or edge://tracing then load the JSON files.

Few things we could take a note when analyzing the generated profile based on the documentation:

  • Individual slow action, especially in the Critical action path, this mean it’s blocking other execution
  • Slower than expected analysis phase, especially on incremental builds.

To generate build profile, we could pass --profile=<path-to-profile>/prof in our build command or add them in bazelrc

Once the build is done, we could run bazelizk analyze_profile <path-to-prof-file>

The output will be like this

In the json generated by Bazel, ts or timestamps and dur or duration are given in microseconds.

Source: Optimizing performance - Bazel main

Linked Notes: