Skip to content

Commit

Permalink
Trace contents of drm files when reading them
Browse files Browse the repository at this point in the history
  • Loading branch information
nokyan committed Jan 24, 2025
1 parent 217b518 commit d1f14bc
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/utils/gpu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,23 +193,28 @@ 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:?}…");
trace!("Reading {path:?} (parsing to int)…");
std::fs::read_to_string(&path)?
.replace('\n', "")
.parse::<isize>()
.inspect(|int| trace!("{path:?} → {int} (size)"))
.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', ""))
std::fs::read_to_string(&path)
.map(|s| s.replace('\n', ""))
.inspect(|s| trace!("{path:?} → {s} (String)"))
.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)?
.parse::<isize>()
.inspect(|int| trace!("{path:?} → {int} (size)"))
.with_context(|| format!("error parsing file {}", &path.to_string_lossy()))
}

Expand All @@ -219,6 +224,7 @@ pub trait GpuImpl {
std::fs::read_to_string(&path)?
.replace('\n', "")
.parse::<isize>()
.inspect(|int| trace!("{path:?} → {int} (size)"))
.with_context(|| format!("error parsing file {}", &path.to_string_lossy()))
}

Expand Down

0 comments on commit d1f14bc

Please sign in to comment.