This commit is contained in:
2025-10-12 18:39:03 +02:00
parent 0656af17f2
commit 75910610e4
3 changed files with 22 additions and 11 deletions

View File

@@ -389,8 +389,8 @@ impl ServiceCollector {
Ok((parse(parts[0])?, parse(parts[1])?, parse(parts[2])?))
}
async fn get_cpu_cstate_info(&self) -> Option<String> {
// Read C-state information to show actual sleep state distribution
async fn get_cpu_cstate_info(&self) -> Option<Vec<String>> {
// 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);
}
}