[−][src]Struct perf_event::Group
A group of counters that can be managed as a unit.
A Group
represents a group of Counter
s that can be enabled,
disabled, reset, or read as a single atomic operation. This is necessary if
you want to compare counter values, produce ratios, and so on, since those
operations are only meaningful on counters that cover exactly the same
period of execution.
A Counter
is placed in a group when it is created, by calling the
Builder
's group
method. A Group
's read
method returns values
of all its member counters at once as a Counts
value, which can be
indexed by Counter
to retrieve a specific value.
For example, the following program computes the average number of cycles
used per instruction retired for a call to println!
:
use perf_event::{Builder, Group}; use perf_event::events::Hardware; let mut group = Group::new()?; let cycles = Builder::new().group(&group).kind(Hardware::CPU_CYCLES).build()?; let insns = Builder::new().group(&group).kind(Hardware::INSTRUCTIONS).build()?; let vec = (0..=51).collect::<Vec<_>>(); group.enable()?; println!("{:?}", vec); group.disable()?; let counts = group.read()?; println!("cycles / instructions: {} / {} ({:.2} cpi)", counts[&cycles], counts[&insns], (counts[&cycles] as f64 / counts[&insns] as f64));
The lifetimes of Counter
s and Group
s are independent: placing a
Counter
in a Group
does not take ownership of the Counter
, nor must
the Counter
s in a group outlive the Group
. If a Counter
is dropped, it
is simply removed from its Group
, and omitted from future results. If a
Group
is dropped, its individual counters continue to count.
Enabling or disabling a Group
affects each Counter
that belongs to it.
Subsequent reads from the Counter
will not reflect activity while the
Group
was disabled, unless the Counter
is re-enabled individually.
A Group
and its members must all observe the same tasks and cpus; mixing
these makes building the Counter
xreturn an error. Unfortunately, there is
no way at present to specify a Group
s task and cpu, so you can only use
Group
on the calling task.
Methods
impl Group
[src]
pub fn new() -> Result<Group>
[src]
Construct a new, empty Group
.
pub fn enable(&mut self) -> Result<()>
[src]
Allow all Counter
s in this Group
to begin counting their designated
events, as a single atomic operation.
This does not affect whatever values the Counter
s had previously; new
events add to the current counts. To clear the Counter
s, use the
reset
method.
pub fn disable(&mut self) -> Result<()>
[src]
Make all Counter
s in this Group
stop counting their designated
events, as a single atomic operation. Their counts are unaffected.
pub fn reset(&mut self) -> Result<()>
[src]
Reset all Counter
s in this Group
to zero, as a single atomic operation.
pub fn read(&mut self) -> Result<Counts>
[src]
Return the values of all the Counter
s in this Group
as a Counts
value.
A Counts
value is a map from specific Counter
s to their values. You
can find a specific Counter
's value by indexing:
let mut group = Group::new()?; let counter1 = Builder::new().group(&group).kind(...).build()?; let counter2 = Builder::new().group(&group).kind(...).build()?; ... let counts = group.read()?; println!("Rhombus inclinations per taxi medallion: {} / {} ({:.0}%)", counts[&counter1], counts[&counter2], (counts[&counter1] as f64 / counts[&counter2] as f64) * 100.0);
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Group
impl Send for Group
impl Sync for Group
impl Unpin for Group
impl UnwindSafe for Group
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,