Skip to content

Commit

Permalink
Trace logs for reading device files
Browse files Browse the repository at this point in the history
  • Loading branch information
nokyan committed Dec 24, 2024
1 parent 42c1bc9 commit 58cea02
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/utils/gpu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ 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:?}…");
std::fs::read_to_string(&path)?
.replace('\n', "")
.parse::<isize>()
Expand All @@ -145,6 +146,7 @@ pub trait GpuImpl {

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', ""))
}

Expand All @@ -157,6 +159,7 @@ pub trait GpuImpl {

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:?}…");
std::fs::read_to_string(&path)?
.replace('\n', "")
.parse::<isize>()
Expand Down
4 changes: 4 additions & 0 deletions src/utils/npu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ 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:?}…");
std::fs::read_to_string(&path)?
.replace('\n', "")
.parse::<isize>()
Expand All @@ -121,18 +122,21 @@ pub trait NpuImpl {

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', ""))
}

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)?
.parse::<isize>()
.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:?}…");
std::fs::read_to_string(&path)?
.replace('\n', "")
.parse::<isize>()
Expand Down

0 comments on commit 58cea02

Please sign in to comment.