Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ jobs:
build:
strategy:
matrix:
zig-version: [0.14.1]
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Zig
uses: mlugg/setup-zig@v2
with:
version: 0.16.0-dev.2368+380ea6fb5
- name: Run build
run: zig build
working-directory: ./example
working-directory: ./example
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# zig-tracy

Library for instrumenting zig code for [Tracy 0.12.2](https://github.com/wolfpld/tracy).
Library for instrumenting zig code for [Tracy 0.13.1](https://github.com/wolfpld/tracy).

## how to use

1. Add `tracy` to the dependency list in `build.zig.zon`:
1. Add `tracy` to the dependency list in `build.zig.zon`:

```sh
zig fetch --save git+https://github.com/johan0A/zig-tracy
Expand Down Expand Up @@ -34,4 +34,4 @@ fn baz() void {
}
```

see more in depth example in the example folder.
see more in depth example in the example directory.
10 changes: 5 additions & 5 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ pub fn build(b: *std.Build) !void {
}),
});

tracy.addIncludePath(b.path("vendor/tracy/tracy"));
tracy.addCSourceFile(.{
tracy.root_module.addIncludePath(b.path("vendor/tracy/tracy"));
tracy.root_module.addCSourceFile(.{
.file = b.path("vendor/tracy/TracyClient.cpp"),
.flags = &.{"-fno-sanitize=undefined"},
});
Expand All @@ -65,14 +65,14 @@ pub fn build(b: *std.Build) !void {
if (options.on_demand) tracy.root_module.addCMacro("TRACY_ON_DEMAND", "");

if (target.result.abi != .msvc) {
tracy.linkLibCpp();
tracy.root_module.link_libcpp = true;
} else {
tracy.root_module.addCMacro("fileno", "_fileno");
}

if (target.result.os.tag == .windows) {
tracy.linkSystemLibrary("ws2_32");
tracy.linkSystemLibrary("dbghelp");
tracy.root_module.linkSystemLibrary("ws2_32", .{});
tracy.root_module.linkSystemLibrary("dbghelp", .{});
}

root_module.linkLibrary(tracy);
Expand Down
4 changes: 2 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.{
.name = .tracy,
.version = "0.11.1",
.version = "0.12.0",
.fingerprint = 0x255a89ee6affc16e, // Changing this has security and trust implications.
.minimum_zig_version = "0.14.0",
.minimum_zig_version = "0.15.2",
.dependencies = .{},
.paths = .{
"src",
Expand Down
2 changes: 1 addition & 1 deletion example/build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.name = .example,
.version = "0.0.0",
.fingerprint = 0x6eec9b9f1ee586b1, // Changing this has security and trust implications.
.minimum_zig_version = "0.14.0",
.minimum_zig_version = "0.16.0-dev.2368+380ea6fb5",
.dependencies = .{
.tracy = .{
.path = "../",
Expand Down
32 changes: 15 additions & 17 deletions example/src/main.zig
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
const std = @import("std");
const tracy = @import("tracy");

fn foo() void {
fn foo(io: std.Io) void {
const zone = tracy.zone(@src());
defer zone.end();
std.Thread.sleep(std.time.ns_per_ms);
io.sleep(.fromMilliseconds(1), .awake) catch unreachable;
}

fn bar() void {
fn bar(io: std.Io) void {
const zone = tracy.zone(@src());
defer zone.end();
foo();
foo(io);
tracy.message("foo message!", .{});
foo();
foo();
foo(io);
foo(io);
}

fn baz() void {
fn baz(io: std.Io) void {
const zone = tracy.zone(@src());
defer zone.end();
foo();
bar();
foo(io);
bar(io);
}

fn qux(alloc: std.mem.Allocator) !void {
fn qux(io: std.Io, alloc: std.mem.Allocator) !void {
var list: std.ArrayListUnmanaged(u8) = .empty;
for (0..1e6) |_| {
try list.appendSlice(alloc, "hello");
Expand All @@ -35,17 +35,15 @@ fn qux(alloc: std.mem.Allocator) !void {

const zone = tracy.zone(@src());
defer zone.end();
baz();
baz(io);
const frame_name = "foo frame";
tracy.frameMarkStart(frame_name);
defer tracy.frameMarkEnd(frame_name);
foo();
foo(io);
}

pub fn main() !void {
var gpa: std.heap.DebugAllocator(.{}) = .init;
defer _ = gpa.deinit();
var tracy_allocator = tracy.TracyAllocator.init(gpa.allocator(), "foo allocator");
pub fn main(init: std.process.Init) !void {
var tracy_allocator = tracy.TracyAllocator.init(init.gpa, "foo allocator");
const alloc: std.mem.Allocator = tracy_allocator.allocator();

tracy.appInfo("foo app info");
Expand All @@ -55,7 +53,7 @@ pub fn main() !void {
var it: u64 = 0;
while (true) : (it += 1) {
tracy.plot("plot foo", std.math.sin(@as(f64, @floatFromInt(it)) / 2) + 1);
try qux(alloc);
try qux(init.io, alloc);

tracy.setFrameImage(image.ptr, 100, 100, 0, false);
for (0..100) |x| {
Expand Down
20 changes: 2 additions & 18 deletions vendor/tracy/TracyClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,11 @@
#include "client/TracyOverride.cpp"
#include "client/TracyKCore.cpp"

#if defined(TRACY_HAS_CALLSTACK)
# if TRACY_HAS_CALLSTACK == 2 || TRACY_HAS_CALLSTACK == 3 || TRACY_HAS_CALLSTACK == 4 || TRACY_HAS_CALLSTACK == 6
# include "libbacktrace/alloc.cpp"
# include "libbacktrace/dwarf.cpp"
# include "libbacktrace/fileline.cpp"
# include "libbacktrace/mmapio.cpp"
# include "libbacktrace/posix.cpp"
# include "libbacktrace/sort.cpp"
# include "libbacktrace/state.cpp"
# if TRACY_HAS_CALLSTACK == 4
# include "libbacktrace/macho.cpp"
# else
# include "libbacktrace/elf.cpp"
# endif
# include "common/TracyStackFrames.cpp"
# endif
#ifdef TRACY_ROCPROF
# include "client/TracyRocprof.cpp"
#endif

#ifdef _MSC_VER
# pragma comment(lib, "ws2_32.lib")
# pragma comment(lib, "dbghelp.lib")
# pragma comment(lib, "advapi32.lib")
# pragma comment(lib, "user32.lib")
# pragma warning(pop)
Expand Down
Loading