Skip to content

Commit 798b3a2

Browse files
tamewarecursoragent
andcommitted
Show live per-run rows during runs, hidden before the summary
Display the script's per-run timing rows as progress while the benchmark runs. On a tty without --details they are shown on the alternate screen and discarded when we switch back to the main screen just before the summary, so they never clutter the final output regardless of how much scrolls. With --details they stay on the main screen; off a tty they are suppressed (summary only). dtest's own output is captured, not shown. Replaces the old transient per-run rows, whose ANSI line-clearing could not erase content that had scrolled off-screen. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 3a3106e commit 798b3a2

1 file changed

Lines changed: 33 additions & 31 deletions

File tree

benchmark.sh

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ BRANCH_TMP=""
5555
BUILD_LOG=""
5656

5757
cleanup() {
58+
# Leave the alternate screen first so any restore/error messages and the shell
59+
# prompt land on the normal screen.
60+
if [[ "${ALT_SCREEN_ACTIVE:-0}" == "1" ]]; then
61+
printf '\033[?1049l' >/dev/tty 2>/dev/null || true
62+
ALT_SCREEN_ACTIVE=0
63+
fi
5864
if [[ -n "$ORIG_BRANCH" ]]; then
5965
local cur
6066
cur="$(git -C "$ROOT" symbolic-ref --quiet --short HEAD 2>/dev/null \
@@ -468,6 +474,7 @@ run_dtest() {
468474
# Wrap with `time -p` so we can capture wall-clock elapsed for this run. Its
469475
# "real/user/sys" lines go to the merged output but do not collide with the
470476
# dtest lines parse_dtest_output looks for.
477+
#
471478
local out
472479
if ! out="$(/usr/bin/time -p "${cmd[@]}" 2>&1)"; then
473480
echo "error: dtest failed: ${cmd[*]}" >&2
@@ -487,40 +494,18 @@ run_dtest() {
487494
echo "$parsed $wall"
488495
}
489496

490-
progress_lines=0
491-
TRANSIENT_PROGRESS=0
492497
show_run_lines=1
493498

494499
print_run_table_header() {
495500
printf "%-6s %-13s %7s %8s %8s %10s %6s %s\n" \
496501
"solver" "file" "ver" "user_ms" "sys_ms" "avg_user" "ratio" "run"
497502
printf "%-6s %-13s %7s %8s %8s %10s %6s %s\n" \
498503
"------" "-------------" "-------" "--------" "--------" "----------" "------" "---"
499-
if [[ "$TRANSIENT_PROGRESS" == "1" ]]; then
500-
progress_lines=$((progress_lines + 2))
501-
fi
502504
}
503505

504506
print_run_row() {
505507
printf "%-6s %-13s %7s %8s %8s %10s %6s %s\n" \
506508
"$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8"
507-
if [[ "$TRANSIENT_PROGRESS" == "1" ]]; then
508-
progress_lines=$((progress_lines + 1))
509-
fi
510-
}
511-
512-
clear_transient_progress() {
513-
if [[ "$TRANSIENT_PROGRESS" != "1" || $progress_lines -le 0 ]]; then
514-
return
515-
fi
516-
# Cursor rests on a blank line below the last row; erase it, then each table line.
517-
# Do not move up after clearing the topmost line (would hit the header above).
518-
printf '\033[2K'
519-
local i
520-
for (( i = 0; i < progress_lines; i++ )); do
521-
printf '\033[1A\033[2K'
522-
done
523-
progress_lines=0
524509
}
525510

526511
echo "DDS dtest benchmark"
@@ -572,16 +557,28 @@ if ((${#DTEST_EXTRA[@]} > 0)); then
572557
fi
573558
echo
574559

560+
# The per-run rows are the script's live progress. With --details they are kept
561+
# in the final output. Without --details, on a tty, they are shown on the
562+
# alternate screen so the user sees progress, then discarded when we switch back
563+
# to the main screen just before the summary; off a tty they are suppressed
564+
# (summary only), since there is nothing to hide them.
575565
show_run_lines=0
576-
TRANSIENT_PROGRESS=0
577-
# Per-run rows are detail: show them only with --details. Without it they are
578-
# suppressed entirely (no transient progress table, which could otherwise scroll
579-
# off-screen and leave residue). The summary is always shown regardless.
580-
if [[ "$DETAILS" == "1" ]]; then
581-
show_run_lines=1
566+
ALT_SCREEN=0
567+
if [[ "$DRY_RUN" != "1" ]]; then
568+
if [[ "$DETAILS" == "1" ]]; then
569+
show_run_lines=1
570+
elif [[ -t 1 ]]; then
571+
show_run_lines=1
572+
ALT_SCREEN=1
573+
fi
582574
fi
583575

584-
if [[ "$DRY_RUN" != "1" && ( "$show_run_lines" == "1" || "$TRANSIENT_PROGRESS" == "1" ) ]]; then
576+
if [[ "$ALT_SCREEN" == "1" ]]; then
577+
printf '\033[?1049h\033[H\033[2J' >/dev/tty # enter alt screen, home, clear
578+
ALT_SCREEN_ACTIVE=1
579+
fi
580+
581+
if [[ "$DRY_RUN" != "1" && "$show_run_lines" == "1" ]]; then
585582
print_run_table_header
586583
fi
587584

@@ -611,7 +608,7 @@ for solver in "${SOLVERS[@]}"; do
611608

612609
read -r user sys avg ratio wall < <(run_dtest "$bin" "$solver" "$hands")
613610

614-
if [[ "$show_run_lines" == "1" || "$TRANSIENT_PROGRESS" == "1" ]]; then
611+
if [[ "$show_run_lines" == "1" ]]; then
615612
print_run_row "$solver" "$file" "$ver" "$user" "$sys" "$avg" "$ratio" "$run_label"
616613
fi
617614

@@ -623,7 +620,12 @@ for solver in "${SOLVERS[@]}"; do
623620
done
624621
done
625622

626-
clear_transient_progress
623+
# Return to the normal screen, discarding the live dtest output, before the
624+
# summary so the final output is just the header and the summary.
625+
if [[ "$ALT_SCREEN" == "1" ]]; then
626+
printf '\033[?1049l' >/dev/tty
627+
ALT_SCREEN_ACTIVE=0
628+
fi
627629

628630
if [[ -n "${COMPARE:-}" && "$DRY_RUN" != "1" ]]; then
629631
echo # compare summary (two binaries)

0 commit comments

Comments
 (0)