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

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.