summaryrefslogtreecommitdiffstats
path: root/src/app/data_harvester/cpu.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/data_harvester/cpu.rs')
-rw-r--r--src/app/data_harvester/cpu.rs66
1 files changed, 25 insertions, 41 deletions
diff --git a/src/app/data_harvester/cpu.rs b/src/app/data_harvester/cpu.rs
index bbc17509..61e79e28 100644
--- a/src/app/data_harvester/cpu.rs
+++ b/src/app/data_harvester/cpu.rs
@@ -10,56 +10,40 @@ pub type CpuHarvest = Vec<CpuData>;
pub type PastCpuWork = f64;
pub type PastCpuTotal = f64;
-#[cfg(not(target_os = "linux"))]
-use sysinfo::{ProcessorExt, System, SystemExt};
-
-#[cfg(not(target_os = "linux"))]
-pub fn get_cpu_data_list(sys: &System, show_average_cpu: bool) -> CpuHarvest {
- let cpu_data = sys.get_processors();
- let avg_cpu_usage = sys.get_global_processor_info().get_cpu_usage();
- let mut cpu_vec = vec![];
-
- if show_average_cpu {
- cpu_vec.push(CpuData {
- cpu_prefix: "AVG".to_string(),
- cpu_count: None,
- cpu_usage: avg_cpu_usage as f64,
- });
- }
-
- for (itx, cpu) in cpu_data.iter().enumerate() {
- cpu_vec.push(CpuData {
- cpu_prefix: "CPU".to_string(),
- cpu_count: Some(itx),
- cpu_usage: f64::from(cpu.get_cpu_usage()),
- });
- }
-
- cpu_vec
-}
-
-#[cfg(target_os = "linux")]
pub async fn get_cpu_data_list(
show_average_cpu: bool, previous_cpu_times: &mut Vec<(PastCpuWork, PastCpuTotal)>,
previous_average_cpu_time: &mut Option<(PastCpuWork, PastCpuTotal)>,
) -> crate::error::Result<CpuHarvest> {
use futures::StreamExt;
+ #[cfg(target_os = "linux")]
use heim::cpu::os::linux::CpuTimeExt;
use std::collections::VecDeque;
fn convert_cpu_times(cpu_time: &heim::cpu::CpuTime) -> (f64, f64) {
- let working_time: f64 = (cpu_time.user()
- + cpu_time.nice()
- + cpu_time.system()
- + cpu_time.irq()
- + cpu_time.soft_irq()
- + cpu_time.steal())
- .get::<heim::units::time::second>();
- (
- working_time,
- working_time
- + (cpu_time.idle() + cpu_time.io_wait()).get::<heim::units::time::second>(),
- )
+ #[cfg(not(target_os = "linux"))]
+ {
+ let working_time: f64 =
+ (cpu_time.user() + cpu_time.system()).get::<heim::units::time::second>();
+ (
+ working_time,
+ working_time + cpu_time.idle().get::<heim::units::time::second>(),
+ )
+ }
+ #[cfg(target_os = "linux")]
+ {
+ let working_time: f64 = (cpu_time.user()
+ + cpu_time.nice()
+ + cpu_time.system()
+ + cpu_time.irq()
+ + cpu_time.soft_irq()
+ + cpu_time.steal())
+ .get::<heim::units::time::second>();
+ (
+ working_time,
+ working_time
+ + (cpu_time.idle() + cpu_time.io_wait()).get::<heim::units::time::second>(),
+ )
+ }
}
fn calculate_cpu_usage_percentage(