API reference
Tracy profiler bindings for Zig: zones, plots, messages, and an allocator, compiled out when disabled.
When enable is false, every function here is an inline no-op and the Tracy
client is never fetched, compiled, or linked. When it is true, the module
compiles public/TracyClient.cpp from wolfpld/tracy, and each call emits an
event to the profiler on the other end of the connection.
Adapted from the Zig compiler and ZLS. LICENSE-ZIG carries the MIT notice,
and THIRD_PARTY.md records what changed.
True when events are emitted. Tests force it false, so the suite runs on
the no-op path even in a build with -Denable=true.
pub const enable_allocation = enable and options.enable_allocation
src
True when TracyAllocator reports to the profiler.
pub const enable_callstack = enable and options.enable_callstack
src
True when every zone, message, and allocation carries a callstack.
value
if (enable) ___tracy_c_zone_context else struct {
const Self = @This();
pub inline fn end(self: Self) void {
_ = self;
}
pub inline fn addText(self: Self, text: []const u8) void {
_ = self;
_ = text;
}
pub inline fn setName(self: Self, name: []const u8) void {
_ = self;
_ = name;
}
pub inline fn setColor(self: Self, color: u32) void {
_ = self;
_ = color;
}
pub inline fn setValue(self: Self, value: u64) void {
_ = self;
_ = value;
}
}A zone that is open. end closes it; the other methods attach data to it
until then. When disabled, this is an empty struct and every method is a
no-op, so the same code compiles both ways.
Opens a zone named after the calling function, with the file and line
@src() carries. Pass it as trace(@src()).
pub inline fn traceNamed(comptime src: std.builtin.SourceLocation, comptime name: [:0]const u8) Ctx
src
Like trace, with a name that is already a sentinel-terminated string.
Use it to tell two zones in one function apart.
pub fn tracyAllocator(allocator: Allocator) TracyAllocator(null)
src
Wraps allocator so every allocation, free, and resize appears in the
profiler's memory view. The child keeps no state beyond the parent.
type fn
TracyAllocator
src
pub fn TracyAllocator(comptime name: ?[:0]const u8) type
tracyAllocator with a name, which the memory view uses to group the
allocations apart from the unnamed ones.
Fields
parent_allocator: Allocator
Functions
Writes msg to the profiler's log at severity, in color as 0xRRGGBB.
The string lives in the binary, so the call costs a pointer. Use logCopy
for a string that is not known at comptime.
log for a string the caller builds at run time. The profiler copies the
bytes, so the caller may free them after the call.
Writes msg to the profiler's log at info severity.
pub inline fn messageColor(comptime msg: [:0]const u8, color: u32) void
src
message in a color, as 0xRRGGBB.
pub inline fn messageCopy(msg: []const u8) void
src
message for a string the caller builds at run time.
pub inline fn messageColorCopy(msg: [:0]const u8, color: u32) void
src
messageCopy in a color, as 0xRRGGBB.
pub inline fn setThreadName(name: [*:0]const u8) void
src
Names the calling thread. The profiler copies the bytes.
pub inline fn plotConfig(comptime name: [:0]const u8, plot_type: PlotType, step: bool, fill: bool, color: u32) void
src
Declares a plot's label, unit, and colors. Call it once for a name, before
the first plotInt or plotFloat that uses it.
Adds one point to the integer plot name.
Adds one point to the float plot name.
Adds a line to the profiler's info view. The profiler copies the bytes.
Closes the current frame. Call it once per tick or per rendered frame, from
one thread, or use frameMarkNamed when threads produce separate streams.
pub inline fn frameMarkNamed(comptime name: [:0]const u8) void
src
frameMark on the named stream.
pub inline fn namedFrame(comptime name: [:0]const u8) Frame(name)
src
Opens the named frame and returns a handle whose end closes it, for a
frame that spans a block rather than a point:
more
const frame = tracy.namedFrame("update");
defer frame.end();