Skip to content

Commit

Permalink
Restore demo behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
walles committed Jul 23, 2023
1 parent 19d93c7 commit ff0f025
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion libloadviz/src/cpuload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,42 @@ pub fn diff(older: &[LoadCounters], newer: &[LoadCounters]) -> Vec<CpuLoad> {
/// Hard code load in debug builds to simplify testing the visualization
#[cfg(all(debug_assertions, not(test)))]
pub fn diff(_: &[LoadCounters], _: &[LoadCounters]) -> Vec<CpuLoad> {
use std::time::{SystemTime, UNIX_EPOCH};

let secs = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs();
if secs % 20 < 7 {
// High user load
return vec![
CpuLoad {
user_0_to_1: 0.7,
system_0_to_1: 0.2,
},
CpuLoad {
user_0_to_1: 0.0,
system_0_to_1: 0.1,
},
];
} else if secs % 20 < 14 {
// High system load
return vec![
CpuLoad {
user_0_to_1: 0.2,
system_0_to_1: 0.7,
},
CpuLoad {
user_0_to_1: 0.1,
system_0_to_1: 0.0,
},
];
}

// Idle
return vec![
CpuLoad {
user_0_to_1: 1.0,
user_0_to_1: 0.0,
system_0_to_1: 0.0,
},
CpuLoad {
Expand Down

0 comments on commit ff0f025

Please sign in to comment.