perfcnt/
lib.rs

1//! Example usage:
2//!
3//! ```no_run
4//! use perfcnt::{AbstractPerfCounter, PerfCounter};
5//! use perfcnt::linux::{PerfCounterBuilderLinux, HardwareEventType};
6//!
7//! let mut pc: PerfCounter =
8//!     PerfCounterBuilderLinux::from_hardware_event(HardwareEventType::CacheMisses)
9//!         .finish().expect("Could not create the counter");
10//! pc.start().expect("Can not start the counter");
11//! pc.stop().expect("Can not start the counter");
12//! let res = pc.read().expect("Can not read the counter");
13//! println!("Measured {} cache misses.", res);
14//! ```
15
16pub mod linux;
17pub use crate::linux::PerfCounter;
18
19use std::io;
20
21/// Abstract trait to control performance counters.
22pub trait AbstractPerfCounter {
23    /// Reset performance counter.
24    fn reset(&self) -> Result<(), io::Error>;
25
26    /// Start measuring.
27    fn start(&self) -> Result<(), io::Error>;
28
29    /// Stop measuring.
30    fn stop(&self) -> Result<(), io::Error>;
31
32    /// Read the counter value.
33    fn read(&mut self) -> Result<u64, io::Error>;
34}