I am looking to reliably measure the time spent in each phase while building a derivation. I am primarily interested in the
Additionally, I need to have such metrics even when a derivation fails to build.
I found this open issue 1. Do you have any other pointers?
The generic builder currently logs the start of each phase to Nix using a structured log message: https://github.com/NixOS/nixpkgs/blob/2c166749c9ef9440defccf94f50cc8f1a9852b3c/pkgs/stdenv/generic/setup.sh#L1377-L1379
Currently this is only used in Nix to update the progress bar, but we could use it to infer the duration of each phase. Or change
showPhaseFooter (https://github.com/NixOS/nixpkgs/blob/2c166749c9ef9440defccf94f50cc8f1a9852b3c/pkgs/stdenv/generic/setup.sh#L1392) to emit a structured log message to $NIX_LOG_FD showing the duration. However, that won’t work if the phase fails.
I will into this, thank you @edolstra!
nom is already using that.