#!/usr/bin/env node /** * Boot / VFS / shell benchmark harness sketch (append-only trend file). * Run manually: `node scripts/benchmark-boot-sketch.mjs` * Trend path: `BARE_OS_BENCHMARK_TREND_NDJSON` or `${TMPDIR:-/tmp}/bare-os-benchmark-trend.ndjson` */ import { appendFileSync, readFileSync } from 'node:fs' import process from 'node:process' function readBootPerfRows() { const p = String(process.env.BARE_OS_BOOT_PERF_PATH || '').trim() || '/run/bare-os/boot-perf.json' try { const raw = String(readFileSync(p, 'utf8') || '').trim() if (!raw) return { path: p, phases: [] } const j = JSON.parse(raw) const phases = Array.isArray(j?.phaseSamples) ? j.phaseSamples .map((x) => ({ phase: String(x?.phase || ''), ms: Number(x?.ms || 0) })) .filter((x) => x.phase && Number.isFinite(x.ms) && x.ms >= 0) : [] return { path: p, phases } } catch { return { path: p, phases: [] } } } const perf = readBootPerfRows() const totalMs = perf.phases.reduce((a, b) => a + b.ms, 0) const path = String(process.env.BARE_OS_BENCHMARK_TREND_NDJSON || '').trim() || `${process.env.TMPDIR || '/tmp'}/bare-os-benchmark-trend.ndjson` const line = JSON.stringify({ schema: 2, name: 'boot-sketch', wallMs: totalMs, bootPerfPath: perf.path, phaseCount: perf.phases.length, phaseTimings: perf.phases, atMs: Date.now() }) + '\n' try { appendFileSync(path, line) } catch { /* ignore */ } console.log( 'benchmark-boot-sketch: ok (trend → ' + path + ', phases=' + perf.phases.length + ')' ) process.exit(0)