If you’re a developer rocking an Apple Silicon Mac and writing in Zig, congratulations - you’ve chosen the scenic route through the desert of profiling tools. It’s just you, your code, and a tumbleweed named Apple Instruments. But don’t worry - we’ll try to find some oases. Okay, it’s not that bad, but we’re far away from the rich ecosystem of profiling tools available on Linux. Note: I have limited experience using low-level languages, so this article doesn’t provide a deep dive into profiling, but rather serves as an entry point to the world of profiling. Classification# We focus only on these types of profilers: There are many other types of profilers, like memory profilers, network profilers, etc., but we won’t cover them here. Many profilers combine methods from both categories. For Linux, we have perf, valgrind, and tracy. These tools cover almost all possible cases. Sadly, that’s not true for Apple Silicon Macs: perf - supports only Linux as it relies on the Linux kernel. valgrind - doesn’t support macOS on arm64. tracy - mostly works, but callstack sampling is not supported. Interfaces# Apple provides several interfaces for profiling: Mach Interface - provides access to threads, address spaces, memory objects, and IPC primitives. DTrace Framework - similar to Mach, but requires root privileges and disabling System Integrity Protection (SIP) for profiling system apps. kperf - private framework, Apple’s alternative to Linux perf. Samply is a sampling profiler that collects stack traces, per thread, at a specified sampling interval (default: 1ms or 1000Hz). Both on- and off-CPU samples are collected. It relies on the Mach Interface to collect samples and uses the Firefox Profiler as its UI. Features: Sampling executables or already running processes Feature-rich UI: call tree, flamegraph, source code, CPU usage Install: # using cargo cargo install --locked samply # homebrew brew install samply Usage: # fresh start samply record <command> # pid (requires signing...
First seen: 2025-07-31 14:59
Last seen: 2025-08-01 04:03