interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / tools / estimation / est5_collect.sh

102 lines · 4473 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0
3# Copyright 2026 Drake Stapleton (AIEN / aien-dev)
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# ESTIMATION v5 (docs/estimation/protocols/est-v5.md) data collection under the declared
18# est_load schedule. The v4 collector (est4_collect.sh) with an ENFORCED WINDOW: it runs only
19# while the caller holds the machine-wide quiet flag for this gate (the flag is enforced by
20# the quiet-guard hook), it never creates or removes the flag, it refuses to start when a
21# foreign build/test/gate process is already running, and it records a process monitor
22# (process-monitor.log, one sample every 2 s) whose verdict est5_window_check.sh gives.
23# tools/estimation/est5_collect.sh <fit|heldout|smoke> <seconds> <seed> <raw-root> <est_load-binary>
24# Writes <raw-root>/<UTC>-est5-<role>-silicon/ with machine-state.ndjson (1 Hz),
25# machine-state-marks.txt, schedule.txt, machine-state-start.txt, process-monitor.log,
26# WINDOW verdict and SHA256SUMS. Prints no thermal statistic.
27set -u
28role=${1:?fit, heldout or smoke}
29secs=${2:?seconds}
30seed=${3:?seed}
31root=${4:?raw root}
32load=${5:?est_load binary}
33here=$(cd "$(dirname "$0")" && pwd)
34quiet=$HOME/workspace/.spark-quiet
35if ! grep -q '^gate est-v5$' "$quiet" 2> /dev/null; then
36 echo "est5_collect: $quiet missing or not held for gate est-v5; the window must be held first" >&2
37 exit 3
38fi
39if pgrep -x est_load > /dev/null 2>&1; then
40 echo "est5_collect: an est_load process is running; refusing" >&2
41 exit 3
42fi
43pre=$(sh "$here/est5_window_scan.sh" 0)
44if [ -n "$pre" ]; then
45 echo "est5_collect: foreign build/test/gate process already running; refusing:" >&2
46 echo "$pre" | head -5 >&2
47 exit 3
48fi
49lpid=
50mpid=
51cleanup() {
52 [ -n "$lpid" ] && kill "$lpid" 2> /dev/null
53 [ -n "$mpid" ] && kill "$mpid" 2> /dev/null
54}
55trap cleanup EXIT
56trap 'exit 4' HUP INT TERM
57mkdir -p "$root" || exit 5
58d=$root/$(date -u +%Y%m%dT%H%M%SZ)-est5-$role-silicon
59# Plain mkdir: refuses an existing folder, so a prior collection is never truncated.
60mkdir "$d" || { echo "est5_collect: $d already exists; refusing" >&2; exit 5; }
61date -u +%FT%TZ > "$d/machine-state-start.txt"
62: > "$d/machine-state-marks.txt"
63: > "$d/process-monitor.log"
64"$load" "$seed" "$secs" "$d/machine-state-marks.txt" > "$d/schedule.txt" &
65lpid=$!
66# process monitor: a sample line every 2 s, FOREIGN lines for builds/tests/gates, and
67# informational HIGHCPU lines (any process above 25 % CPU other than the load generator).
68(
69 while :; do
70 ts=$(date -u +%FT%TZ)
71 echo "$ts S $(ps -e --no-headers | wc -l)"
72 sh "$here/est5_window_scan.sh" "$lpid" | sed "s/^/$ts /"
73 ps -eo pid=,pcpu=,comm= | awk -v own="$lpid" -v ts="$ts" '$1 != own && $2 > 25 { print ts, "HIGHCPU", $1, $2, $3 }'
74 sleep 2
75 done
76) >> "$d/process-monitor.log" 2> /dev/null &
77mpid=$!
78end=$(( $(date +%s) + secs ))
79while [ "$(date +%s)" -lt "$end" ]; do
80 t=$(date +%s.%N)
81 th=$(cat /sys/class/thermal/thermal_zone*/temp | tr '\n' ' ')
82 la=$(cut -d' ' -f1-3 /proc/loadavg)
83 cpu=$(head -1 /proc/stat | cut -d' ' -f3-10)
84 printf '{"t":%s,"thermal_mc":"%s","loadavg":"%s","cpu":"%s"}\n' "$t" "$th" "$la" "$cpu" >> "$d/machine-state.ndjson"
85 if ! kill -0 "$lpid" 2> /dev/null && [ "$(( end - $(date +%s) ))" -gt 5 ]; then
86 echo "est5_collect: est_load exited early; collection is INVALID" >&2
87 lpid=; echo INVALID_EARLY_LOAD_EXIT > "$d/INVALID"; exit 6
88 fi
89 sleep 1
90done
91wait "$lpid"; rc=$?; lpid=
92kill "$mpid" 2> /dev/null; mpid=
93if [ "$rc" -ne 0 ]; then
94 echo "est5_collect: est_load exit status $rc; collection is INVALID" >&2
95 echo "INVALID_LOAD_EXIT $rc" > "$d/INVALID"; exit 6
96fi
97wrc=0
98sh "$here/est5_window_check.sh" "$d" "$secs" > "$d/WINDOW" || wrc=$?
99(cd "$d" && sha256sum machine-state.ndjson machine-state-marks.txt machine-state-start.txt schedule.txt process-monitor.log WINDOW > SHA256SUMS)
100echo "$d"
101cat "$d/WINDOW" >&2
102[ "$wrc" -eq 0 ] || exit 7