perf: move temperature polling into nova-stats daemon; Temperature.qml is now pure display
This commit is contained in:
parent
dd5ca9d263
commit
3854763ce5
3 changed files with 32 additions and 17 deletions
|
|
@ -93,6 +93,23 @@ fn read_stat() -> Vec<Sample> {
|
|||
parse_stat(&fs::read_to_string("/proc/stat").unwrap_or_default())
|
||||
}
|
||||
|
||||
fn read_temp_celsius() -> Option<i32> {
|
||||
let mut max: Option<i32> = None;
|
||||
for i in 0.. {
|
||||
let path = format!("/sys/class/thermal/thermal_zone{i}/temp");
|
||||
match fs::read_to_string(&path) {
|
||||
Ok(s) => {
|
||||
if let Ok(millic) = s.trim().parse::<i32>() {
|
||||
let c = millic / 1000;
|
||||
max = Some(max.map_or(c, |m: i32| m.max(c)));
|
||||
}
|
||||
}
|
||||
Err(_) => break,
|
||||
}
|
||||
}
|
||||
max
|
||||
}
|
||||
|
||||
fn read_core_freqs() -> Vec<f64> {
|
||||
let mut freqs = Vec::new();
|
||||
for i in 0.. {
|
||||
|
|
@ -148,6 +165,12 @@ fn emit_cpu(out: &mut impl Write, prev: &[Sample], curr: &[Sample], freqs: &[f64
|
|||
let _ = writeln!(out, "]}}");
|
||||
}
|
||||
|
||||
fn emit_temp(out: &mut impl Write) {
|
||||
if let Some(c) = read_temp_celsius() {
|
||||
let _ = writeln!(out, "{{\"type\":\"temp\",\"celsius\":{c}}}");
|
||||
}
|
||||
}
|
||||
|
||||
fn emit_mem(out: &mut impl Write) {
|
||||
let content = fs::read_to_string("/proc/meminfo").unwrap_or_default();
|
||||
if let Some(m) = parse_meminfo(&content) {
|
||||
|
|
@ -190,6 +213,7 @@ fn main() {
|
|||
|
||||
if tick.is_multiple_of(2) {
|
||||
emit_mem(&mut out);
|
||||
emit_temp(&mut out);
|
||||
}
|
||||
|
||||
let _ = out.flush();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue