Build resource monitoring#
The cross container builds are long and QEMU-heavy, and the failure that hurts
most is silent resource exhaustion — an OOM-killed cc1plus at hour six, or a
full disk mid-export. linux/scripts/01-core/resource-monitor.sh records what
the system was doing throughout a build so you can answer, after the fact:
When, and during which build activity, did RAM / disk / CPU headroom run out?
Active-log discovery keeps file paths intact while ordering by modification time. It prefers
a stage log with a .run marker, then falls back to the newest log. Spaces in either the
log directory or filename are supported. The exit handler preserves the original status
even when writing the final resource summary fails.
What it captures#
A CSV time-series (resources-<run-id>.csv), one row per tick (default every
15 s), plus a computed resources-<run-id>.summary.txt on exit.
Column |
Meaning |
|---|---|
|
sample time (absolute + seconds since start) |
|
load average and CPU-busy % (from |
|
|
|
swap in use — any value >0 means real memory pressure |
|
free space / % used on the build filesystem |
|
live |
|
coarse build stage + the exact build log line active then |
The context column is the key one: at every peak-pressure moment the
summary tells you which file/target was compiling, so you can trace an OOM or
disk spike straight to the offending stage (e.g. torch’s aten TUs).
The runtime lane’s step markers#
The runtime lane writes no per-stage log with a .run marker, so before CON142
every one of its samples read stage=?. Now start_resource_monitor
(lib-orchestrator.sh) exports RESOURCE_MONITOR_STEP_DIR
(<log dir>/.steps-<run id>) and passes it to the monitor as --step-dir.
_runtime_timed (01-core/runtime-build-fns.sh) creates <arch>.<step> there
while a step runs: base, package, smoke, wrapper, wrapper-build, and
any other step it times. The background pusher does the same with <arch>.push.
The marker is removed when the step ends, whether it passed or failed.
After the arch loop build-runtime-manifest.sh keeps naming its work. Each gate
holds <arch>.<script> (arm64/verify-shipped-wrapper), and runtime_step_phase
holds index.<step> for what no arch owns: binfmt, input-preflight, reuse-plan,
reuse-pull, push-wait, manifest, acceptance, freshness and drop-pushed.
It runs its command unguarded, so a body keeps the caller’s errexit; a lane that
errexit stops leaves its last marker behind, as a killed lane does.
While any marker exists, the stage column lists every one of them as
arch/step, joined by + because a comma would add CSV columns: for example
amd64/push+arm64/package. The summary therefore names the arch and step of
each peak, even while arches overlap. When no marker exists, the column falls
back to the active log and then to --label, as before.
A child lane keeps the directory its parent exported, so the chain’s single
monitor reads what build-runtime-manifest.sh marks. A lane killed past its
traps can leave a marker behind; the directory is per run id, and a fresh start
of that run id clears it.
Overhead#
Negligible. Each tick is a handful of /proc reads plus ~3 short-lived forks
(df, pgrep, tail|grep). At 15 s that is far below the noise floor of a
32-core build and never competes with the compilers.
Automatic use#
build-cross-chain.sh and build-cross-stage.sh start it automatically for
the whole run (start_resource_monitor in lib-orchestrator.sh, gated by
RESOURCE_MONITOR, default on) and it self-terminates when the orchestrator
exits (via --watch-pid), writing the summary. Output lands in --log-dir.
The chain defaults to logs/build-logs/. If stage logging is disabled or its
directory is unwritable, resource samples fall back to the ignored logs/ root.
# default: monitoring on, 15s interval, CSV+summary in the run's log dir
bash linux/scripts/build-cross-chain.sh --from-stage media --log-dir ~/build-logs
# disable it
RESOURCE_MONITOR=0 bash linux/scripts/build-cross-chain.sh ...
Manual use (any other build)#
# start in the background, following whichever log is newest, self-ending with
# the build process:
setsid bash linux/scripts/01-core/resource-monitor.sh \
--out-dir ~/build-logs --run-id my-run --interval 15 \
--stage-log-dir ~/build-logs --disk-path / --watch-pid "$BUILD_PID" &
# ...or re-analyze a finished run's CSV at any time:
bash linux/scripts/01-core/resource-monitor.sh summarize ~/build-logs/resources-my-run.csv
Thresholds for the summary’s “near-OOM” / “low-disk” sample counts are tunable
with --near-oom-mb (default 4096) and --low-disk-gb (default 20; the chain orchestrators pass RM_LOW_DISK_GB, else the disk-watch floor CROSS_DISK_GUARD_GB, 40).
Reading the results#
swap_used_mbclimbing ormem_avail_mbnear zero → you are at the OOM edge. Cross-reference thecontextat that row and lower the relevant*_MB_PER_JOBper build-parallelism-memory-tuning.md, or add RAM.disk_avail_gbdropping toward the low-disk threshold → reclaim disk before the next run in the order of Linux Host Setup § B7:prune-safe.shfirst, the regenerable cache-export dir~/.cache/kata-buildcacheafter it.compilerswell below core count whilemem_availis low → the stage is RAM-bound (expected for torch); more RAM, not more-j, is the lever.The CSV plots directly in any spreadsheet /
gnuplotif you want a timeline.
The CSV is rewritten on each start, so give each build a distinct
--run-id(the orchestrator passesCROSS_RUN_ID) to preserve history.
Mining a build log for the actual failure#
The monitoring above tells you what a build consumed. When one fails, the complementary problem is finding the real error in tens of thousands of lines, where the last line printed is usually a downstream symptom rather than the cause.
Capture the log in the first place — build-cross-chain.sh and
build-cross-stage.sh take --log-dir; every other build, including a
hand-run one, should be teed:
mkdir -p logs/build-logs
nerdctl build -t <tag> -f linux/Dockerfile.<stage> . 2>&1 | tee logs/build-logs/build.log
Then pull out the lines that actually mark failures:
grep -nE '(^| )FAILED: |ninja: build stopped|error:|fatal error:|undefined reference|collect2: error|ld\.lld: error|permission denied|no space left on device|exit code [1-9]' logs/build-logs/build.log
Reading the hits, in order of what they mean:
Match |
What it usually means |
|---|---|
|
The ninja edge that broke — start here, it names the target |
|
The compiler diagnostic; the first one is the cause, later ones are fallout |
|
Link stage — a missing library or an ABI mismatch, not a source bug |
|
Host disk, not the build. See Linux Host Setup § B3 |
|
Usually a bind-mount uid mismatch rather than a real permission problem |
|
Terminator line only — the cause is above it |
-n matters: it gives you the line number to seek to, which is the point of the
exercise on a log too large to read.