cu_profiler_report/
model.rs1pub use cu_profiler_core::baseline::BaselineComparison;
8pub use cu_profiler_core::budget::{PolicyResult, PolicyStatus, Severity};
9pub use cu_profiler_core::confidence::{Confidence, ConfidenceLevel};
10pub use cu_profiler_core::diagnostics::Diagnostic;
11pub use cu_profiler_core::model::{
12 InstructionMeasurement, Measurement, Report, ScenarioReport, Status, Summary,
13};
14
15#[must_use]
17pub fn thousands(n: u64) -> String {
18 let s = n.to_string();
19 let mut grouped: Vec<char> = Vec::with_capacity(s.len() + s.len() / 3);
20 for (count, ch) in s.chars().rev().enumerate() {
21 if count != 0 && count % 3 == 0 {
22 grouped.push(',');
23 }
24 grouped.push(ch);
25 }
26 grouped.iter().rev().collect()
27}
28
29#[must_use]
31pub fn scenario_budget(scenario: &ScenarioReport) -> Option<u64> {
32 scenario
33 .policy_results
34 .iter()
35 .find(|p| p.policy_id == "absolute_max_cu")
36 .and_then(|p| p.expected)
37 .map(|f| f as u64)
38}
39
40#[must_use]
42pub fn scenario_delta_pct(scenario: &ScenarioReport) -> Option<f64> {
43 scenario.baseline_comparison.as_ref().map(|c| c.delta_pct)
44}
45
46#[cfg(test)]
47mod tests {
48 use super::*;
49
50 #[test]
51 fn thousands_formatting() {
52 assert_eq!(thousands(0), "0");
53 assert_eq!(thousands(96_812), "96,812");
54 assert_eq!(thousands(1_000_000), "1,000,000");
55 assert_eq!(thousands(999), "999");
56 }
57}