diff --git a/scripts/build-setup.sh b/scripts/build-setup.sh index aa7ee0ff43..cc767f2b1a 100755 --- a/scripts/build-setup.sh +++ b/scripts/build-setup.sh @@ -133,12 +133,44 @@ run_step() { # In order to run code on error, we must handle errors manually set +e; +# Initialize timing arrays +declare -a STEP_START_TIME +declare -a STEP_END_TIME +declare -a STEP_DESCRIPTION +STEPS=11 + function begin_step { thisStepNum=$1; thisStepDesc=$2; + STEP_DESCRIPTION[$thisStepNum]=$thisStepDesc + STEP_START_TIME[$thisStepNum]=$(date +%s.%N 2>/dev/null || date +%s) echo " ========== BEGINNING STEP $thisStepNum: $thisStepDesc ==========" } +function print_timing_table +{ + echo "" + echo "Per-step timing" + printf "%-8s %-15s %-18s %-20s %s\n" "Step #" "Wall Time (s)" "% of Total Time" "Cumulative Time (s)" "Description" + echo "--------------------------------------------------------------------------------------------------------" + + local -a wt + local total=0 cumulative=0 + for ((i=1; i<=STEPS; i++)); do + [[ -z "${STEP_START_TIME[$i]}" || -z "${STEP_END_TIME[$i]}" ]] && continue + wt[$i]=$(awk "BEGIN {printf \"%.0f\", ${STEP_END_TIME[$i]} - ${STEP_START_TIME[$i]}}") + total=$(awk "BEGIN {printf \"%.0f\", $total + ${wt[$i]}}") + done + + for ((i=1; i<=STEPS; i++)); do + [[ -z "${wt[$i]}" ]] && continue + cumulative=$(awk "BEGIN {printf \"%.0f\", $cumulative + ${wt[$i]}}") + local pct=$(awk -v w="${wt[$i]}" -v t="$total" "BEGIN {if (t > 0) printf \"%.0f\", (w/t)*100; else printf \"%.0f\", 0}") + printf "%-8s %-15.0f %-18.0f %-20.0f %s\n" "$i" "${wt[$i]}" "$pct" "$cumulative" "${STEP_DESCRIPTION[$i]}" + done + printf "%-8s %-15.0f\n" "Total" "$total" + echo "" +} function exit_if_last_command_failed { local exitcode=$?; @@ -223,6 +255,7 @@ END_CONDA_ACTIVATE $CONDA_ACTIVATE_PREAMBLE conda activate $CONDA_ENV_NAME source $CYDIR/scripts/fix-open-files.sh" + STEP_END_TIME[1]=$(date +%s.%N 2>/dev/null || date +%s) fi if [ -z ${CONDA_DEFAULT_ENV+x} ]; then @@ -234,6 +267,7 @@ if run_step "2"; then begin_step "2" "Initializing Chipyard submodules" $CYDIR/scripts/init-submodules-no-riscv-tools.sh --full exit_if_last_command_failed + STEP_END_TIME[2]=$(date +%s.%N 2>/dev/null || date +%s) fi # build extra toolchain collateral (i.e. spike, pk, riscv-tests, libgloss) @@ -250,6 +284,7 @@ if run_step "3"; then fi $CYDIR/scripts/build-toolchain-extra.sh $TOOLCHAIN_TYPE -p $PREFIX exit_if_last_command_failed + STEP_END_TIME[3]=$(date +%s.%N 2>/dev/null || date +%s) fi # run ctags for code navigation @@ -257,6 +292,7 @@ if run_step "4"; then begin_step "4" "Running ctags for code navigation" $CYDIR/scripts/gen-tags.sh exit_if_last_command_failed + STEP_END_TIME[4]=$(date +%s.%N 2>/dev/null || date +%s) fi # precompile chipyard scala sources @@ -267,6 +303,7 @@ if run_step "5"; then make launch-sbt SBT_COMMAND=";project tapeout; compile" && popd exit_if_last_command_failed + STEP_END_TIME[5]=$(date +%s.%N 2>/dev/null || date +%s) fi # setup firesim @@ -275,6 +312,7 @@ if run_step "6"; then $CYDIR/scripts/firesim-setup.sh && $CYDIR/sims/firesim/gen-tags.sh exit_if_last_command_failed + STEP_END_TIME[6]=$(date +%s.%N 2>/dev/null || date +%s) # precompile firesim scala sources if run_step "7"; then @@ -290,6 +328,7 @@ if run_step "6"; then ) exit_if_last_command_failed popd + STEP_END_TIME[7]=$(date +%s.%N 2>/dev/null || date +%s) fi fi @@ -307,10 +346,12 @@ if run_step "8"; then ./marshal $VERBOSE_FLAG build br-base.json && ./marshal $VERBOSE_FLAG build bare-base.json exit_if_last_command_failed + STEP_END_TIME[9]=$(date +%s.%N 2>/dev/null || date +%s) fi popd # Ensure FireMarshal CLI is on PATH in env.sh (idempotent) replace_content env.sh build-setup-marshal "# line auto-generated by build-setup.sh\n__DIR=\"$CYDIR\"\nPATH=\\$__DIR/software/firemarshal:\\$PATH" + STEP_END_TIME[8]=$(date +%s.%N 2>/dev/null || date +%s) fi if run_step "10"; then @@ -341,6 +382,7 @@ if run_step "10"; then -g $GITHUB_TOKEN fi exit_if_last_command_failed + STEP_END_TIME[10]=$(date +%s.%N 2>/dev/null || date +%s) fi @@ -349,8 +391,11 @@ if run_step "11"; then begin_step "11" "Cleaning up repository" $CYDIR/scripts/repo-clean.sh exit_if_last_command_failed + STEP_END_TIME[11]=$(date +%s.%N 2>/dev/null || date +%s) fi +print_timing_table + echo "Setup complete!" } 2>&1 | tee build-setup.log