pub struct Counter { /* private fields */ }
Expand description
An allocated PMC counter.
Counters are initialised using the CounterBuilder
type.
use std::{thread, time::Duration};
use pmc::*;
let mut instr = CounterBuilder::default()
.attach_to(vec![0])
.allocate("inst_retired.any")?;
let handle = instr.start()?;
// Stop the counter after 5 seconds
thread::sleep(Duration::from_secs(5));
handle.stop();
println!("instructions: {}", instr.read()?);
Implementations§
source§impl Counter
impl Counter
sourcepub fn start(&mut self) -> Result<Running<'_>, Error>
pub fn start(&mut self) -> Result<Running<'_>, Error>
Start this counter.
The counter stops when the returned Running
handle is dropped.
sourcepub fn read(&self) -> Result<u64, Error>
pub fn read(&self) -> Result<u64, Error>
Read the counter value.
This call is valid for both running, stopped, and unused counters.
use pmc::*;
let mut counter = CounterBuilder::default()
.attach_to(vec![0])
.allocate("inst_retired.any")?;
let r1 = counter.read()?;
let r2 = counter.read()?;
// A counter that is not running does not advance
assert!(r2 == r1);
sourcepub fn set(&mut self, value: u64) -> Result<u64, Error>
pub fn set(&mut self, value: u64) -> Result<u64, Error>
Set an explicit counter value.
use pmc::*;
let mut counter = CounterBuilder::default()
.attach_to(vec![0])
.allocate("inst_retired.any")?;
let r1 = counter.set(42)?;
// The previous value is returned when setting a new value
assert_eq!(r1, 0);
// Reading the counter returns the value set
let r2 = counter.read()?;
assert_eq!(r2, 42);
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Counter
impl Send for Counter
impl Sync for Counter
impl Unpin for Counter
impl UnwindSafe for Counter
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