Performance markers for Tracy Frame Profiler in Zig.
  • C++ 97.1%
  • C 1.5%
  • Zig 1.4%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-10-25 15:52:36 +00:00
.github/workflows upgrade setup-zig 2025-07-20 22:51:45 +01:00
libs/tracy Upgrade to Tracy 0.14.1 (#18) 2026-10-25 15:51:41 +00:00
src Upgrade to zig 0.16.0 (#16) 2026-10-25 15:52:36 +00:00
.gitignore Upgrade to zig 0.16.0 (#16) 2026-10-25 15:52:36 +00:00
build.zig Upgrade to Tracy 0.14.1 (#18) 2026-10-25 15:51:41 +00:00
build.zig.zon Upgrade to zig 0.16.0 (#16) 2026-10-25 15:52:36 +00:00
LICENSE files from monorepo @ bde42aaeec763c1bd8781d26285b0f4dc65b1a4c 2024-11-04 21:45:45 +00:00
README.md Upgrade to Tracy 0.14.1 (#18) 2026-10-25 15:51:41 +00:00

ztracy

Performance markers for Tracy 0.14.1 in Zig

Initial Zig bindings created by Martin Wickham

Getting started

Example build.zig:

pub fn build(b: *std.Build) void {
    const options = .{
        .enable_ztracy = b.option(
            bool,
            "enable_ztracy",
            "Enable Tracy profile markers",
        ) orelse false,
        .enable_fibers = b.option(
            bool,
            "enable_fibers",
            "Enable Tracy fiber support",
        ) orelse false,
        .on_demand = b.option(
            bool,
            "on_demand",
            "Build tracy with TRACY_ON_DEMAND",
        ) orelse false,
    };

    const exe = b.addExecutable(.{ ... });

    const ztracy = b.dependency("ztracy", .{
        .enable_ztracy = options.enable_ztracy,
        .enable_fibers = options.enable_fibers,
        .on_demand = options.on_demand,
    });
    exe.root_module.addImport("ztracy", ztracy.module("root"));
    exe.linkLibrary(ztracy.artifact("tracy"));
}

Now in your code you may import and use ztracy. To build your project with Tracy enabled run:

zig build -Denable_ztracy=true

const ztracy = @import("ztracy");

pub fn main() !void {
    {
        const tracy_zone = ztracy.ZoneNC(@src(), "Compute Magic", 0x00_ff_00_00);
        defer tracy_zone.End();
        ...
    }
}

Async "Fibers" support

Tracy has support for marking fibers (also called green threads, coroutines, and other forms of cooperative multitasking). This support requires an additional option passed through when compiling the Tracy library, so:

    ...
    const optimize = b.standardOptimizeOption(.{});
    const target = b.standardTargetOptions(.{});

    const ztracy_pkg = ztracy.package(b, target, optimize, .{
        .options = .{ .enable_ztracy = true, .enable_fibers = true },
    });

    ztracy_pkg.link(exe);