Quick Hardware Performance Counters on macOS ARM64
20 hours ago
- #Hardware Counters
- #Performance Monitoring
- #macOS ARM64
- Introduces mperf, a CLI tool for collecting hardware performance counters on Apple Silicon macOS, similar to Linux's perf stat.
- Addresses limitations of Apple's Instruments GUI by providing JSON output for automated benchmarking pipelines and CI.
- Utilizes Apple's private frameworks (kperf.framework and kperfdata.framework) to access performance counters without requiring Xcode or SIP changes.
- Supports up to 10 simultaneous events (2 fixed, 8 configurable) on Apple Silicon, with portable aliases for common metrics like cycles and instructions.
- Uses Profile Every Thread (PET) sampling to measure multi-threaded applications, crucial for OCaml programs with multiple domains.
- Explains accuracy trade-offs: PET-based sampling approximates counts, unlike perf stat's exact counting under certain conditions.
- Includes OCaml bindings for easy integration into benchmarking services, parsing JSON output without external dependencies.
- Compares mperf with Linux perf stat, noting differences in multiplexing and estimating approaches across hardware.
- Provides usage examples for event listing and measurement, with adjustable sampling periods for different benchmark lengths.
- Future plans include porting to x86_64 macOS and integration into OCaml compiler performance tracking pipelines.