Add a feature-gated profiler for the rx-loop maintenance tick

The tick arm runs twenty-six housekeeping steps in sequence on the one
runtime thread, and is polled last, so anything slow in it holds up
inbound packets, TUN traffic and control commands behind it. Field
evidence says that happens for over a second at a time, but the
attribution behind that is two months old and predates the
connect-on-send gate, the control read isolation, and the peer lifecycle
rework. This measures it rather than continuing to reason about it.

Per step it records exact count, max and total into fixed static
counters; a dedicated writer thread drains them every ten seconds to a
TSV under /var/log/fips, one file per capture, capped at 32 MB. Nothing
accumulates: the counters are swapped to zero each interval and the
thread holds no history. Arming is `fipsctl profile tick on`, served in
the control accept task so the toggle cannot queue behind the very
behaviour it measures, and it does not survive a restart.

The whole thing is behind a Cargo feature that is off by default,
because the risk worth eliminating is the twenty-six edited call sites
in the hot loop. With the feature off the macro expands to the bare
expression, which makes the default build's neutrality something you
read off the generated code rather than something a benchmark fails to
disprove.

The measurement that matters is how late each tick is against the
deadline it was scheduled for, since the arm is polled last and that
lateness is the delay. Two earlier designs derived it from the interval
between entries and both under-reported: the schedule is fixed, so a
steady delay leaves every gap exactly one period and any gap-derived
figure reads zero under precisely the sustained overload this is meant
to find. The interval hands back its own deadline, so the delay is now a
subtraction with no model behind it, and a test drives three late ticks
at a constant gap to keep it that way.

CI gains a default-features clippy and a feature-on build and test on
both runners, closing the gap left by clippy already running with all
features.
This commit is contained in:
Johnathan Corgan
2026-07-28 00:56:54 +00:00
parent 52dc21726a
commit 7493153a89
17 changed files with 1540 additions and 42 deletions
+35
View File
@@ -521,6 +521,30 @@ run_build() {
return 1
fi
# An optional feature means two source trees, and --all-features lints only
# one of them. The default build is what ships, so lint it explicitly:
# without this stage, code that compiles only with `profiling` enabled would
# pass CI while breaking every release build.
info "cargo clippy --all-targets -- -D warnings (default features)"
if cargo clippy --all-targets -- -D warnings 2>&1; then
record "clippy-default-features" 0
else
record "clippy-default-features" 1
return 1
fi
# Tick-body profiler: the feature-on tree must build too. Added alongside
# the default-feature stages rather than replacing them. Mirrored in
# .github/workflows/ci.yml — check-ci-parity.sh compares integration suites
# only and will not catch a stage added to one runner and not the other.
info "cargo build --workspace --features profiling"
if cargo build --workspace --features profiling 2>&1; then
record "build-profiling" 0
else
record "build-profiling" 1
return 1
fi
# Guard: the effectively-immutable state lives solely in NodeContext. The
# Node struct must not re-declare a bundled field (config/identity/
# startup_epoch/started_at/is_leaf_only/node_profile/max_*) — a shadow field
@@ -560,6 +584,17 @@ run_tests() {
record "unit-tests" 1
fi
fi
# The `profiling` feature adds a module, a recorder and a writer thread that
# the default-feature run above never compiles. Run the library tests once
# more with it on so its own tests execute at all. Mirrored in
# .github/workflows/ci.yml.
info "cargo test --lib --features profiling"
if cargo test --lib --features profiling 2>&1; then
record "unit-tests-profiling" 0
else
record "unit-tests-profiling" 1
fi
}
# ── Stage 3: Integration Tests ─────────────────────────────────────────────