From 1e2a288f0e84b7064020554cd89415932b458c1b Mon Sep 17 00:00:00 2001 From: Artturin Date: Fri, 1 Apr 2022 17:14:14 +0300 Subject: [PATCH] stdenv: print the time the phase took if it was longer than 30s will be useful for finding why a build runs for a long time on hydra because of tests or the build etc etc --- pkgs/stdenv/generic/setup.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 620244d6e10d..6d30e6c01ffb 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -1305,6 +1305,23 @@ showPhaseHeader() { } +showPhaseFooter() { + local phase="$1" + local startTime="$2" + local endTime="$3" + local delta=$(( endTime - startTime )) + (( $delta < 30 )) && return + + local H=$((delta/3600)) + local M=$((delta%3600/60)) + local S=$((delta%60)) + echo -n "$phase completed in " + (( $H > 0 )) && echo -n "$H hours " + (( $M > 0 )) && echo -n "$M minutes " + echo "$S seconds" +} + + genericBuild() { if [ -f "${buildCommandPath:-}" ]; then source "$buildCommandPath" @@ -1340,10 +1357,16 @@ genericBuild() { showPhaseHeader "$curPhase" dumpVars + local startTime=$(date +"%s") + # Evaluate the variable named $curPhase if it exists, otherwise the # function named $curPhase. eval "${!curPhase:-$curPhase}" + local endTime=$(date +"%s") + + showPhaseFooter "$curPhase" "$startTime" "$endTime" + if [ "$curPhase" = unpackPhase ]; then # make sure we can cd into the directory [ -z "${sourceRoot}" ] || chmod +x "${sourceRoot}"