Skip to content

Commit 2eab880

Browse files
authored
Add last_seen_timestamp parameter to get more accurate process utilization counts. (#92)
This PR improves the process_utilization_stats_count function to accept a last_seen_timestamp parameter, providing more accurate process utilization counts.
1 parent 0a43c30 commit 2eab880

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

nvml-wrapper/src/device.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2231,7 +2231,7 @@ impl<'nvml> Device<'nvml> {
22312231

22322232
unsafe {
22332233
let last_seen_timestamp = last_seen_timestamp.into().unwrap_or(0);
2234-
let mut count = match self.process_utilization_stats_count()? {
2234+
let mut count = match self.process_utilization_stats_count(last_seen_timestamp)? {
22352235
0 => return Ok(vec![]),
22362236
v => v,
22372237
};
@@ -2253,13 +2253,21 @@ impl<'nvml> Device<'nvml> {
22532253
}
22542254
}
22552255

2256-
fn process_utilization_stats_count(&self) -> Result<c_uint, NvmlError> {
2256+
fn process_utilization_stats_count(
2257+
&self,
2258+
last_seen_timestamp: u64,
2259+
) -> Result<c_uint, NvmlError> {
22572260
let sym = nvml_sym(self.nvml.lib.nvmlDeviceGetProcessUtilization.as_ref())?;
22582261

22592262
unsafe {
22602263
let mut count: c_uint = 0;
22612264

2262-
match sym(self.device, ptr::null_mut(), &mut count, 0) {
2265+
match sym(
2266+
self.device,
2267+
ptr::null_mut(),
2268+
&mut count,
2269+
last_seen_timestamp,
2270+
) {
22632271
// Despite being undocumented, this appears to be the correct behavior
22642272
nvmlReturn_enum_NVML_ERROR_INSUFFICIENT_SIZE => Ok(count),
22652273
other => nvml_try(other).map(|_| 0),

0 commit comments

Comments
 (0)