mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-28 22:06:31 +00:00
feat(make/parallel): per-target wall-clock breakdown + live status
Replace the single `make -j ... --output-sync=target` invocation with a shell-level fan-out that times each target individually and reports a status table at the end. Output for each target is buffered to a log file and dumped under a ✅/❌ header as soon as that target finishes (preserving the per-target grouping `--output-sync` gave us). Non-zero exit codes propagate; the run aborts at the first failure once all already-launched children drain. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
38f3e2fc5a
commit
762b95bfaf
1 file changed
+76
-8
@@ -1,9 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
# Generic parallel-make wrapper. Takes one or more make targets as
|
||||
# args, derives `-j` from min(arg-count, INFINITO_WORKER_CPU) so each
|
||||
# target gets at most one CPU and never more workers than necessary,
|
||||
# runs them with --output-sync=target to keep logs readable, and
|
||||
# prints wall-clock elapsed time at the end.
|
||||
# args, runs each as its own background `make` invocation (capped at
|
||||
# INFINITO_WORKER_CPU concurrent workers), and at the end prints a
|
||||
# per-target wall-clock breakdown plus the overall elapsed time.
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
@@ -38,10 +37,79 @@ echo " 📋 targets: $*"
|
||||
echo " ⚙️ jobs: ${jobs} (cpu cap: ${INFINITO_WORKER_CPU})"
|
||||
echo
|
||||
|
||||
SECONDS=0
|
||||
make -j "${jobs}" --output-sync=target "$@"
|
||||
elapsed=$SECONDS
|
||||
tmpdir="$(mktemp -d)"
|
||||
trap 'rm -rf "${tmpdir}"' EXIT
|
||||
|
||||
declare -A pid_to_target=()
|
||||
declare -A target_start=()
|
||||
declare -A target_dur=()
|
||||
declare -A target_rc=()
|
||||
declare -A target_log=()
|
||||
|
||||
start_ts="$(date +%s)"
|
||||
|
||||
# Concurrency throttle: launch up to ${jobs} children at a time. When
|
||||
# the active count hits the cap, drain via wait -n before spawning more.
|
||||
active=0
|
||||
to_launch=("$@")
|
||||
launch_idx=0
|
||||
|
||||
drain_one() {
|
||||
local pid=""
|
||||
local rc=0
|
||||
# `|| rc=$?` keeps set -e happy when a child exited non-zero.
|
||||
wait -n -p pid || rc=$?
|
||||
local tgt="${pid_to_target[${pid}]}"
|
||||
target_rc["${tgt}"]="${rc}"
|
||||
target_dur["${tgt}"]=$(($(date +%s) - target_start["${tgt}"]))
|
||||
if ((rc == 0)); then
|
||||
echo "✅ ${tgt} ($(format_duration "${target_dur[${tgt}]}"))"
|
||||
else
|
||||
echo "❌ ${tgt} ($(format_duration "${target_dur[${tgt}]}")) exit=${rc}"
|
||||
fi
|
||||
cat "${target_log[${tgt}]}"
|
||||
active=$((active - 1))
|
||||
}
|
||||
|
||||
for tgt in "${to_launch[@]}"; do
|
||||
while ((active >= jobs)); do
|
||||
drain_one
|
||||
done
|
||||
log="${tmpdir}/${launch_idx}.log"
|
||||
target_log["${tgt}"]="${log}"
|
||||
target_start["${tgt}"]="$(date +%s)"
|
||||
(make -- "${tgt}") >"${log}" 2>&1 &
|
||||
pid_to_target[$!]="${tgt}"
|
||||
active=$((active + 1))
|
||||
launch_idx=$((launch_idx + 1))
|
||||
done
|
||||
|
||||
while ((active > 0)); do
|
||||
drain_one
|
||||
done
|
||||
|
||||
total=$(($(date +%s) - start_ts))
|
||||
|
||||
echo
|
||||
echo "✨ done in $(format_duration "${elapsed}") 🎉"
|
||||
echo "📊 per-target wall-clock:"
|
||||
overall_rc=0
|
||||
for tgt in "$@"; do
|
||||
rc="${target_rc[${tgt}]}"
|
||||
if ((rc == 0)); then
|
||||
status="✅"
|
||||
else
|
||||
status="❌"
|
||||
overall_rc="${rc}"
|
||||
fi
|
||||
printf ' %s %-30s %s\n' "${status}" "${tgt}" "$(format_duration "${target_dur[${tgt}]}")"
|
||||
done
|
||||
|
||||
echo
|
||||
if ((overall_rc == 0)); then
|
||||
echo "✨ total $(format_duration "${total}") 🎉"
|
||||
else
|
||||
echo "💥 total $(format_duration "${total}") (exit=${overall_rc})"
|
||||
fi
|
||||
echo
|
||||
|
||||
exit "${overall_rc}"
|
||||
Reference in new issue
Block a user