A capable 200 lines profiler. It features a very simple API, supports multiple threads and dumps to a profile in the Trace Event Format
- Keep in mind
profile.zig
has hard limits likemax_frames
andmax_threads
, this is done to cap the memory usage, you can increase or decrese them as nescesary to your project. - Use
profile_file.zig
to reduce memory usage and record as many frames as you want, is still limitedmax_threads
- Uses
rdtsc
instruction for better measurements liketracy
, this adds a 200ms startup delay nescessary to peform an initial timer calibration, it's also possible to get anillegal instruction
if you CPU doesn't support it - Inspect traces with Perfetto
const P = if (enable_profiling) @import("profiler.zig") else @import("profiler_mock.zig");
pub fn main() !void {
P.init(.{});
defer {
P.dump("profile.json") catch |err| log.err("profile dump failed: {}", .{err});
P.deinit();
}
const zone = P.begin(@src(), "main_fn");
defer zone.end();
// ... your code
}