mirror of
https://github.com/RGBCube/superfreq
synced 2025-07-27 17:07:44 +00:00
system: add logs
This commit is contained in:
parent
f7f738caa9
commit
ce83ba3c91
2 changed files with 94 additions and 10 deletions
|
@ -56,10 +56,10 @@ struct Daemon {
|
||||||
|
|
||||||
impl Daemon {
|
impl Daemon {
|
||||||
fn rescan(&mut self) -> anyhow::Result<()> {
|
fn rescan(&mut self) -> anyhow::Result<()> {
|
||||||
log::debug!("rescanning daemon view of system hardware...");
|
|
||||||
|
|
||||||
self.system.rescan()?;
|
self.system.rescan()?;
|
||||||
|
|
||||||
|
log::debug!("appending daemon logs...");
|
||||||
|
|
||||||
let at = Instant::now();
|
let at = Instant::now();
|
||||||
|
|
||||||
while self.cpu_log.len() > 100 {
|
while self.cpu_log.len() > 100 {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{collections::HashMap, path::Path};
|
use std::{collections::HashMap, path::Path, time::Instant};
|
||||||
|
|
||||||
use anyhow::{Context, bail};
|
use anyhow::{Context, bail};
|
||||||
|
|
||||||
|
@ -39,19 +39,72 @@ impl System {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rescan(&mut self) -> anyhow::Result<()> {
|
pub fn rescan(&mut self) -> anyhow::Result<()> {
|
||||||
self.cpus = cpu::Cpu::all().context("failed to scan CPUs")?;
|
log::debug!("rescanning view of system hardware...");
|
||||||
|
|
||||||
|
{
|
||||||
|
let start = Instant::now();
|
||||||
|
self.cpus = cpu::Cpu::all().context("failed to scan CPUs")?;
|
||||||
|
log::debug!(
|
||||||
|
"rescanned all CPUs in {millis}ms",
|
||||||
|
millis = start.elapsed().as_millis(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
let start = Instant::now();
|
||||||
self.power_supplies =
|
self.power_supplies =
|
||||||
power_supply::PowerSupply::all().context("failed to scan power supplies")?;
|
power_supply::PowerSupply::all().context("failed to scan power supplies")?;
|
||||||
|
log::debug!(
|
||||||
|
"rescanned all power supplies in {millis}ms",
|
||||||
|
millis = start.elapsed().as_millis(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
self.is_ac = self
|
self.is_ac = self
|
||||||
.power_supplies
|
.power_supplies
|
||||||
.iter()
|
.iter()
|
||||||
.any(|power_supply| power_supply.is_ac())
|
.any(|power_supply| power_supply.is_ac())
|
||||||
|| self.is_desktop()?;
|
|| {
|
||||||
|
log::debug!(
|
||||||
|
"checking whether if this device is a desktop to determine if it is AC as no power supplies are"
|
||||||
|
);
|
||||||
|
|
||||||
|
let start = Instant::now();
|
||||||
|
let is_desktop = self.is_desktop()?;
|
||||||
|
log::debug!(
|
||||||
|
"checked if is a desktop in {millis}ms",
|
||||||
|
millis = start.elapsed().as_millis(),
|
||||||
|
);
|
||||||
|
|
||||||
|
log::debug!(
|
||||||
|
"scan result: {elaborate}",
|
||||||
|
elaborate = if is_desktop {
|
||||||
|
"is a desktop, therefore is AC"
|
||||||
|
} else {
|
||||||
|
"not a desktop, and not AC"
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
is_desktop
|
||||||
|
};
|
||||||
|
|
||||||
|
{
|
||||||
|
let start = Instant::now();
|
||||||
self.rescan_load_average()?;
|
self.rescan_load_average()?;
|
||||||
|
log::debug!(
|
||||||
|
"rescanned load average in {millis}ms",
|
||||||
|
millis = start.elapsed().as_millis(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
let start = Instant::now();
|
||||||
self.rescan_temperatures()?;
|
self.rescan_temperatures()?;
|
||||||
|
log::debug!(
|
||||||
|
"rescanned temperatures in {millis}ms",
|
||||||
|
millis = start.elapsed().as_millis(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -109,9 +162,20 @@ impl System {
|
||||||
let input_path = device_path.join(format!("temp{i}_input"));
|
let input_path = device_path.join(format!("temp{i}_input"));
|
||||||
|
|
||||||
if !label_path.exists() || !input_path.exists() {
|
if !label_path.exists() || !input_path.exists() {
|
||||||
|
log::debug!(
|
||||||
|
"{label_path} or {input_path} doesn't exist, skipping temp label",
|
||||||
|
label_path = label_path.display(),
|
||||||
|
input_path = input_path.display(),
|
||||||
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log::debug!(
|
||||||
|
"{label_path} or {input_path} exists, scanning temp label...",
|
||||||
|
label_path = label_path.display(),
|
||||||
|
input_path = input_path.display(),
|
||||||
|
);
|
||||||
|
|
||||||
let Some(label) = fs::read(&label_path).with_context(|| {
|
let Some(label) = fs::read(&label_path).with_context(|| {
|
||||||
format!(
|
format!(
|
||||||
"failed to read hardware hardware device label from '{path}'",
|
"failed to read hardware hardware device label from '{path}'",
|
||||||
|
@ -121,6 +185,7 @@ impl System {
|
||||||
else {
|
else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
log::debug!("label content: {number}");
|
||||||
|
|
||||||
// Match various common label formats:
|
// Match various common label formats:
|
||||||
// "Core X", "core X", "Core-X", "CPU Core X", etc.
|
// "Core X", "core X", "Core-X", "CPU Core X", etc.
|
||||||
|
@ -139,9 +204,16 @@ impl System {
|
||||||
.trim_start_matches("-")
|
.trim_start_matches("-")
|
||||||
.trim();
|
.trim();
|
||||||
|
|
||||||
|
log::debug!("stripped 'Core' or similar identifier prefix of label content: {number}");
|
||||||
|
|
||||||
let Ok(number) = number.parse::<u32>() else {
|
let Ok(number) = number.parse::<u32>() else {
|
||||||
|
log::debug!("stripped content not a valid number, skipping");
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
log::debug!("stripped content is a valid number, taking it as the core number");
|
||||||
|
log::debug!(
|
||||||
|
"it is fine if this number doesn't seem accurate due to CPU binning, see a more detailed explanation at: https://rgbcu.be/blog/why-cores"
|
||||||
|
);
|
||||||
|
|
||||||
let Some(temperature_mc) = fs::read_n::<i64>(&input_path).with_context(|| {
|
let Some(temperature_mc) = fs::read_n::<i64>(&input_path).with_context(|| {
|
||||||
format!(
|
format!(
|
||||||
|
@ -152,6 +224,10 @@ impl System {
|
||||||
else {
|
else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
log::debug!(
|
||||||
|
"temperature content: {celcius} celcius",
|
||||||
|
celcius = temperature_mc as f64 / 1000.0
|
||||||
|
);
|
||||||
|
|
||||||
temperatures.insert(number, temperature_mc as f64 / 1000.0);
|
temperatures.insert(number, temperature_mc as f64 / 1000.0);
|
||||||
}
|
}
|
||||||
|
@ -160,6 +236,7 @@ impl System {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_desktop(&mut self) -> anyhow::Result<bool> {
|
fn is_desktop(&mut self) -> anyhow::Result<bool> {
|
||||||
|
log::debug!("checking chassis type to determine if we are a desktop");
|
||||||
if let Some(chassis_type) =
|
if let Some(chassis_type) =
|
||||||
fs::read("/sys/class/dmi/id/chassis_type").context("failed to read chassis type")?
|
fs::read("/sys/class/dmi/id/chassis_type").context("failed to read chassis type")?
|
||||||
{
|
{
|
||||||
|
@ -170,16 +247,18 @@ impl System {
|
||||||
match chassis_type.trim() {
|
match chassis_type.trim() {
|
||||||
// Desktop form factors.
|
// Desktop form factors.
|
||||||
"3" | "4" | "5" | "6" | "7" | "15" | "16" | "17" => {
|
"3" | "4" | "5" | "6" | "7" | "15" | "16" | "17" => {
|
||||||
|
log::debug!("chassis is a desktop form factor, short circuting true");
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Laptop form factors.
|
// Laptop form factors.
|
||||||
"9" | "10" | "14" | "31" => {
|
"9" | "10" | "14" | "31" => {
|
||||||
|
log::debug!("chassis is a laptop form factor, short circuting false");
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unknown, continue with other checks
|
// Unknown, continue with other checks
|
||||||
_ => {}
|
_ => log::debug!("unknown chassis type"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,21 +269,26 @@ impl System {
|
||||||
"/proc/acpi/battery",
|
"/proc/acpi/battery",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
log::debug!("checking existence of ACPI paths");
|
||||||
for path in laptop_acpi_paths {
|
for path in laptop_acpi_paths {
|
||||||
if fs::exists(path) {
|
if fs::exists(path) {
|
||||||
|
log::debug!("path '{path}' exists, short circuting false");
|
||||||
return Ok(false); // Likely a laptop.
|
return Ok(false); // Likely a laptop.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log::debug!("checking if power saving paths exists");
|
||||||
// Check CPU power policies, desktops often don't have these
|
// Check CPU power policies, desktops often don't have these
|
||||||
let power_saving_exists = fs::exists("/sys/module/intel_pstate/parameters/no_hwp")
|
let power_saving_exists = fs::exists("/sys/module/intel_pstate/parameters/no_hwp")
|
||||||
|| fs::exists("/sys/devices/system/cpu/cpufreq/conservative");
|
|| fs::exists("/sys/devices/system/cpu/cpufreq/conservative");
|
||||||
|
|
||||||
if !power_saving_exists {
|
if !power_saving_exists {
|
||||||
|
log::debug!("power saving paths do not exist, short circuting true");
|
||||||
return Ok(true); // Likely a desktop.
|
return Ok(true); // Likely a desktop.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default to assuming desktop if we can't determine.
|
// Default to assuming desktop if we can't determine.
|
||||||
|
log::debug!("cannot determine whether if we are a desktop, defaulting to true");
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue