Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions build-metrics.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
set -euo pipefail

METRICS_FILE="build-metrics-$(date +%Y%m%d-%H%M%S).log"
START_TIME=$(date +%s)

log_metric() {
local stage="$1"
local elapsed=$(( $(date +%s) - START_TIME ))
local elapsed_min=$(echo "scale=2; $elapsed / 60" | bc)
echo "[$(date +%H:%M:%S)] [${elapsed}s / ${elapsed_min}m] ${stage}" | tee -a "$METRICS_FILE"
}

run_stage() {
local stage="$1"
shift
log_metric "START: ${stage}"
"$@"
log_metric "END: ${stage}"
}

if [ $# -eq 0 ]; then
echo "Usage: $0 <command> [args...]"
echo "Records elapsed time and logs build stage performance."
echo
echo "Example:"
echo " source build-metrics.sh"
echo " run_stage 'Building ISO' ./mkarchiso.sh"
exit 0
fi

run_stage "$@"
14 changes: 11 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
./refresh.sh -j && ./mkarchiso.sh
# sudo rm /var/cache/pacman/pkg/*
sudo rm -rf ./work
#!/usr/bin/env bash
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "${SCRIPT_DIR}/build-metrics.sh"

run_stage "Clean workspace" ./refresh.sh -j
run_stage "Build ISO" ./mkarchiso.sh
run_stage "Clean build artifacts" sudo rm -rf ./work

log_metric "BUILD COMPLETE"