tracy API reference Changelog View on GitHub

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.

pub const enable = if (builtin.is_test) false else options.enable

src

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.

pub const Ctx = …

src
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.

pub inline fn trace(comptime src: std.builtin.SourceLocation) Ctx

src

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

pub fn init(parent_allocator: Allocator) Self

src

pub fn allocator(self: *Self) Allocator

src

enum Severity

src
pub const Severity = enum(i8)

The severity the profiler's log view groups a message under.

Fields

trace trace = 0
debug debug = 1
info info = 2
warning warning = 3
err err = 4
fatal fatal = 5

pub inline fn log(comptime severity: Severity, comptime msg: [:0]const u8, color: u32) void

src

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.

pub inline fn logCopy(comptime severity: Severity, msg: []const u8, color: u32) void

src

log for a string the caller builds at run time. The profiler copies the bytes, so the caller may free them after the call.

pub inline fn message(comptime msg: [:0]const u8) void

src

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.

enum PlotType

src
pub const PlotType = enum(c_int)

Fields

number number = 0
memory memory = 1
percentage percentage = 2
watt watt = 3

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.

pub inline fn plotInt(comptime name: [:0]const u8, value: i64) void

src

Adds one point to the integer plot name.

pub inline fn plotFloat(comptime name: [:0]const u8, value: f64) void

src

Adds one point to the float plot name.

pub inline fn appInfo(text: []const u8) void

src

Adds a line to the profiler's info view. The profiler copies the bytes.

pub inline fn frameMark() void

src

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();

type fn Frame

src
pub fn Frame(comptime name: [:0]const u8) type

Functions

pub fn end(_: Self) void

src