Struct pmc::Counter [−][src]
pub struct Counter { /* fields omitted */ }
Expand description
An allocated PMC counter.
Counters are initialised using the CounterBuilder
type.
use std::{thread, time::Duration}; let instr = CounterConfig::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
Start this counter.
The counter stops when the returned Running
handle is dropped.
Read the counter value.
This call is valid for both running, stopped, and unused counters.
let mut counter = CounterConfig::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);
Set an explicit counter value.
let mut counter = CounterConfig::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 UnwindSafe for Counter