Criterion-perf-events

This is a measurement plugin for Criterion.rs to measure events of the Linux perf interface.

Supported Events

Criterion-perf-events uses the perfcnt crate and supports events provided by this crate. If you are interested in more details, please take a look at the events listed here:

Troubleshooting

If you get a "Permission denied" error, update perf_event_paranoid: sudo sh -c 'echo 1 >/proc/sys/kernel/perf_event_paranoid' For further details please take a look at the following link.

Example

The following code shows how to count retired instructions.

```rust use criterion::{criteriongroup, criterionmain, BenchmarkId, blackbox, Criterion}; use criterionperf_events::Perf; use perfcnt::linux::HardwareEventType as Hardware; use perfcnt::linux::PerfCounterBuilderLinux as Builder;

fn fibonaccislow(n: usize) -> usize { match n { 0 => 1, 1 => 1, n => fibonaccislow(n - 1) + fibonacci_slow(n - 2), } }

fn bench(c: &mut Criterion) { let mut group = c.benchmark_group("fibonacci");

let fibo_arg = 30;
group.bench_function(BenchmarkId::new("slow", fibo_arg), |b| {
    b.iter(|| fibonacci_slow(black_box(fibo_arg)))
});

group.finish()

}

criteriongroup!( name = instructionsbench; config = Criterion::default().withmeasurement(Perf::new(Builder::fromhardwareevent(Hardware::Instructions))); targets = bench ); criterionmain!(instructions_bench); ```

run with: cargo criterion Open target/criterion/reports/index.html to view detailed results with plots. For all event types (Hardware::Instructions, Hardware::CacheMisses...) criterion will always report cycles as the unit. Note that your event type is what is being shown, not CPU cycles.