max_by_sum_u64

Function max_by_sum_u64 

Source
pub fn max_by_sum_u64(rows: &[(&str, Vec<SnapshotField<'_>>)]) -> Option<usize>
Expand description

Pick the candidate row whose fields sum to the largest u64 — the “max-activity bss” heuristic generalized to N co-picked variables. For each row, the picker as_u64-projects every field and saturating_adds them; rows containing ANY field that fails to project to u64 are dropped entirely (not partial-summed); among the surviving rows, the one with the largest sum wins.

Pairs with super::view::Snapshot::live_vars_via for ratio / fraction metrics: the row whose counters have accumulated the most TOTAL events is the live scheduler instance, and selecting that row guarantees all N returned fields come from the same source map (no cross-bss-copy corruption).

§When this picks WRONG

Inherits every failure mode of max_by_counter_value (gauges, sentinel-init counters like u64::MAX, immediately-post-swap windows before the new instance has accumulated past the old’s BSS-zero point), plus one sum-specific mode:

Any-non-u64-field row excluded. A single rodata or non-counter variable accidentally included in the name set silently makes every candidate row ineligible (every row would have that non-u64 field). Verify all N names project to u64 counters BEFORE composing the picker.

Sums use saturating_add: a row containing a sentinel u64::MAX saturates to u64::MAX and wins all comparisons. Treat that as a sentinel-mode failure (per max_by_counter_value’s caveat).

Ties resolve to the LAST tied row (matches Iterator::max_by_key semantics — same as max_by_counter_value).