Struct perf_event::Counts
source · pub struct Counts { /* private fields */ }
Expand description
A collection of counts from a Group
of counters.
This is the type returned by calling read
on a Group
.
You can index it with a reference to a specific Counter
:
let counts = group.read()?;
println!("cycles / instructions: {} / {} ({:.2} cpi)",
counts[&cycles],
counts[&insns],
(counts[&cycles] as f64 / counts[&insns] as f64));
Or you can iterate over the results it contains:
for (id, value) in &counts {
println!("Counter id {} has value {}", id, value);
}
The id
values produced by this iteration are internal identifiers assigned
by the kernel. You can use the Counter::id
method to find a
specific counter’s id.
For some kinds of events, the kernel may use timesharing to give all
counters access to scarce hardware registers. You can see how long a group
was actually running versus the entire time it was enabled using the
time_enabled
and time_running
methods:
let scale = counts.time_enabled() as f64 /
counts.time_running() as f64;
for (id, value) in &counts {
print!("Counter id {} has value {}",
id, (*value as f64 * scale) as u64);
if scale > 1.0 {
print!(" (estimated)");
}
println!();
}
Implementations
sourceimpl Counts
impl Counts
sourcepub fn time_enabled(&self) -> u64
pub fn time_enabled(&self) -> u64
Return the number of nanoseconds the Group
was enabled that
contributed to this Counts
’ contents.
sourcepub fn time_running(&self) -> u64
pub fn time_running(&self) -> u64
Return the number of nanoseconds the Group
was actually collecting
counts that contributed to this Counts
’ contents.
sourceimpl Counts
impl Counts
sourcepub fn get(&self, member: &Counter) -> Option<&u64>
pub fn get(&self, member: &Counter) -> Option<&u64>
Return the value recorded for member
in self
, or None
if member
is not present.
If you know that member
is in the group, you can simply index:
let cycles = counts[&cycle_counter];
sourcepub fn iter(&self) -> CountsIter<'_>ⓘNotable traits for CountsIter<'c>impl<'c> Iterator for CountsIter<'c> type Item = (u64, &'c u64);
pub fn iter(&self) -> CountsIter<'_>ⓘNotable traits for CountsIter<'c>impl<'c> Iterator for CountsIter<'c> type Item = (u64, &'c u64);
Return an iterator over the counts in self
.
for (id, value) in &counts {
println!("Counter id {} has value {}", id, value);
}
Each item is a pair (id, &value)
, where id
is the number assigned to
the counter by the kernel (see Counter::id
), and value
is that
counter’s value.