enable clippy pedantic for nova-stats, fix all warnings
This commit is contained in:
parent
64d0172bee
commit
e30cae5c7f
5 changed files with 15 additions and 17 deletions
|
|
@ -3,6 +3,12 @@ name = "nova-stats"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
[lints.clippy]
|
||||||
|
pedantic = { level = "warn", priority = -1 }
|
||||||
|
cast_possible_truncation = "allow"
|
||||||
|
cast_precision_loss = "allow"
|
||||||
|
cast_sign_loss = "allow"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "nova-stats"
|
name = "nova-stats"
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|
|
||||||
|
|
@ -56,11 +56,7 @@ pub fn emit_cpu(out: &mut impl Write, prev: &[Sample], curr: &[Sample], freqs: &
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let usage = prev
|
let usage = prev.first().zip(curr.first()).map_or(0, |(p, c)| pct(p, c));
|
||||||
.first()
|
|
||||||
.zip(curr.first())
|
|
||||||
.map(|(p, c)| pct(p, c))
|
|
||||||
.unwrap_or(0);
|
|
||||||
|
|
||||||
let core_usage: Vec<u32> = prev
|
let core_usage: Vec<u32> = prev
|
||||||
.iter()
|
.iter()
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ fn find_amd_hwmon() -> Option<String> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_amd(card: &str, hwmon: &Option<String>) -> Option<GpuInfo> {
|
fn read_amd(card: &str, hwmon: Option<&String>) -> Option<GpuInfo> {
|
||||||
let usage: u32 = fs::read_to_string(format!("{card}/gpu_busy_percent"))
|
let usage: u32 = fs::read_to_string(format!("{card}/gpu_busy_percent"))
|
||||||
.ok()?
|
.ok()?
|
||||||
.trim()
|
.trim()
|
||||||
|
|
@ -70,11 +70,9 @@ fn read_amd(card: &str, hwmon: &Option<String>) -> Option<GpuInfo> {
|
||||||
.parse()
|
.parse()
|
||||||
.ok()?;
|
.ok()?;
|
||||||
let temp_c = hwmon
|
let temp_c = hwmon
|
||||||
.as_ref()
|
|
||||||
.and_then(|h| fs::read_to_string(format!("{h}/temp1_input")).ok())
|
.and_then(|h| fs::read_to_string(format!("{h}/temp1_input")).ok())
|
||||||
.and_then(|s| s.trim().parse::<i32>().ok())
|
.and_then(|s| s.trim().parse::<i32>().ok())
|
||||||
.map(|mc| mc / 1000)
|
.map_or(0, |mc| mc / 1000);
|
||||||
.unwrap_or(0);
|
|
||||||
Some(GpuInfo {
|
Some(GpuInfo {
|
||||||
usage,
|
usage,
|
||||||
vram_used_gb: vram_used as f64 / 1_073_741_824.0,
|
vram_used_gb: vram_used as f64 / 1_073_741_824.0,
|
||||||
|
|
@ -114,7 +112,7 @@ pub fn emit_gpu(out: &mut impl Write, backend: &GpuBackend) {
|
||||||
GpuBackend::Amd {
|
GpuBackend::Amd {
|
||||||
card_path,
|
card_path,
|
||||||
hwmon_path,
|
hwmon_path,
|
||||||
} => read_amd(card_path, hwmon_path),
|
} => read_amd(card_path, hwmon_path.as_ref()),
|
||||||
GpuBackend::Nvidia => read_nvidia(),
|
GpuBackend::Nvidia => read_nvidia(),
|
||||||
GpuBackend::None => return,
|
GpuBackend::None => return,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -55,8 +55,8 @@ fn main() {
|
||||||
tick += 1;
|
tick += 1;
|
||||||
|
|
||||||
let elapsed = t0.elapsed();
|
let elapsed = t0.elapsed();
|
||||||
if elapsed < interval {
|
if let Some(remaining) = interval.checked_sub(elapsed) {
|
||||||
thread::sleep(interval - elapsed);
|
thread::sleep(remaining);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,8 @@ pub fn read_thermal_devices() -> Vec<ThermalDevice> {
|
||||||
let temp_path = format!("/sys/class/thermal/thermal_zone{i}/temp");
|
let temp_path = format!("/sys/class/thermal/thermal_zone{i}/temp");
|
||||||
let type_path = format!("/sys/class/thermal/thermal_zone{i}/type");
|
let type_path = format!("/sys/class/thermal/thermal_zone{i}/type");
|
||||||
|
|
||||||
let temp_str = match fs::read_to_string(&temp_path) {
|
let Ok(temp_str) = fs::read_to_string(&temp_path) else {
|
||||||
Ok(s) => s,
|
break;
|
||||||
Err(_) => break,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let millic: i32 = match temp_str.trim().parse() {
|
let millic: i32 = match temp_str.trim().parse() {
|
||||||
|
|
@ -27,8 +26,7 @@ pub fn read_thermal_devices() -> Vec<ThermalDevice> {
|
||||||
let celsius = millic / 1000;
|
let celsius = millic / 1000;
|
||||||
|
|
||||||
let name = fs::read_to_string(&type_path)
|
let name = fs::read_to_string(&type_path)
|
||||||
.map(|s| s.trim().to_string())
|
.map_or_else(|_| format!("zone{i}"), |s| s.trim().to_string());
|
||||||
.unwrap_or_else(|_| format!("zone{i}"));
|
|
||||||
|
|
||||||
// Keep the highest temp seen for each device type
|
// Keep the highest temp seen for each device type
|
||||||
let entry = by_name.entry(name).or_insert(celsius);
|
let entry = by_name.entry(name).or_insert(celsius);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue