Skip to content

Commit

Permalink
Cleaner trace logs
Browse files Browse the repository at this point in the history
  • Loading branch information
nokyan committed Jan 24, 2025
1 parent d1f14bc commit 6aabf21
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/utils/gpu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,38 +193,40 @@ pub trait GpuImpl {

fn read_sysfs_int<P: AsRef<Path> + std::marker::Send>(&self, file: P) -> Result<isize> {
let path = self.sysfs_path().join(file);
trace!("Reading {path:?} (parsing to int)…");
trace!("Reading {} (parsing to isize)…", &path.to_string_lossy());
std::fs::read_to_string(&path)?
.replace('\n', "")
.parse::<isize>()
.inspect(|int| trace!("{path:?} → {int} (size)"))
.inspect(|int| trace!("{} → {int} (isize)", &path.to_string_lossy()))
.with_context(|| format!("error parsing file {}", &path.to_string_lossy()))
}

fn read_device_file<P: AsRef<Path> + std::marker::Send>(&self, file: P) -> Result<String> {
let path = self.sysfs_path().join("device").join(file);
trace!("Reading {path:?}…");
trace!("Reading {}…", &path.to_string_lossy());
std::fs::read_to_string(&path)
.map(|s| s.replace('\n', ""))
.inspect(|s| trace!("{path:?} → {s} (String)"))
.inspect(|s| trace!("{} → {s} (String)", &path.to_string_lossy()))
.with_context(|| format!("error reading file {}", &path.to_string_lossy()))
}

fn read_device_int<P: AsRef<Path> + std::marker::Send>(&self, file: P) -> Result<isize> {
let path = self.sysfs_path().join("device").join(file);
self.read_device_file(&path)?
trace!("Reading {} (parsing to isize)…", &path.to_string_lossy());
std::fs::read_to_string(&path)?
.replace('\n', "")
.parse::<isize>()
.inspect(|int| trace!("{path:?} → {int} (size)"))
.inspect(|int| trace!("{} → {int} (isize)", &path.to_string_lossy()))
.with_context(|| format!("error parsing file {}", &path.to_string_lossy()))
}

fn read_hwmon_int<P: AsRef<Path> + std::marker::Send>(&self, file: P) -> Result<isize> {
let path = self.first_hwmon().context("no hwmon found")?.join(file);
trace!("Reading {path:?}…");
trace!("Reading {} (parsing to isize)…", &path.to_string_lossy());
std::fs::read_to_string(&path)?
.replace('\n', "")
.parse::<isize>()
.inspect(|int| trace!("{path:?} → {int} (size)"))
.inspect(|int| trace!("{} → {int} (isize)", &path.to_string_lossy()))
.with_context(|| format!("error parsing file {}", &path.to_string_lossy()))
}

Expand Down

0 comments on commit 6aabf21

Please sign in to comment.