Struct CounterGroup

Source
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

Source

pub fn from(leader: Counter) -> Self

Create group with leader counter.

Source

pub fn leader(&self) -> &Counter

Returns a reference to the leader of the counter group.

Source

pub fn siblings(&self) -> &[Rc<Counter>]

Returns the sibling counters of the counter group in the order they were added.

Source

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.

Source

pub fn enable(&self) -> Result<()>

Enables all counters in the group.

Source

pub fn disable(&self) -> Result<()>

Disables all counters in the group.

Source

pub fn clear_count(&self) -> Result<()>

Clears the counts of all counters in the group.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.