Skip to content

Instantly share code, notes, and snippets.

@nico
nico / kpc_demo.c
Created April 20, 2023 15:06 — forked from ibireme/kpc_demo.c
A demo shows how to read Intel or Apple M1 CPU performance counter in macOS.
// =============================================================================
// XNU kperf/kpc demo
// Available for 64-bit Intel/Apple Silicon, macOS/iOS, with root privileges
//
//
// Demo 1 (profile a function in current thread):
// 1. Open directory '/usr/share/kpep/', find your CPU PMC database.
// For M1 (Pro/Max), the database file is '/usr/share/kpep/a14.plist'.
// 2. Select a few events that you are interested in,
// add their names to the `profile_events` array below.