From 829a94fa2f184818a2e54f162cebaf7da25f0ffa Mon Sep 17 00:00:00 2001 From: ates Date: Thu, 26 Nov 2026 18:47:28 +0300 Subject: [PATCH] bx-cli: print clwb VEH traps : 0 when no CLWB records exist Signed-off-by: ates --- launcher/crates/bx-cli/src/main.rs | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/launcher/crates/bx-cli/src/main.rs b/launcher/crates/bx-cli/src/main.rs index 2dec3436..5ce322cf 100644 --- a/launcher/crates/bx-cli/src/main.rs +++ b/launcher/crates/bx-cli/src/main.rs @@ -153,6 +153,16 @@ fn cmd_probe(path: &str) -> ExitCode { ExitCode::SUCCESS } +fn format_clwb_line(clwb_events: usize, clwb_trap_lower_bound: Option) -> String { + if let Some(lower_bound) = clwb_trap_lower_bound { + format!("clwb VEH traps : at least {lower_bound} (sampled)") + } else if clwb_events == 0 { + "clwb VEH traps : 0".to_string() + } else { + format!("clwb VEH samples : {clwb_events}") + } +} + fn cmd_trace(path: &str) -> ExitCode { let text = match fs::read_to_string(path) { Ok(s) => s, @@ -163,11 +173,10 @@ fn cmd_trace(path: &str) -> ExitCode { }; let summary = summarize_jsonl(&text); println!("Trace events : {}", summary.total_lines); - if let Some(lower_bound) = summary.clwb_trap_lower_bound { - println!("clwb VEH traps : at least {lower_bound} (sampled)"); - } else { - println!("clwb VEH samples : {}", summary.clwb_events); - } + println!( + "{}", + format_clwb_line(summary.clwb_events, summary.clwb_trap_lower_bound) + ); println!("ADX illegal ops : {}", summary.adx_errors); if !summary.unhandled_exceptions.is_empty() { println!( @@ -433,4 +442,14 @@ mod tests { "Z:\\tmp\\bx-test.jsonl" ); } + + #[test] + fn formats_clwb_summary_lines() { + assert_eq!(format_clwb_line(0, None), "clwb VEH traps : 0"); + assert_eq!(format_clwb_line(2, None), "clwb VEH samples : 2"); + assert_eq!( + format_clwb_line(3, Some(4)), + "clwb VEH traps : at least 4 (sampled)" + ); + } }