Reporting build timings - The Cargo Book (original) (raw)

The Cargo Book

Reporting build timings

The --timings option gives some information about how long each compilation takes, and tracks concurrency information over time.

cargo build --timings

This writes an HTML report in target/cargo-timings/cargo-timing.html. This also writes a copy of the report to the same directory with a timestamp in the filename, if you want to look at older runs.

Reading the graphs

There are two tables and two graphs in the output.

The first table displays the build information of the project, including the number of units built, the maximum number of concurrency, build time, and the version information of the currently used compiler.

build-info

The “unit” graph shows the duration of each unit over time. A “unit” is a single compiler invocation. There are lines that show which additional units are “unlocked” when a unit finishes. That is, it shows the new units that are now allowed to run because their dependencies are all finished. Hover the mouse over a unit to highlight the lines. This can help visualize the critical path of dependencies. This may change between runs because the units may finish in different orders.

The “codegen” times are highlighted in a lavender color. In some cases, build pipelining allows units to start when their dependencies are performing code generation. This information is not always displayed (for example, binary units do not show when code generation starts).

The “custom build” units are build.rs scripts, which when run are highlighted in orange.

build-unit-time

The second graph shows Cargo’s concurrency over time. The background indicates CPU usage. The three lines are:

cargo-concurrency-over-time

Note: This does not show the concurrency in the compiler itself. rustccoordinates with Cargo via the “job server” to stay within the concurrency limit. This currently mostly applies to the code generation phase.

Tips for addressing compile times:

The last table lists the total time and “codegen” time spent on each unit, as well as the features that were enabled during each unit’s compilation.