pub struct CounterGroup { /* private fields */ }
Expand description
Counter group.
An event group is scheduled onto the CPU as a unit: it will be put onto the CPU only if all of the events in the group can be put onto the CPU.
This means that the values of the member events can be meaningfully compared, added, divided (to get ratios), and so on with each other, since they have counted events for the same set of executed instructions.
§Examples
use std::thread;
use std::time::Duration;
use perf_event_open::config::{Cpu, Opts, Proc};
use perf_event_open::count::group::CounterGroup;
use perf_event_open::count::Counter;
use perf_event_open::event::hw::Hardware;
let target = (Proc::ALL, Cpu(0)); // All processes on CPU 0.
let mut opts = Opts::default();
opts.stat_format.siblings = true; // Collect sibling counts in leader stat.
let leader = Counter::new(Hardware::Instr, target, opts).unwrap();
let mut group = CounterGroup::from(leader);
group.add(Hardware::CpuCycle, &Default::default()).unwrap();
group.enable().unwrap();
thread::sleep(Duration::from_millis(100));
group.disable().unwrap();
let stat = group.leader().stat().unwrap();
let instrs = stat.count;
let cycles = stat.siblings[0].count;
println!("IPC: {}", instrs as f64 / cycles as f64);
Implementations§
Source§impl CounterGroup
impl CounterGroup
Sourcepub fn siblings(&self) -> &[Rc<Counter>]
pub fn siblings(&self) -> &[Rc<Counter>]
Returns the sibling counters of the counter group in the order they were added.
Sourcepub fn add(
&mut self,
event: impl TryInto<Event, Error = Error>,
opts: impl Borrow<Opts>,
) -> Result<Rc<Counter>>
pub fn add( &mut self, event: impl TryInto<Event, Error = Error>, opts: impl Borrow<Opts>, ) -> Result<Rc<Counter>>
Add sibling event to group.
All siblings share the same target with the group leader.
Sourcepub fn clear_count(&self) -> Result<()>
pub fn clear_count(&self) -> Result<()>
Clears the counts of all counters in the group.
Auto Trait Implementations§
impl !Freeze for CounterGroup
impl !RefUnwindSafe for CounterGroup
impl !Send for CounterGroup
impl !Sync for CounterGroup
impl Unpin for CounterGroup
impl !UnwindSafe for CounterGroup
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more