Skip to content

Commit

Permalink
gpu: dependency-free amdgpu parsing
Browse files Browse the repository at this point in the history
Co-authored-by: lvxnull2 <[email protected]>

gpu: fix clippy issues
  • Loading branch information
yretenai committed Dec 2, 2024
1 parent a4c83d7 commit 0828efd
Show file tree
Hide file tree
Showing 5 changed files with 1,129 additions and 121 deletions.
20 changes: 0 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ required-features = ["generate_schema"]
# Used for general builds.
battery = ["starship-battery"]
nvidia = ["nvml-wrapper"]
amd = ["libamdgpu_top"]
gpu = ["nvidia", "amd"]
gpu = ["nvidia"]
zfs = []
deploy = ["battery", "gpu", "zfs"]
default = ["deploy"]
Expand Down Expand Up @@ -113,7 +112,6 @@ libc = "0.2.162"

[target.'cfg(target_os = "linux")'.dependencies]
rustix = { version = "0.38.40", features = ["fs", "param"] }
libamdgpu_top = { version = "0.10.0", optional = true }

[target.'cfg(target_os = "macos")'.dependencies]
core-foundation = "0.10.0"
Expand Down
25 changes: 20 additions & 5 deletions src/data_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#[cfg(feature = "nvidia")]
pub mod nvidia;

#[cfg(all(feature = "amd", target_os = "linux"))]
#[cfg(all(target_os = "linux", feature = "gpu"))]
pub mod amd;

#[cfg(feature = "battery")]
Expand Down Expand Up @@ -376,11 +376,12 @@ impl DataCollector {
}
}

#[cfg(all(feature = "amd", target_os = "linux"))]
#[cfg(target_os = "linux")]
if let Some(data) = amd::get_amd_vecs(
&self.temperature_type,
&self.filters.temp_filter,
&self.widgets_to_harvest,
self.last_collection_time,
) {
if let Some(mut temp) = data.temperature {
if let Some(sensors) = &mut self.data.temperature_sensors {
Expand All @@ -398,9 +399,23 @@ impl DataCollector {
}
}

self.data.gpu = Some(local_gpu);
self.gpu_pids = Some(local_gpu_pids);
self.gpus_total_mem = Some(local_gpu_total_mem);
self.data.gpu = if !local_gpu.is_empty() {
Some(local_gpu)
} else {
None
};

self.gpu_pids = if !local_gpu_pids.is_empty() {
Some(local_gpu_pids)
} else {
None
};

self.gpus_total_mem = if local_gpu_total_mem > 0 {
Some(local_gpu_total_mem)
} else {
None
};
}
}

Expand Down
Loading

0 comments on commit 0828efd

Please sign in to comment.