summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2023-02-19 18:44:35 -0500
committerGitHub <noreply@github.com>2023-02-19 18:44:35 -0500
commit6d15f0100901652bd135cab7915c70f79785c047 (patch)
tree8fef45834e935766bcf1ebc637c5851a13b399ff
parent2a1c4104fd5c5279b391c02708295839faa351ec (diff)
other: support hw.temperature-based temps on FreeBSD (#1024)
* other: support hw.temperature-based temps for FreeBSD * update changelog * enable sysctl always for freebsd
-rw-r--r--CHANGELOG.md1
-rw-r--r--Cargo.lock23
-rw-r--r--Cargo.toml20
-rw-r--r--src/app/data_harvester/temperature/sysinfo.rs25
4 files changed, 61 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1a8bf802..cdd09b07 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#1016](https://github.com/ClementTsang/bottom/pull/1016): Add support for displaying process usernames on Windows.
- [#1022](https://github.com/ClementTsang/bottom/pull/1022): Support three-character hex colour strings for styling.
+- [#1024](https://github.com/ClementTsang/bottom/pull/1024): Support FreeBSD temperature sensors based on `hw.temperature`.
## Changes
diff --git a/Cargo.lock b/Cargo.lock
index 949deed9..bebd1cef 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -568,6 +568,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
[[package]]
+name = "enum-as-inner"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c9720bba047d567ffc8a3cba48bf19126600e249ab7f128e9233e6376976a116"
+dependencies = [
+ "heck",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
name = "errno"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -787,6 +799,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
[[package]]
+name = "heck"
+version = "0.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
+
+[[package]]
name = "heim"
version = "0.1.0-rc.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1644,12 +1662,13 @@ dependencies = [
[[package]]
name = "sysctl"
-version = "0.5.2"
+version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f99d037b2bef227ab8963f4b0acc33ecbb1f9a2e7365add7789372b387ec19e1"
+checksum = "ed66d6a2ccbd656659289bc90767895b7abbdec897a0fc6031aca3ed1cb51d3e"
dependencies = [
"bitflags",
"byteorder",
+ "enum-as-inner",
"libc",
"thiserror",
"walkdir",
diff --git a/Cargo.toml b/Cargo.toml
index 48783b0b..d75015b8 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -63,13 +63,12 @@ strip = false
battery = ["starship-battery"]
gpu = ["nvidia"]
nvidia = ["nvml-wrapper"]
-zfs = ["sysctl"]
# The features we use by default.
-default = ["fern", "log", "battery", "gpu", "zfs"]
+default = ["fern", "log", "battery", "gpu"]
# The features we use on deploy. Logging is not included as that is primarily (for now) just for debugging locally.
-deploy = ["battery", "gpu", "zfs"]
+deploy = ["battery", "gpu"]
[dependencies]
anyhow = "1.0.57"
@@ -109,7 +108,13 @@ unicode-width = "0.1.10"
libc = "0.2.124"
[target.'cfg(target_os = "linux")'.dependencies]
-heim = { version = "0.1.0-rc.1", features = ["cpu", "disk", "memory", "net", "sensors"] }
+heim = { version = "0.1.0-rc.1", features = [
+ "cpu",
+ "disk",
+ "memory",
+ "net",
+ "sensors",
+] }
procfs = { version = "0.14.2", default-features = false }
smol = "1.2.5"
@@ -119,13 +124,16 @@ mach2 = "0.4.1"
[target.'cfg(target_os = "windows")'.dependencies]
heim = { version = "0.1.0-rc.1", features = ["cpu", "disk", "memory"] }
-windows = { version = "0.44.0", features = ["Win32_System_Threading", "Win32_Foundation"] }
+windows = { version = "0.44.0", features = [
+ "Win32_System_Threading",
+ "Win32_Foundation",
+] }
winapi = "0.3.9"
[target.'cfg(target_os = "freebsd")'.dependencies]
serde_json = { version = "1.0.82" }
-sysctl = { version = "0.5.2", optional = true }
+sysctl = { version = "0.5.4" }
filedescriptor = "0.8.2"
[dev-dependencies]
diff --git a/src/app/data_harvester/temperature/sysinfo.rs b/src/app/data_harvester/temperature/sysinfo.rs
index c1e11527..d72901aa 100644
--- a/src/app/data_harvester/temperature/sysinfo.rs
+++ b/src/app/data_harvester/temperature/sysinfo.rs
@@ -38,5 +38,30 @@ pub fn get_temperature_data(
super::nvidia::add_nvidia_data(&mut temperature_vec, temp_type, filter)?;
}
+ // For RockPro64 boards on FreeBSD, they apparently use "hw.temperature" for sensors.
+ #[cfg(target_os = "freebsd")]
+ {
+ use sysctl::Sysctl;
+
+ const KEY: &str = "hw.temperature";
+ if let Ok(root) = sysctl::Ctl::new(KEY) {
+ for ctl in sysctl::CtlIter::below(root).flatten() {
+ if let (Ok(name), Ok(temp)) = (ctl.name(), ctl.value()) {
+ if let Some(temp) = temp.as_temperature() {
+ temperature_vec.push(TempHarvest {
+ name,
+ temperature: match temp_type {
+ TemperatureType::Celsius => temp.celsius(),
+ TemperatureType::Kelvin => temp.kelvin(),
+ TemperatureType::Fahrenheit => temp.fahrenheit(),
+ },
+ });
+ }
+ }
+ }
+ }
+ }
+
+ // TODO: Should we instead use a hashmap -> vec to skip dupes?
Ok(Some(temperature_vec))
}