Skip to content

Commit

Permalink
Use better trace logs for drm files for NPUs as well
Browse files Browse the repository at this point in the history
  • Loading branch information
nokyan committed Jan 24, 2025
1 parent 6aabf21 commit af8faeb
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/utils/npu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,33 +113,40 @@ pub trait NpuImpl {

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:?}…");
trace!("Reading {} (parsing to isize)…", &path.to_string_lossy());
std::fs::read_to_string(&path)?
.replace('\n', "")
.parse::<isize>()
.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:?}…");
Ok(std::fs::read_to_string(path)?.replace('\n', ""))
trace!("Reading {}…", &path.to_string_lossy());
std::fs::read_to_string(&path)
.map(|s| s.replace('\n', ""))
.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);
trace!("Reading {path:?}…");
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!("{} → {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!("{} → {int} (isize)", &path.to_string_lossy()))
.with_context(|| format!("error parsing file {}", &path.to_string_lossy()))
}

Expand Down

0 comments on commit af8faeb

Please sign in to comment.