From ff0f02534e4e1bf36897c3eca302366d157db834 Mon Sep 17 00:00:00 2001 From: Johan Walles Date: Sun, 23 Jul 2023 09:10:58 +0200 Subject: [PATCH] Restore demo behavior --- libloadviz/src/cpuload.rs | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/libloadviz/src/cpuload.rs b/libloadviz/src/cpuload.rs index 0f3eeee..370b000 100644 --- a/libloadviz/src/cpuload.rs +++ b/libloadviz/src/cpuload.rs @@ -60,9 +60,42 @@ pub fn diff(older: &[LoadCounters], newer: &[LoadCounters]) -> Vec { /// Hard code load in debug builds to simplify testing the visualization #[cfg(all(debug_assertions, not(test)))] pub fn diff(_: &[LoadCounters], _: &[LoadCounters]) -> Vec { + 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 {