diff --git a/crates/reims-vgpu/src/backend/vulkan/engine/counters.rs b/crates/reims-vgpu/src/backend/vulkan/engine/counters.rs index 3bc17e623..04ac1595c 100644 --- a/crates/reims-vgpu/src/backend/vulkan/engine/counters.rs +++ b/crates/reims-vgpu/src/backend/vulkan/engine/counters.rs @@ -2,14 +2,14 @@ //! //! # The vocabulary is declared once //! -//! [`engine_counters!`] takes the counter names and generates the five things +//! [`engine_counters!`] takes the counter names and generates the six things //! that used to spell them out separately: the atomic [`EngineCounters`], the -//! plain-`u64` [`CounterSnapshot`], and the three whole-vocabulary walks -//! [`EngineCounters::snapshot`], [`EngineCounters::reset`] and -//! [`CounterSnapshot::delta_since`]. +//! plain-`u64` [`CounterSnapshot`], and the four whole-vocabulary walks +//! [`EngineCounters::snapshot`], [`EngineCounters::reset`], +//! [`CounterSnapshot::delta_since`] and [`CounterSnapshot::delta_fields`]. //! -//! Writing seventy names five times is how a counter silently stops working, and -//! neither failure mode is a compile error or a log line: +//! Writing a hundred names six times is how a counter silently stops working, +//! and none of the failure modes is a compile error or a log line: //! //! * missing from `reset` — the counter reports a lifetime total into a reader //! that asked for a window, so a per-second rate reads as monotonically rising; @@ -17,22 +17,39 @@ //! is indistinguishable from "this path never ran". That is the //! "an event count is not a state" trap in `AGENTS.md` with the count itself //! broken. +//! * missing from the emitted line — the counter is correct and nobody can read +//! it, which is the same thing from the outside. This is the one that actually +//! happened: `engine_delta` named its fields by hand and had fallen **35 +//! counters** behind the vocabulary, so a run built to read four of them +//! measured nothing and reported a clean zero. `delta_fields` is generated for +//! that reason, and the emitter now walks it instead of naming anything. //! //! All five lists were checked against each other before this collapse and all //! five agreed, so the macro changes no behaviour. What it changes is that they //! can no longer disagree. //! -//! The three groups are a real distinction, not a formatting one. `windowed` is +//! The four groups are a real distinction, not a formatting one. `windowed` is //! zeroed by `reset()`; `cumulative` deliberately survives it, because a //! device-loss count is a fact about the boot and not about the measurement //! window, and only `reset_all()` clears it; `pool_sourced` has no atomic at all //! and is merged in from `ResourcePools` by `engine::counter_snapshot`. //! +//! `pool_levels` is merged in the same way as `pool_sourced` but is not a rate: +//! every field in it is an absolute high-water or an instantaneous level, so +//! subtracting two readings of one yields nonsense that reads as a plausible +//! zero. That is why the group exists rather than a comment saying so — +//! `delta_since` carries these through unchanged, `delta_fields` omits them, and +//! `census::emit_registry_pressure` prints them absolute beside the prose that +//! says how each is read. Putting a level in the wrong group is now the only way +//! to get it onto the per-interval line, and that is a visible edit rather than +//! an omission. +//! //! # A field with no named reader is not dead //! -//! [`CounterSnapshot`] is consumed only by the integration tests in `tests/`. -//! No product code reads it and no log line emits it, so a sweep for "fields -//! nobody references" reports most of this struct. Twenty-seven of the +//! [`CounterSnapshot`] is named field-by-field only by the integration tests in +//! `tests/`; the census reaches it through the generated `delta_fields`, which +//! mentions no name. So a sweep for "fields nobody references" still reports +//! most of this struct. Twenty-seven of the //! seventy-one came back that way. Do not act on that sweep: the struct derives //! `Debug` and every assertion in those tests prints the *whole* snapshot on //! failure (`"...: {d:?}"`), so the unasserted fields are the diagnostic context @@ -90,6 +107,7 @@ macro_rules! engine_counters { windowed { $($(#[$wm:meta])* $win:ident,)* } cumulative { $($(#[$cm:meta])* $cum:ident,)* } pool_sourced { $($(#[$pm:meta])* $pool:ident,)* } + pool_levels { $($(#[$lm:meta])* $lvl:ident,)* } ) => { /// Process-wide product-path counters (resettable for tests). #[derive(Debug, Default)] @@ -105,6 +123,7 @@ macro_rules! engine_counters { $($(#[$wm])* pub $win: u64,)* $($(#[$cm])* pub $cum: u64,)* $($(#[$pm])* pub $pool: u64,)* + $($(#[$lm])* pub $lvl: u64,)* } impl EngineCounters { @@ -116,6 +135,7 @@ macro_rules! engine_counters { $($win: self.$win.load(Ordering::Relaxed),)* $($cum: self.$cum.load(Ordering::Relaxed),)* $($pool: 0,)* + $($lvl: 0,)* } } @@ -135,13 +155,47 @@ macro_rules! engine_counters { /// This reading minus an earlier one, field by field. Saturating /// because a `reset` between the two readings makes `earlier` /// larger, and a window of "no work" must read 0 rather than wrap. + /// + /// `pool_levels` fields are **carried through unchanged**, not + /// subtracted: a high-water mark minus an earlier high-water mark is + /// not a high-water mark, and it reads as 0 for the rest of a boot + /// once the true maximum is behind the window. So the difference of + /// two readings still holds the level, and a caller that prints one + /// gets the answer rather than a plausible zero. pub fn delta_since(&self, earlier: &CounterSnapshot) -> CounterSnapshot { CounterSnapshot { $($win: self.$win.saturating_sub(earlier.$win),)* $($cum: self.$cum.saturating_sub(earlier.$cum),)* $($pool: self.$pool.saturating_sub(earlier.$pool),)* + $($lvl: self.$lvl,)* } } + + /// Every field that is a **rate** — one `(name, value)` pair per + /// counter that means "this many since the last reading", in + /// declaration order. + /// + /// This is what `runtime::drain::census` prints as `engine_delta`, + /// and it exists so that line cannot drift from the vocabulary. It + /// used to be a hand-written format string naming its fields twice, + /// and it had silently fallen 35 counters behind: a name added to + /// this macro got a field, a reset and a delta, and then printed + /// nowhere. That reads exactly like a path that never runs, which is + /// the same trap this module's docs describe for a missing + /// `delta_since` arm, one step further along — and it cost a + /// twelve-boot A/B run that could not answer its own question, + /// because the four counters it was built to read were among them. + /// + /// `pool_levels` is excluded on purpose. Those are absolute + /// high-waters, they are not per-interval, and `registry_pressure` + /// prints them beside the prose that says how to read each one. + pub fn delta_fields(&self) -> Vec<(&'static str, u64)> { + vec![ + $((stringify!($win), self.$win),)* + $((stringify!($cum), self.$cum),)* + $((stringify!($pool), self.$pool),)* + ] + } } }; } @@ -604,6 +658,9 @@ engine_counters! { target_free_allocs, target_recycle_admits, target_recycle_cap_drops, + } + + pool_levels { /// High-water mark of the non-pinned resident population, in slots. /// /// The demand, with no ceiling to read it against: this population is diff --git a/crates/reims-vgpu/src/runtime/drain/census.rs b/crates/reims-vgpu/src/runtime/drain/census.rs index 0ccbe21c4..b3ca3aae4 100644 --- a/crates/reims-vgpu/src/runtime/drain/census.rs +++ b/crates/reims-vgpu/src/runtime/drain/census.rs @@ -2665,89 +2665,14 @@ fn emit_engine_delta() { }; let d = now.delta_since(&prev.unwrap_or_default()); *prev = Some(now); - crate::observe::off(format!( - "engine_delta creates={} allocs={} batch_opens={} batch_joins={} batch_flushes={} \ - batch_flush_draws={} batch_readback_joins={} readbacks={} readback_bytes={} render_post_wait_skips={} \ - target_reads={} target_read_bytes={} gpu_stamps={} pipeline_misses={} \ - shader_misses={} shader_hits={} shader_digest_hits={} shader_hash_words={} \ - pass_misses={} layout_misses={} sampler_misses={} \ - sampled_cache_hits={} sampled_identity_hits={} sampled_cache_hit_bytes={} \ - sampled_cache_misses={} sampled_reuploads={} \ - sampled_reupload_bytes={} sampled_gathers={} sampled_gather_bytes={} \ - sampled_gather_skips={} sampled_gather_skip_bytes={} \ - sampled_guest_imports={} sampled_guest_import_bytes={} \ - sampled_gather_unvouched={} sampled_gather_unretained={} \ - draw_cover_full={} draw_cover_loaded_full_scissor={} \ - draw_cover_loaded_partial_scissor={} \ - buffer_guest_imports={} buffer_guest_import_bytes={} \ - buffer_guest_gathers={} buffer_guest_gather_bytes={} \ - buffer_guest_gather_regions={} \ - buffer_gather_dispatches={} buffer_gather_declined={} \ - buffer_bind_reuses={} \ - buffer_snapshot_binds={} \ - guest_write_linear={} guest_write_rects={} guest_write_regions={} \ - guest_write_dispatches={} guest_write_scatter_declined={} \ - seed_uploads={} seed_upload_bytes={} \ - ring_retire_blocks={} target_evicts={} desc_pool_grow={} gen_mismatch={}", - d.creates, - d.allocs, - d.batch_opens, - d.batch_joins, - d.batch_flushes, - d.batch_flush_draws, - d.batch_readback_joins, - d.readbacks, - d.readback_bytes, - d.render_post_wait_skips, - d.target_reads, - d.target_read_bytes, - d.gpu_stamps, - d.pipeline_misses, - d.shader_misses, - d.shader_hits, - d.shader_digest_hits, - d.shader_hash_words, - d.pass_misses, - d.layout_misses, - d.sampler_misses, - d.sampled_cache_hits, - d.sampled_identity_hits, - d.sampled_cache_hit_bytes, - d.sampled_cache_misses, - d.sampled_reuploads, - d.sampled_reupload_bytes, - d.sampled_gathers, - d.sampled_gather_bytes, - d.sampled_gather_skips, - d.sampled_gather_skip_bytes, - d.sampled_guest_imports, - d.sampled_guest_import_bytes, - d.sampled_gather_unvouched, - d.sampled_gather_unretained, - d.draw_cover_full, - d.draw_cover_loaded_full_scissor, - d.draw_cover_loaded_partial_scissor, - d.buffer_guest_imports, - d.buffer_guest_import_bytes, - d.buffer_guest_gathers, - d.buffer_guest_gather_bytes, - d.buffer_guest_gather_regions, - d.buffer_gather_dispatches, - d.buffer_gather_declined, - d.buffer_bind_reuses, - d.buffer_snapshot_binds, - d.guest_write_linear, - d.guest_write_rects, - d.guest_write_regions, - d.guest_write_dispatches, - d.guest_write_scatter_declined, - d.seed_uploads, - d.seed_upload_bytes, - d.ring_retire_blocks, - d.target_evicts, - d.desc_pool_grow, - d.gen_mismatch, - )); + // Generated from the counter vocabulary rather than named here, so this line + // cannot fall behind it again; see `CounterSnapshot::delta_fields`. + let mut line = String::from("engine_delta"); + for (name, value) in d.delta_fields() { + use std::fmt::Write as _; + let _ = write!(line, " {name}={value}"); + } + crate::observe::off(line); emit_registry_pressure(&now); emit_draw_phase(); }