diff --git a/crates/rocm-dash-tui/src/ui/tabs/home.rs b/crates/rocm-dash-tui/src/ui/tabs/home.rs index e49cdeb872..0b17aaf72e 100644 --- a/crates/rocm-dash-tui/src/ui/tabs/home.rs +++ b/crates/rocm-dash-tui/src/ui/tabs/home.rs @@ -104,6 +104,25 @@ fn snap_util(s: &rocm_dash_core::metrics::Snapshot) -> f64 { .fold(0.0, f64::max) } +/// Sums the finite values `pick` yields across instances, or `None` when no +/// instance contributed one. The `Option` is the point: "nothing reported a +/// value" has to stay distinct from "every reporter measured zero", which a +/// bare sum cannot express. A single NaN/Infinity sample is dropped rather +/// than allowed to poison the total, as `gen_tps_cell` does per instance. +/// `Iterator::sum` is deliberately avoided — its `f64` identity is `-0.0`, so +/// an empty iterator sums to `-0.0` and renders as `"-0"`. +fn instance_aggregate(state: &AppState, pick: F) -> Option +where + F: Fn(&rocm_dash_core::metrics::Instance) -> Option, +{ + state + .instances + .values() + .filter_map(pick) + .filter(|v| v.is_finite()) + .fold(None, |acc, v| Some(acc.unwrap_or(0.0) + v)) +} + /// A labeled one-row instrument: `LABEL ▁▂▃▅▆▇ value`. Port of the mock's /// `mini_spark`; `accent` picks the flat throughput tint, else value-gradient. fn mini_spark( @@ -293,7 +312,7 @@ fn draw_activity(f: &mut Frame, area: Rect, state: &AppState, theme: &Theme) { fn draw_hero_band(f: &mut Frame, area: Rect, state: &AppState, theme: &Theme) { let title = node_throughput_title(state); let hero = card(f, area, &title, BoxRole::Secondary, theme); - if hero.width >= 8 && hero.height >= 6 { + if hero.width >= 8 && hero.height >= 1 { let hcols = Layout::default() .direction(Direction::Horizontal) .constraints([Constraint::Percentage(50), Constraint::Percentage(50)]) @@ -304,11 +323,22 @@ fn draw_hero_band(f: &mut Frame, area: Rect, state: &AppState, theme: &Theme) { } } +/// One-row slots for a hero column, top to bottom. Slots past the column's +/// height come back zero-height, so a short terminal drops the bottom rows +/// (the legends first) rather than the whole hero. +fn hero_rows(area: Rect) -> [Rect; 6] { + std::array::from_fn(|i| { + let i = u16::try_from(i).unwrap_or(u16::MAX); + if i < area.height { + Rect::new(area.x, area.y + i, area.width, 1) + } else { + Rect::new(area.x, area.y, area.width, 0) + } + }) +} + fn draw_hero_left(f: &mut Frame, area: Rect, state: &AppState, theme: &Theme) { - let lh = Layout::default() - .direction(Direction::Vertical) - .constraints([Constraint::Length(1); 6]) - .split(area); + let lh = hero_rows(area); f.render_widget( Paragraph::new(Line::from(Span::styled( "GPU UTILIZATION", @@ -339,31 +369,27 @@ fn draw_hero_left(f: &mut Frame, area: Rect, state: &AppState, theme: &Theme) { // Tokens/watt: summed across running instances when available. // Mark held if any contributing instance has a held gen_tps observation // (tok/W derives from gen_tps; aggregate inherits held status). - // A single NaN/Infinity instance would otherwise poison the whole sum - // (and, for `any_tpw_held`, count as held without ever being displayed) — - // filtered out the same way `tokens_per_watt` is guarded per-instance - // elsewhere in this tab. - let tpw: f64 = state - .instances - .values() - .filter_map(|i| i.tokens_per_watt) - .filter(|v| v.is_finite()) - .sum(); + let tpw = instance_aggregate(state, |i| i.tokens_per_watt); let any_tpw_held = state.instances.values().any(|i| { i.tokens_per_watt.is_some_and(f64::is_finite) && i.gen_tps_observation .as_ref() .is_some_and(|m| m.freshness == rocm_dash_core::metrics::ObservationFreshness::Held) }); - let tpw_label = if tpw > 0.0 { - let marker = if any_tpw_held { - crate::ui::format::HELD_MARKER - } else { - "" - }; - format!("⎓ {tpw:.1} tokens / watt{marker}") - } else { - "⎓ tokens / watt —".to_string() + // The marker and the legend that explains it share fate: the legend row + // is the first thing a short hero drops, and a bare "*" with nothing on + // screen to define it is worse than an unannotated prior-window value. + let legend_fits = lh[5].height > 0; + let tpw_label = match tpw { + None => "⎓ tokens / watt —".to_string(), + Some(v) => { + let marker = if any_tpw_held && legend_fits { + crate::ui::format::HELD_MARKER + } else { + "" + }; + format!("⎓ {v:.1} tokens / watt{marker}") + } }; f.render_widget( Paragraph::new(Line::from(Span::styled( @@ -375,10 +401,15 @@ fn draw_hero_left(f: &mut Frame, area: Rect, state: &AppState, theme: &Theme) { lh[4], ); // Show the shared HELD_LEGEND only when the tok/W aggregate is actually - // held AND rendered with a marker — `tpw > 0.0` mirrors the gate on - // `tpw_label` above so a zero-throughput aggregate (which prints - // "tokens / watt —" with no marker) never shows an unexplained legend. - if tpw > 0.0 && any_tpw_held { + // held, so an unmeasured aggregate (which prints "tokens / watt —" with no + // marker) never shows an unexplained legend. + // + // `any_tpw_held` already implies `tpw.is_some()`: it requires some instance + // with a finite `tokens_per_watt`, and `instance_aggregate` folds exactly + // those into `Some` over the same `state.instances` set. The extra + // `tpw.is_some() &&` term was unreachable-false, so it is gone rather than + // left to read as a real second condition. + if any_tpw_held { f.render_widget( Paragraph::new(Line::from(Span::styled( format::HELD_LEGEND, @@ -390,10 +421,7 @@ fn draw_hero_left(f: &mut Frame, area: Rect, state: &AppState, theme: &Theme) { } fn draw_hero_right(f: &mut Frame, area: Rect, state: &AppState, theme: &Theme) { - let rh = Layout::default() - .direction(Direction::Vertical) - .constraints([Constraint::Length(1); 6]) - .split(area); + let rh = hero_rows(area); // In demo/replay this is not a live feed — say so rather than "LIVE". let (feed_label, feed_color) = if state.simulated { ("SIMULATED · last 60s", theme.warn) @@ -478,26 +506,22 @@ fn draw_hero_right(f: &mut Frame, area: Rect, state: &AppState, theme: &Theme) { false, theme, ); - // A single NaN/Infinity instance would otherwise poison the whole sum - // (rendering "NaN"/"inf" in the hero) and could mark the aggregate held - // without ever contributing a displayed value — guarded the same way - // `gen_tps_cell` guards a single instance's value. - let tps: f64 = state - .instances - .values() - .filter_map(|i| i.gen_tps) - .filter(|v| v.is_finite()) - .sum(); + let tps = instance_aggregate(state, |i| i.gen_tps); let any_tps_held = state.instances.values().any(|i| { i.gen_tps.is_some_and(f64::is_finite) && i.gen_tps_observation .as_ref() .is_some_and(|m| m.freshness == rocm_dash_core::metrics::ObservationFreshness::Held) }); - let tps_str = if any_tps_held { - format!("{:.0}{}", tps, crate::ui::format::HELD_MARKER) - } else { - format!("{tps:.0}") + // The held marker is suppressed with the legend row that explains it, as + // in `draw_hero_left`. + let legend_fits = rh[5].height > 0; + let tps_str = match tps { + None => "—".to_string(), + Some(v) if any_tps_held && legend_fits => { + format!("{:.0}{}", v, crate::ui::format::HELD_MARKER) + } + Some(v) => format!("{v:.0}"), }; mini_spark(f, rh[4], "T/S ", &tps_str, &[], true, theme); // Show the shared HELD_LEGEND only when the tok/s aggregate is actually @@ -1151,6 +1175,42 @@ mod tests { } } + #[test] + fn hero_drops_only_its_lowest_rows_in_a_short_terminal() { + // A ~22-row terminal leaves the Home tab fewer rows than the six the + // hero's columns ask for. The readings must still draw, and they must + // go bottom-first: at every height the visible rows form a prefix of + // this list, so one is missing only when all below it are too. That is + // the promise docs/manual-testing.md 4c makes, pinned without naming + // the height each row happens to appear at (POWER at 13, T/S at 15 — + // thresholds that would otherwise drift silently). + let s = state_with_gpu(); + let top_down = ["VRAM", "TEMP", "POWER", "T/S"]; + for h in 8u16..=24 { + let out = render(&s, 160, h); + assert!( + out.contains("GPU UTILIZATION"), + "the hero must never render as an empty card, at height {h}:\n{out}" + ); + let present: Vec = top_down.iter().map(|l| out.contains(l)).collect(); + let kept = present.iter().take_while(|p| **p).count(); + assert!( + present[kept..].iter().all(|p| !*p), + "the hero dropped {} but kept a row below it, at height {h}:\n{out}", + top_down[kept] + ); + } + // Without this the prefix check above would pass on a hero that + // renders none of these rows at any height. + let roomy = render(&s, 160, 24); + for label in top_down { + assert!( + roomy.contains(label), + "{label} missing from a hero with room for it:\n{roomy}" + ); + } + } + fn instance_with_obs(gen_tps: f64, obs: Option) -> Instance { Instance { container_id: "m".into(), @@ -1185,6 +1245,35 @@ mod tests { s } + /// The hero's T/S value, i.e. the text after the "T/S" label up to the + /// panel border on that row. + fn hero_tps_value(out: &str) -> &str { + out.split("T/S") + .nth(1) + .and_then(|s| s.split('│').next()) + .unwrap_or_else(|| panic!("T/S row missing: {out:?}")) + .trim() + } + + #[test] + fn hero_tps_shows_dash_not_negative_zero_when_nothing_reports_throughput() { + // A GPU is reported but no instance is serving: the Windows in-process + // collectors never send instances, and a Linux host with nothing + // running is in the same state. + let out = render(&state_with_gpu(), 160, 30); + assert_eq!(hero_tps_value(&out), "—", "got:\n{out}"); + } + + #[test] + fn hero_tps_shows_zero_when_an_instance_reports_zero_throughput() { + let out = render( + &state_with_instance(instance_with_obs(0.0, Some(fresh_obs()))), + 160, + 30, + ); + assert_eq!(hero_tps_value(&out), "0", "got:\n{out}"); + } + #[test] fn home_held_legend_visible_when_tpw_and_tps_held() { let out = render( @@ -1209,6 +1298,37 @@ mod tests { ); } + #[test] + fn hero_never_shows_a_held_marker_without_its_legend() { + // Squeezing the hero drops the legend row before the value rows, so + // every height has to be checked, not just the roomy one. + let s = state_with_instance(instance_with_obs(300.0, Some(held_obs()))); + let marked_tps = format!("{:.0}{}", 300.0, format::HELD_MARKER); + let marked_tpw = format!("{:.1} tokens / watt{}", 1.0, format::HELD_MARKER); + let mut saw_unmarked_value = false; + for h in 8u16..=30 { + let out = render(&s, 160, h); + if out.contains(&marked_tps) || out.contains(&marked_tpw) { + assert!( + out.contains(format::HELD_LEGEND), + "held marker with no legend to explain it at height {h}:\n{out}" + ); + } + // The reading itself must survive the legend being dropped. + if out.contains("T/S") && !out.contains(format::HELD_LEGEND) { + assert!( + out.contains("300"), + "the T/S reading must stay once the marker is dropped, at height {h}:\n{out}" + ); + saw_unmarked_value = true; + } + } + assert!( + saw_unmarked_value, + "no height rendered T/S without the legend — the squeeze this guards never happened" + ); + } + #[test] fn home_held_legend_absent_when_all_fresh() { let out = render( @@ -1235,29 +1355,54 @@ mod tests { ); } - #[test] - fn home_tpw_legend_absent_when_aggregate_is_zero_even_if_held() { - // tokens_per_watt sums to 0.0 (the "tokens / watt —" branch, no marker - // rendered) while gen_tps is absent (so the tok/s side never fires - // either). Held metadata alone must not add an unexplained legend. - let inst = Instance { + /// An instance whose only reading is `tokens_per_watt`, held. + fn tpw_only_instance(tokens_per_watt: Option) -> Instance { + Instance { container_id: "m".into(), container_name: "m".into(), status: InstanceStatus::Running, model_name: "m".into(), gpu_ids: vec!["0".into()], gen_tps: None, - tokens_per_watt: Some(0.0), + tokens_per_watt, gen_tps_observation: Some(held_obs()), ..Default::default() - }; - let out = render(&state_with_instance(inst), 160, 30); + } + } + + #[test] + fn home_tpw_shows_a_measured_zero_rather_than_a_dash() { + // An instance that reports 0.0 tok/W measured it; only "no instance + // reported one at all" is unmeasured. Mirrors the tok/s side, which + // renders a reported 0 as "0" and reserves "—" for nothing reporting. + let out = render(&state_with_instance(tpw_only_instance(Some(0.0))), 160, 30); assert!( - !out.contains(format::HELD_LEGEND), - "HELD_LEGEND must not appear when the tok/W aggregate is zero; got:\n{out}" + out.contains(&format!("0.0 tokens / watt{}", format::HELD_MARKER)), + "a measured zero tok/W must render as 0.0, not —; got:\n{out}" + ); + assert!( + out.contains(format::HELD_LEGEND), + "the marked zero aggregate must still be explained; got:\n{out}" ); } + #[test] + fn home_tpw_legend_absent_when_no_instance_reports_a_finite_value() { + // The invariant the aggregate change must not break: held metadata + // alone, with nothing finite to mark, must not conjure a legend. + for tpw in [None, Some(f64::NAN), Some(f64::INFINITY)] { + let out = render(&state_with_instance(tpw_only_instance(tpw)), 160, 30); + assert!( + out.contains("tokens / watt —"), + "unmeasured tok/W must read —; got for {tpw:?}:\n{out}" + ); + assert!( + !out.contains(format::HELD_LEGEND), + "HELD_LEGEND must not appear with nothing marked; got for {tpw:?}:\n{out}" + ); + } + } + #[test] fn home_tps_aggregate_ignores_nonfinite_instance() { // A NaN `gen_tps` on one instance must not poison the summed hero diff --git a/docs/manual-testing.md b/docs/manual-testing.md index c8528d7118..80811350b6 100644 --- a/docs/manual-testing.md +++ b/docs/manual-testing.md @@ -829,6 +829,8 @@ Expected result: present. With more than one adapter (for example a hybrid laptop) VRAM total stays unmeasured and shows `—` in the Home hero and in the GPU wall sidebar, never `0.0%`. +- The hero's `T/S` row reads `—`, never `0` or `-0`: Windows has no + serving-instance view, so no throughput is ever measured there. - Utilization rises under GPU load (run a Lemonade or ComfyUI job) and falls back when it ends. - Hiding `amdadlx64.dll` (for example on a non-AMD GPU host) leaves @@ -837,6 +839,36 @@ Expected result: - No other output of this section needs a daemon: `rocm dash` must not report a failed daemon connection. +### 4c. Dashboard Hero In A Short Terminal + +**Any platform.** The hero's row dropping is terminal layout, not a +Windows-specific path, so this reproduces on Linux and WSL too. + +Open a terminal about 22 to 24 rows tall — the VS Code panel is one — and +run: + +``` +rocm dash +``` + +Expected result: + +- The hero still shows utilization, VRAM, temperature and power. It never + renders as an empty box with only its "Node throughput · …" title. +- As the terminal gets shorter the hero loses rows from the bottom only: the + held legend first, then `T/S`. Enlarging it brings them back. +- With a model served whose figures are a scrape window old, the `*` held + marker and the `* = held (prior scrape window)` legend explaining it appear + and disappear **together** as the terminal is resized. A `*` on a reading + with no legend anywhere on screen is a bug; so is the legend with nothing + marked. + + Check this one by **starting tall and shrinking**, not at the 22-to-24 rows + above. The legend is the first row the hero drops, and the marker is gated on + the legend fitting — so at 22 to 24 rows neither is on screen and there is + nothing to compare. Start around 30 rows, confirm both are present, then + shrink past the drop and confirm both go at once. + ## 5. Reuse Is Exempt From The No-GPU Refusal **Linux or WSL only.** Unlike the rest of this file, the commands below are diff --git a/tests/e2e-cucumber/features/dash.feature b/tests/e2e-cucumber/features/dash.feature index fe3ed468ee..455edb4d5c 100644 --- a/tests/e2e-cucumber/features/dash.feature +++ b/tests/e2e-cucumber/features/dash.feature @@ -623,13 +623,16 @@ Feature: Interactive dashboard # placeholder shown before the first snapshot arrives at all, is not covered # here (the unit test `gpu_telemetry_pending_while_connected_but_no_snapshot_yet` # pins it): it closes in well under a second and there's no hook to freeze the daemon - # mid-handshake, so asserting on it would be asserting on a race. + # mid-handshake, so asserting on it would be asserting on a race. Nothing is + # served either, so the T/S row must read "—" too: an empty sum of rates is + # -0.0 in Rust, which used to render as "-0". @id:dash-reports-no-gpu-telemetry @requires-os:linux Scenario: dash-37 - The hero shows placeholders, not fake zeros, when no GPU is detected Given a machine with no GPU When the user opens the dashboard Then the dashboard home view is displayed And the hero reports no GPU telemetry available + And the hero reports no generation throughput When the user quits the dashboard Then the dashboard exits successfully diff --git a/tests/e2e-cucumber/tests/e2e/dash_steps.rs b/tests/e2e-cucumber/tests/e2e/dash_steps.rs index 45915271ef..d0bd23430b 100644 --- a/tests/e2e-cucumber/tests/e2e/dash_steps.rs +++ b/tests/e2e-cucumber/tests/e2e/dash_steps.rs @@ -1646,8 +1646,8 @@ async fn home_view_displayed(world: &mut E2eWorld) { #[then("the hero reports no GPU telemetry available")] async fn hero_reports_no_gpu_telemetry(world: &mut E2eWorld) { let tui = session(world); - // The VRAM/TEMP/POWER mini-sparks only draw in the hero's wide layout - // (`draw_hero_band`'s `hero.width >= 8 && hero.height >= 6` gate). + // The VRAM/TEMP/POWER/T/S rows sit low in the hero, and a short pty + // squeezes the hero until `hero_rows` drops its bottom rows; enlarge first. tui.use_wide_size() .unwrap_or_else(|e| panic!("failed to enlarge the dashboard: {e}")); @@ -1700,6 +1700,38 @@ async fn hero_reports_no_gpu_telemetry(world: &mut E2eWorld) { .await; } +#[then("the hero reports no generation throughput")] +async fn hero_reports_no_generation_throughput(world: &mut E2eWorld) { + let tui = session(world); + // Self-contained rather than relying on a preceding step: cucumber matches + // step text globally, so this has to hold wherever it is written. The T/S + // row sits low in the hero and a short pty drops it, so enlarge and wait + // for the redraw before reading the screen. + tui.use_wide_size() + .unwrap_or_else(|e| panic!("failed to enlarge the dashboard: {e}")); + tui.wait_for_screen_where( + "the hero's T/S row", + |screen| screen.contains("T/S"), + default_timeout(), + ) + .await + .unwrap_or_else(|e| panic!("the hero's T/S row did not render: {e}")); + + let screen = tui.screen_text(); + let row = screen + .lines() + .find(|line| line.contains("T/S")) + .unwrap_or_else(|| panic!("no T/S row on screen:\n{screen}")); + let value = row + .split_once("T/S") + .and_then(|(_, rest)| rest.split('│').next()) + .map_or_else(|| panic!("no text after T/S on row:\n{row}"), str::trim); + assert_eq!( + value, "—", + "T/S should show the \"—\" placeholder when nothing is served:\n{row}" + ); +} + #[then("the dashboard reports live GPU telemetry")] async fn gpu_telemetry_displayed(world: &mut E2eWorld) { let tui = session(world);