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.
This commit is contained in:
Clement Tsang 2022-09-18 05:13:27 -04:00 committed by GitHub
parent cc048de3b0
commit e80e07a716
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 44 deletions

View file

@ -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;

View file

@ -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::*;

View file

@ -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;

View file

@ -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();