zig-tracer
zig-tracer
Generic tracing library for Zig, supports multiple backends.
Usage
in your program:
const std = @import("std");
const tracer = @import("tracer");
const nfs = @import("nfs");
pub const build_options = @import("build_options");
pub const tracer_impl = tracer.spall; // see 'Backends' section below
pub fn main() !void {
try tracer.init(.{});
defer tracer.deinit();
// main loop
while (true) {
try tracer.init_thread(.{nfs.cwd()});
defer tracer.deinit_thread();
handler();
}
}
fn handler() void {
const t = tracer.trace(@src());
defer t.end();
}
Backends
nonethis is the default and causes tracing calls to become a no-op so thattracercan be added to libraries transparentlylogusesstd.logto print on function entrance.chromewrites a json file in thechrome://tracingformat described here and here.spallwrites a binary file compatible with the Spall profiler.- more? feel free to open an issue with requests!
Any custom backend may also be used that defines the following functions:
pub fn init() !voidpub fn deinit() voidpub fn init_thread(dir: std.fs.Dir) !voidpub fn deinit_thread() voidpub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: anytype) voidpub inline fn trace_end(ctx: tracer.Ctx) void