#!/usr/bin/env bash # build_multiuser_doe_report.sh — full pipeline: disk -> CSV -> R/SVG -> PDF # # Chains: extract_doe_region.py (spool DOE-PERSIST-TRIAL records off # disk/artemis.img) -> analyse_multiuser_doe.R (tables + SVG charts + # auto-generated summary fragment) -> svg_to_pdf.py (SVG -> PDF for # \includegraphics) -> pdflatex (twice, for cross-references) -> # multiuser_doe_report.pdf. # # Safe to re-run at any point, including while a multi-day campaign is # still executing on a separate QEMU instance: every step is read-only # with respect to disk/artemis.img, and analyse_multiuser_doe.R degrades # to a "no data yet" placeholder rather than failing when the DoE region # has 0 trials so far. # # Usage: # scripts/build_multiuser_doe_report.sh [--loop] [--csv PATH] # # --loop Attach disk/artemis.img via losetup instead of reading # the file directly (needs sudo). See extract_doe_region.py. # --csv PATH Skip disk extraction entirely and analyse an existing # CSV instead (e.g. to smoke-test this pipeline against # an old per-tick run CSV, or a CSV saved from a previous # extraction). set -euo pipefail REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$REPO_ROOT" ANALYSIS_DIR="experiments/bare_metal/analysis" RUNS_DIR="experiments/bare_metal/runs" REPORT_DIR="$ANALYSIS_DIR/report" CSV_OUT="$RUNS_DIR/multiuser-doe-trials.csv" USE_LOOP=0 CSV_OVERRIDE="" while [ $# -gt 0 ]; do case "$1" in --loop) USE_LOOP=1; shift ;; --csv) CSV_OVERRIDE="$2"; shift 2 ;; *) echo "Unknown argument: $1" >&2; exit 1 ;; esac done echo "=== [1/4] Extracting trial records ===" if [ -n "$CSV_OVERRIDE" ]; then echo " Using existing CSV: $CSV_OVERRIDE (skipping disk extraction)" CSV_OUT="$CSV_OVERRIDE" elif [ -f disk/artemis.img ]; then mkdir -p "$RUNS_DIR" if [ "$USE_LOOP" -eq 1 ]; then python3 scripts/extract_doe_region.py --img disk/artemis.img --loop -o "$CSV_OUT" else python3 scripts/extract_doe_region.py --img disk/artemis.img -o "$CSV_OUT" fi else echo " disk/artemis.img not found -- writing an empty CSV so the report" >&2 echo " still builds with a 'no data yet' placeholder." >&2 mkdir -p "$RUNS_DIR" echo "isa,run_id,cfg,rep,nw,mode,fail_count,fleet_k_q48,fleet_conserved,switch_count_cumulative" > "$CSV_OUT" fi echo "" echo "=== [2/4] Running R analysis (tables + charts + summary fragment) ===" Rscript "$ANALYSIS_DIR/analyse_multiuser_doe.R" "$CSV_OUT" echo "" echo "=== [3/4] Converting SVG charts to PDF ===" python3 "$ANALYSIS_DIR/svg_to_pdf.py" echo "" echo "=== [4/4] Building PDF report ===" mkdir -p "$REPORT_DIR/sections" if [ ! -f "$REPORT_DIR/sections/multiuser_summary_autogen.tex" ]; then echo "No trial data has been persisted to the DoE region yet." \ > "$REPORT_DIR/sections/multiuser_summary_autogen.tex" fi cd "$REPORT_DIR" pdflatex -interaction=nonstopmode -halt-on-error multiuser_doe_report.tex >/tmp/multiuser_doe_report_latex1.log 2>&1 || { echo "pdflatex (pass 1) failed -- see /tmp/multiuser_doe_report_latex1.log" >&2 tail -40 /tmp/multiuser_doe_report_latex1.log >&2 exit 1 } pdflatex -interaction=nonstopmode -halt-on-error multiuser_doe_report.tex >/tmp/multiuser_doe_report_latex2.log 2>&1 || { echo "pdflatex (pass 2) failed -- see /tmp/multiuser_doe_report_latex2.log" >&2 tail -40 /tmp/multiuser_doe_report_latex2.log >&2 exit 1 } cd "$REPO_ROOT" echo "" echo "=== Done ===" echo " PDF: $REPORT_DIR/multiuser_doe_report.pdf"