Apple Silicon performance-counter access for Rust
darwin-kperf is a Rust crate for reading hardware performance counters on macOS running on Apple Silicon. It provides access to Apple's private kperf and kpc interfaces — the same facilities that power Instruments — so you can configure and sample the CPU's performance-monitoring counters (cycles, retired instructions, cache misses, branch mispredictions, and more) directly from Rust.
It's intended for low-level performance work on Apple Silicon Macs: micro-benchmarking, profiling, and collecting precise hardware metrics that aren't otherwise exposed to user-space code.
The crate is published on crates.io at darwin-kperf.
cargo add darwin-kperf
See the crates.io page for the latest released version.
darwin-kperf targets macOS on Apple Silicon. You select the counters you care about, start sampling, and read the per-counter values back out. For the full API surface — counter configuration, the available counter classes, and the sampling helpers — see the API documentation on docs.rs.
Reading these counters relies on private macOS frameworks and typically requires elevated privileges (for example, running as root). The crate is macOS- and Apple-Silicon-only.