diff options
author | Clement Tsang <34804052+ClementTsang@users.noreply.github.com> | 2022-09-18 05:13:27 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-18 05:13:27 -0400 |
commit | e80e07a716d12f934a91a4ddb454aeaeee1c7d5f (patch) | |
tree | 5b0eef9f9d11852f41828c42be23c815d83427b7 /src | |
parent | cc048de3b03a5cdf6ec93a529df6cae061824ad0 (diff) |
refactor: minor cleanup of linux disk code (#813)
Since we no longer use heim for Linux disk checking, we can remove the
async reliance and update some file names/comments to be more
appropriate to the current state of the code. We also do some small
cleanup.
Diffstat (limited to 'src')
-rw-r--r-- | src/app/data_harvester.rs | 50 | ||||
-rw-r--r-- | src/app/data_harvester/temperature.rs | 4 | ||||
-rw-r--r-- | src/app/data_harvester/temperature/linux.rs (renamed from src/app/data_harvester/temperature/heim.rs) | 17 | ||||
-rw-r--r-- | src/app/data_harvester/temperature/sysinfo.rs | 11 |
4 files changed, 38 insertions, 44 deletions
diff --git a/src/app/data_harvester.rs b/src/app/data_harvester.rs index a15be6e8..cb02bdb1 100644 --- a/src/app/data_harvester.rs +++ b/src/app/data_harvester.rs @@ -343,6 +343,29 @@ impl DataCollector { } } + if self.widgets_to_harvest.use_temp { + #[cfg(not(target_os = "linux"))] + { + if let Ok(data) = temperature::get_temperature_data( + &self.sys, + &self.temperature_type, + &self.filters.temp_filter, + ) { + self.data.temperature_sensors = data; + } + } + + #[cfg(target_os = "linux")] + { + if let Ok(data) = temperature::get_temperature_data( + &self.temperature_type, + &self.filters.temp_filter, + ) { + self.data.temperature_sensors = data; + } + } + } + let network_data_fut = { #[cfg(any(target_os = "windows", target_os = "freebsd"))] { @@ -384,33 +407,12 @@ impl DataCollector { &self.filters.mount_filter, ); let disk_io_usage_fut = disks::get_io_usage(self.widgets_to_harvest.use_disk); - let temp_data_fut = { - #[cfg(not(target_os = "linux"))] - { - temperature::get_temperature_data( - &self.sys, - &self.temperature_type, - self.widgets_to_harvest.use_temp, - &self.filters.temp_filter, - ) - } - - #[cfg(target_os = "linux")] - { - temperature::get_temperature_data( - &self.temperature_type, - self.widgets_to_harvest.use_temp, - &self.filters.temp_filter, - ) - } - }; - let (net_data, mem_res, disk_res, io_res, temp_res) = join!( + let (net_data, mem_res, disk_res, io_res) = join!( network_data_fut, mem_data_fut, disk_data_fut, disk_io_usage_fut, - temp_data_fut ); if let Ok(net_data) = net_data { @@ -442,10 +444,6 @@ impl DataCollector { self.data.io = io; } - if let Ok(temp) = temp_res { - self.data.temperature_sensors = temp; - } - // Update time self.data.last_collection_time = current_instant; self.last_collection_time = current_instant; diff --git a/src/app/data_harvester/temperature.rs b/src/app/data_harvester/temperature.rs index 020ae912..23465588 100644 --- a/src/app/data_harvester/temperature.rs +++ b/src/app/data_harvester/temperature.rs @@ -5,8 +5,8 @@ cfg_if::cfg_if! { if #[cfg(target_os = "linux")] { - pub mod heim; - pub use self::heim::*; + pub mod linux; + pub use self::linux::*; } else if #[cfg(any(target_os = "freebsd", target_os = "macos", target_os = "windows"))] { pub mod sysinfo; pub use self::sysinfo::*; diff --git a/src/app/data_harvester/temperature/heim.rs b/src/app/data_harvester/temperature/linux.rs index 6a9b8f59..beeb265a 100644 --- a/src/app/data_harvester/temperature/heim.rs +++ b/src/app/data_harvester/temperature/linux.rs @@ -1,10 +1,11 @@ -//! Gets temperature data via heim. +//! Gets temperature sensor data for Linux platforms. use super::{is_temp_filtered, temp_vec_sort, TempHarvest, TemperatureType}; use crate::app::{ data_harvester::temperature::{convert_celsius_to_fahrenheit, convert_celsius_to_kelvin}, Filter, }; +use anyhow::{anyhow, Result}; /// Get temperature sensors from the linux sysfs interface `/sys/class/hwmon` /// @@ -21,15 +22,11 @@ use crate::app::{ /// This has the notable issue that once this happens, /// the device will be *kept* on through the sensor reading, /// and not be able to re-enter ACPI D3cold. -pub async fn get_temperature_data( - temp_type: &TemperatureType, actually_get: bool, filter: &Option<Filter>, -) -> crate::utils::error::Result<Option<Vec<TempHarvest>>> { +pub fn get_temperature_data( + temp_type: &TemperatureType, filter: &Option<Filter>, +) -> Result<Option<Vec<TempHarvest>>> { use std::{fs, path::Path}; - if !actually_get { - return Ok(None); - } - let mut temperature_vec: Vec<TempHarvest> = Vec::new(); // Documented at https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-hwmon @@ -83,7 +80,9 @@ pub async fn get_temperature_data( let file = entry?; let name = file.file_name(); // This should always be ASCII - let name = name.to_str().unwrap(); + let name = name + .to_str() + .ok_or_else(|| anyhow!("temperature device filenames should be ASCII"))?; // We only want temperature sensors, skip others early if !(name.starts_with("temp") && name.ends_with("input")) { continue; diff --git a/src/app/data_harvester/temperature/sysinfo.rs b/src/app/data_harvester/temperature/sysinfo.rs index f4f0061b..42ed1a68 100644 --- a/src/app/data_harvester/temperature/sysinfo.rs +++ b/src/app/data_harvester/temperature/sysinfo.rs @@ -5,16 +5,13 @@ use super::{ TempHarvest, TemperatureType, }; use crate::app::Filter; +use anyhow::Result; -pub async fn get_temperature_data( - sys: &sysinfo::System, temp_type: &TemperatureType, actually_get: bool, filter: &Option<Filter>, -) -> crate::utils::error::Result<Option<Vec<TempHarvest>>> { +pub fn get_temperature_data( + sys: &sysinfo::System, temp_type: &TemperatureType, filter: &Option<Filter>, +) -> Result<Option<Vec<TempHarvest>>> { use sysinfo::{ComponentExt, SystemExt}; - if !actually_get { - return Ok(None); - } - let mut temperature_vec: Vec<TempHarvest> = Vec::new(); let sensor_data = sys.components(); |