Revision: 1 Last modified: 2026-12-04T19:00:00Z
This is a library you source, not a command you run. Sourcing it defines functions; it has no
useful standalone main, and invoking it directly exits 1 with a usage message.
fc_timer.sh is the monotonic per-section / per-gate timer for fastcycle instrumentation. source it
once near the top of any bash script — a pre-build suite, a commit wrapper, an exporter, a test runner —
and wrap each timeable unit of work in fc_timer_start <id> … fc_timer_end.
Every completed pair appends exactly one row to a caller-supplied TSV. Never a fixed or guessed row count: as many rows as there were completed units, and no more.
Why a shared library rather than per-script timing code: the elapsed figures feed the cycle-time report and the SC-002 gate-speed claims, so they must be comparable across every instrumented script. Two scripts timing themselves slightly differently would produce a series that cannot be aggregated.
bash(uses arrays,BASH_SOURCE,EPOCHREALTIME-class nanosecond clocks).FC_TIMER_TSV— required unless timing is disabled. The caller sets it to the TSV to append to.- No other environment variable is required.
# source once, near the top
. "$(dirname "$0")/../constitution/scripts/fastcycle/timing/fc_timer.sh"
# tell it where rows go
export FC_TIMER_TSV="qa-results/fastcycle/${FC_TIMER_RUN_ID}/prebuild_sections.tsv"
fc_timer_init
fc_timer_start "section:governance"
run_governance_sections
fc_timer_end "section:governance"
# a single gate that may run long
fc_timer_gate_start "gate:cm_zero_findings_sweep"
bash scripts/gates/cm_zero_findings_sweep.sh
fc_timer_gate_end "gate:cm_zero_findings_sweep"
# always flush what is open
fc_timer_install_exit_flush| Function | Contract |
|---|---|
fc_timer_init |
Initialises the run (run id, fingerprint, TSV path). Call once, early. |
fc_timer_enabled |
Reports whether timing is active (so a caller can skip work cheaply). |
fc_timer_reset |
Clears in-memory state. |
fc_timer_install_exit_flush |
Installs a trap so frames still open at exit are flushed rather than lost. |
| Function | Contract |
|---|---|
fc_timer_start <id> / fc_timer_end <id> |
Open and close a generic timed unit. |
fc_timer_gate_start <id> / fc_timer_gate_end <id> |
The gate-specific pair (a long, check-bearing unit). Use the matching end for the start. |
fc_timer_track <id> -- <cmd...> |
Times a command in one call. |
fc_timer_run <...> |
Convenience wrapper around a tracked run. |
fc_timer_close_all |
Closes every open frame (used by the exit flush). |
| Function | Contract |
|---|---|
fc_timer_run_id |
The current run id. |
fc_timer_candidate_fingerprint |
The candidate fingerprint every row is keyed to. |
fc_timer_stack_depth |
How many frames are currently open. |
fc_timer_rows_written |
How many rows have been appended so far. |
The _fc_timer_* prefixed helpers are internal and not part of the caller contract.
One row per completed pair, DEC-05's shape plus the fastcycle additions:
| Column | Meaning |
|---|---|
run_id |
The run this row belongs to. |
candidate_fingerprint |
T-A01's requirement that every row be keyed to the candidate fingerprint. |
section (the id) |
The <id> you passed to start/end. |
start_ns, end_ns |
Monotonic nanosecond timestamps. |
duration_ms |
Convenience elapsed column. |
verdict |
PASS / FAIL / WARN for that unit. |
checks, fails, warns |
Count deltas attributable to that unit. |
extra |
Trailing free-form column, so an integration (for example a per-remote push row) can attach fields this generic mechanism does not know about without changing the column count of any other row. |
The trailing extra column is why the schema can be extended without breaking existing consumers.
As a sourced library it defines functions and returns normally; it does not exit.
Invoked directly with no valid usage it prints a usage message and exits 1 — it has no useful
standalone behaviour, so a direct invocation is a caller error.
FC_TIMER_TSVnot set. Timing cannot record; set it or leave timing disabled. Do not let the row land in a guessed path.- A script that exits with frames still open.
fc_timer_install_exit_flushcloses and flushes them; without it, an interrupted unit leaves no row (loss, not a wrong row). - Failed creation of the TSV directory. Handled at row-write time, not assumed at
init. - An unusual signal environment. A directive worth noting: an earlier iteration had an exported
_FC_TIMER_SIGNAL_RC=143in a parent that made a cleanexit 0record a failure. The flush path is written to end cooperatively (rather than forcingexit 130), so a clean exit stays clean. fc_timer_gate_endafterfc_timer_start. Mismatching the pair is a caller error; use the same family for start and end.- Nested frames. A stack is maintained, so nesting is supported and
fc_timer_stack_depthreports it.
- On source, sets defaults and records the clock source.
fc_timer_initresolves the run id, candidate fingerprint and TSV path, ensuring the TSV directory exists at first write.fc_timer_startpushes a frame with a monotonic start timestamp.fc_timer_endpops the matching frame, reads the monotonic end timestamp, and appends exactly one row (run id, fingerprint, id, start/end ns, duration, verdict, checks/fails/warns deltas, extra).fc_timer_install_exit_flushinstalls a trap callingfc_timer_close_allso open frames are written rather than dropped.
Sourced by fastcycle instrumented scripts and test runners; the pre_build_verification.sh suite is
the canonical large consumer (its 183 sections produced the 1133.78 s figure quoted in
collect_baseline.py's reduced-scope note).
Self-tests: scripts/fastcycle/timing/fc_timer_selftest.sh (standalone self-test) and
scripts/fastcycle/timing/fc_timer_selftest_mutations.sh (paired §1.1 mutation runner).
Related: scripts/fastcycle/lib/host_guard.sh is used by callers that fan out timed gates.
See also docs/scripts/cycle_report.py.md (consumes the cycle-time evidence these rows feed) and
docs/scripts/collect_baseline.py.md.
2026-12-04 — bash -n scripts/fastcycle/timing/fc_timer.sh → exit 0. bash scripts/fastcycle/timing/fc_timer.sh invoked directly (not sourced) prints a usage message and exits
1.