@@ -133,12 +133,44 @@ run_step() {
133133# In order to run code on error, we must handle errors manually
134134set +e;
135135
136+ # Initialize timing arrays
137+ declare -a STEP_START_TIME
138+ declare -a STEP_END_TIME
139+ declare -a STEP_DESCRIPTION
140+ STEPS=11
141+
136142function begin_step
137143{
138144 thisStepNum=$1 ;
139145 thisStepDesc=$2 ;
146+ STEP_DESCRIPTION[$thisStepNum ]=$thisStepDesc
147+ STEP_START_TIME[$thisStepNum ]=$( date +%s.%N 2> /dev/null || date +%s)
140148 echo " ========== BEGINNING STEP $thisStepNum : $thisStepDesc =========="
141149}
150+ function print_timing_table
151+ {
152+ echo " "
153+ echo " Per-step timing"
154+ printf " %-8s %-15s %-18s %-20s %s\n" " Step #" " Wall Time (s)" " % of Total Time" " Cumulative Time (s)" " Description"
155+ echo " --------------------------------------------------------------------------------------------------------"
156+
157+ local -a wt
158+ local total=0 cumulative=0
159+ for (( i= 1 ; i<= STEPS; i++ )) ; do
160+ [[ -z " ${STEP_START_TIME[$i]} " || -z " ${STEP_END_TIME[$i]} " ]] && continue
161+ wt[$i ]=$( awk " BEGIN {printf \" %.0f\" , ${STEP_END_TIME[$i]} - ${STEP_START_TIME[$i]} }" )
162+ total=$( awk " BEGIN {printf \" %.0f\" , $total + ${wt[$i]} }" )
163+ done
164+
165+ for (( i= 1 ; i<= STEPS; i++ )) ; do
166+ [[ -z " ${wt[$i]} " ]] && continue
167+ cumulative=$( awk " BEGIN {printf \" %.0f\" , $cumulative + ${wt[$i]} }" )
168+ local pct=$( awk -v w=" ${wt[$i]} " -v t=" $total " " BEGIN {if (t > 0) printf \" %.0f\" , (w/t)*100; else printf \" %.0f\" , 0}" )
169+ printf " %-8s %-15.0f %-18.0f %-20.0f %s\n" " $i " " ${wt[$i]} " " $pct " " $cumulative " " ${STEP_DESCRIPTION[$i]} "
170+ done
171+ printf " %-8s %-15.0f\n" " Total" " $total "
172+ echo " "
173+ }
142174function exit_if_last_command_failed
143175{
144176 local exitcode=$? ;
@@ -223,6 +255,7 @@ END_CONDA_ACTIVATE
223255$CONDA_ACTIVATE_PREAMBLE
224256conda activate $CONDA_ENV_NAME
225257source $CYDIR /scripts/fix-open-files.sh"
258+ STEP_END_TIME[1]=$( date +%s.%N 2> /dev/null || date +%s)
226259fi
227260
228261if [ -z ${CONDA_DEFAULT_ENV+x} ]; then
@@ -234,6 +267,7 @@ if run_step "2"; then
234267 begin_step " 2" " Initializing Chipyard submodules"
235268 $CYDIR /scripts/init-submodules-no-riscv-tools.sh --full
236269 exit_if_last_command_failed
270+ STEP_END_TIME[2]=$( date +%s.%N 2> /dev/null || date +%s)
237271fi
238272
239273# build extra toolchain collateral (i.e. spike, pk, riscv-tests, libgloss)
@@ -250,13 +284,15 @@ if run_step "3"; then
250284 fi
251285 $CYDIR /scripts/build-toolchain-extra.sh $TOOLCHAIN_TYPE -p $PREFIX
252286 exit_if_last_command_failed
287+ STEP_END_TIME[3]=$( date +%s.%N 2> /dev/null || date +%s)
253288fi
254289
255290# run ctags for code navigation
256291if run_step " 4" ; then
257292 begin_step " 4" " Running ctags for code navigation"
258293 $CYDIR /scripts/gen-tags.sh
259294 exit_if_last_command_failed
295+ STEP_END_TIME[4]=$( date +%s.%N 2> /dev/null || date +%s)
260296fi
261297
262298# precompile chipyard scala sources
@@ -267,6 +303,7 @@ if run_step "5"; then
267303 make launch-sbt SBT_COMMAND=" ;project tapeout; compile" &&
268304 popd
269305 exit_if_last_command_failed
306+ STEP_END_TIME[5]=$( date +%s.%N 2> /dev/null || date +%s)
270307fi
271308
272309# setup firesim
@@ -275,6 +312,7 @@ if run_step "6"; then
275312 $CYDIR /scripts/firesim-setup.sh &&
276313 $CYDIR /sims/firesim/gen-tags.sh
277314 exit_if_last_command_failed
315+ STEP_END_TIME[6]=$( date +%s.%N 2> /dev/null || date +%s)
278316
279317 # precompile firesim scala sources
280318 if run_step " 7" ; then
@@ -290,6 +328,7 @@ if run_step "6"; then
290328 )
291329 exit_if_last_command_failed
292330 popd
331+ STEP_END_TIME[7]=$( date +%s.%N 2> /dev/null || date +%s)
293332 fi
294333fi
295334
@@ -307,10 +346,12 @@ if run_step "8"; then
307346 ./marshal $VERBOSE_FLAG build br-base.json &&
308347 ./marshal $VERBOSE_FLAG build bare-base.json
309348 exit_if_last_command_failed
349+ STEP_END_TIME[9]=$( date +%s.%N 2> /dev/null || date +%s)
310350 fi
311351 popd
312352 # Ensure FireMarshal CLI is on PATH in env.sh (idempotent)
313353 replace_content env.sh build-setup-marshal " # line auto-generated by build-setup.sh\n__DIR=\" $CYDIR \" \nPATH=\\ $__DIR /software/firemarshal:\\ $PATH "
354+ STEP_END_TIME[8]=$( date +%s.%N 2> /dev/null || date +%s)
314355fi
315356
316357if run_step " 10" ; then
@@ -341,6 +382,7 @@ if run_step "10"; then
341382 -g $GITHUB_TOKEN
342383 fi
343384 exit_if_last_command_failed
385+ STEP_END_TIME[10]=$( date +%s.%N 2> /dev/null || date +%s)
344386fi
345387
346388
@@ -349,8 +391,11 @@ if run_step "11"; then
349391 begin_step " 11" " Cleaning up repository"
350392 $CYDIR /scripts/repo-clean.sh
351393 exit_if_last_command_failed
394+ STEP_END_TIME[11]=$( date +%s.%N 2> /dev/null || date +%s)
352395fi
353396
397+ print_timing_table
398+
354399echo " Setup complete!"
355400
356401} 2>&1 | tee build-setup.log
0 commit comments