Announcing perf-event 0.4.1

I've just published perf-event 0.4.1, a crate for accessing performance counters under Linux. You can observe instruction retirement, cache misses, context switches, and things like that.

For example, this lets us see how many instructions a call to println! entails:

use perf_event::Builder;

fn main() -> std::io::Result<()> {
    let mut counter = Builder::new().build()?;

    let vec = (0..=51).collect::<Vec<_>>();

    counter.enable()?;
    println!("{:?}", vec);
    counter.disable()?;

    println!("{} instructions retired", counter.read()?);

    Ok(())
}

The crate has documentation and an examples directory.

If you try it out, please file issues for whatever problems you run into. Thanks!

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.