diff options
author | Clement Tsang <34804052+ClementTsang@users.noreply.github.com> | 2023-06-08 00:05:30 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-08 00:05:30 -0400 |
commit | 086b622c6665cdbb9d8d9a5447543abae67d9783 (patch) | |
tree | 5cfb3ddd8b6bbf114ef4b2d1d3d10026d971cd56 | |
parent | 358bddf990e204f1de7fb20a133a14e1af2bbe43 (diff) |
feature: use better names for duplicate temp sensors found by `/sys/class/thermal` (#1187)
* docs: update changelog
* feature: add a counter to duplicate names if using /sys/class/thermal/
* update changelog
-rw-r--r-- | CHANGELOG.md | 5 | ||||
-rw-r--r-- | src/app/data_harvester/temperature/linux.rs | 20 |
2 files changed, 22 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index cfc75a10..cd10c105 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,9 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.9.2] - Unreleased +## Bug Fixes + +- [#1186](https://github.com/ClementTsang/bottom/pull/1186): Fix for temperature sensor data gathering on Linux immediately halting if any method failed. + ## Features - [#1172](https://github.com/ClementTsang/bottom/pull/1172): Support human times for `time_delta` and `default_time_value`. +- [#1187](https://github.com/ClementTsang/bottom/pull/1187): Use better names for duplicate temp sensors found by `/sys/class/thermal`. ## [0.9.1] - 2023-05-14 diff --git a/src/app/data_harvester/temperature/linux.rs b/src/app/data_harvester/temperature/linux.rs index c3f250ec..a626b54b 100644 --- a/src/app/data_harvester/temperature/linux.rs +++ b/src/app/data_harvester/temperature/linux.rs @@ -3,6 +3,7 @@ use std::{fs, path::Path}; use anyhow::{anyhow, Result}; +use hashbrown::HashMap; use super::{is_temp_filtered, TempHarvest, TemperatureType}; use crate::app::{ @@ -201,6 +202,9 @@ fn get_from_thermal_zone( ) -> Result<Vec<TempHarvest>> { let mut temperatures = vec![]; let path = Path::new("/sys/class/thermal"); + + let mut seen_names: HashMap<String, u32> = HashMap::new(); + for entry in path.read_dir()? { let file = entry?; if file @@ -211,9 +215,10 @@ fn get_from_thermal_zone( let file_path = file.path(); let name_path = file_path.join("type"); - let name = fs::read_to_string(name_path)?.trim_end().to_string(); + let name = fs::read_to_string(name_path)?; + let name = name.trim_end(); - if is_temp_filtered(filter, &name) { + if is_temp_filtered(filter, name) { let temp_path = file_path.join("temp"); let temp = fs::read_to_string(temp_path)? .trim_end() @@ -222,6 +227,15 @@ fn get_from_thermal_zone( crate::utils::error::BottomError::ConversionError(e.to_string()) })? / 1_000.0; + + let name = if let Some(count) = seen_names.get_mut(name) { + *count += 1; + format!("{name} ({})", *count) + } else { + seen_names.insert(name.to_string(), 0); + name.to_string() + }; + temperatures.push(TempHarvest { name, temperature: match temp_type { @@ -245,7 +259,7 @@ pub fn get_temperature_data( get_from_hwmon(temp_type, filter).unwrap_or_default(); if temperature_vec.is_empty() { - // If it's empty, try to fall back to checking `thermal_zone*`. + // If it's empty or it fails, try to fall back to checking `thermal_zone*`. temperature_vec = get_from_thermal_zone(temp_type, filter).unwrap_or_default(); } |