diff --git a/agent/src/collectors/service.rs b/agent/src/collectors/service.rs index df04d62..3db4982 100644 --- a/agent/src/collectors/service.rs +++ b/agent/src/collectors/service.rs @@ -389,8 +389,8 @@ impl ServiceCollector { Ok((parse(parts[0])?, parse(parts[1])?, parse(parts[2])?)) } - async fn get_cpu_cstate_info(&self) -> Option { - // Read C-state information to show actual sleep state distribution + async fn get_cpu_cstate_info(&self) -> Option> { + // Read C-state information to show all sleep state distributions let mut cstate_times: Vec<(String, u64)> = Vec::new(); let mut total_time = 0u64; @@ -414,13 +414,19 @@ impl ServiceCollector { } if total_time > 0 && !cstate_times.is_empty() { - // Find the dominant C-state (highest time) + // Sort by time spent (highest first) cstate_times.sort_by(|a, b| b.1.cmp(&a.1)); - let dominant_state = &cstate_times[0]; - let dominant_percent = (dominant_state.1 as f32 / total_time as f32) * 100.0; - // Return dominant state info - return Some(format!("{}({:.1}%)", dominant_state.0, dominant_percent)); + // Format all C-states with percentages + let mut result = Vec::new(); + for (name, time) in cstate_times { + let percent = (time as f32 / total_time as f32) * 100.0; + if percent >= 0.1 { // Only show states with at least 0.1% time + result.push(format!("{}: {:.1}%", name, percent)); + } + } + + return Some(result); } } diff --git a/dashboard/src/data/metrics.rs b/dashboard/src/data/metrics.rs index 52ef80b..fec7746 100644 --- a/dashboard/src/data/metrics.rs +++ b/dashboard/src/data/metrics.rs @@ -61,7 +61,7 @@ pub struct ServiceSummary { #[serde(default)] pub cpu_load_15: f32, #[serde(default)] - pub cpu_cstate: Option, + pub cpu_cstate: Option>, #[serde(default)] pub cpu_temp_c: Option, #[serde(default)] diff --git a/dashboard/src/ui/system.rs b/dashboard/src/ui/system.rs index b23a2a4..842d64a 100644 --- a/dashboard/src/ui/system.rs +++ b/dashboard/src/ui/system.rs @@ -83,14 +83,19 @@ fn render_metrics( // CPU dataset let cpu_status = status_level_from_color(cpu_icon_color); - let mut cpu_dataset = WidgetDataSet::new(vec!["CPU load".to_string(), "CPU temp".to_string(), "CPU state".to_string()], Some(WidgetStatus::new(cpu_status))); + let mut cpu_dataset = WidgetDataSet::new(vec!["CPU load".to_string(), "CPU temp".to_string()], Some(WidgetStatus::new(cpu_status))); + + // Get C-state descriptions + let cstate_descriptions = summary.cpu_cstate.as_ref() + .map(|states| states.clone()) + .unwrap_or_else(|| vec!["No C-state data".to_string()]); + cpu_dataset.add_row( Some(WidgetStatus::new(cpu_status)), - vec![], + cstate_descriptions, vec![ format!("{:.2} • {:.2} • {:.2}", summary.cpu_load_1, summary.cpu_load_5, summary.cpu_load_15), format_optional_metric(summary.cpu_temp_c, "°C"), - summary.cpu_cstate.clone().unwrap_or_else(|| "—".to_string()), ], );