Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

samples: Only return samples that are actually valid. #67

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions nvml-wrapper/src/device.rs
Original file line number Diff line number Diff line change
@@ -2606,24 +2606,26 @@ impl<'nvml> Device<'nvml> {

unsafe {
let mut val_type: nvmlValueType_t = mem::zeroed();
let mut count = match self.samples_count(&sample_type, timestamp)? {
let count = match self.samples_count(&sample_type, timestamp)? {
0 => return Ok(vec![]),
value => value,
};
let mut samples: Vec<nvmlSample_t> = vec![mem::zeroed(); count as usize];
let mut new_count = count;

nvml_try(sym(
self.device,
sample_type.as_c(),
timestamp,
&mut val_type,
&mut count,
&mut new_count,
samples.as_mut_ptr(),
))?;

let val_type_rust = SampleValueType::try_from(val_type)?;
Ok(samples
.into_iter()
.take(new_count as usize)
.map(|s| Sample::from_tag_and_struct(&val_type_rust, s))
.collect())
}