Skip to content

Commit 20cf6ff

Browse files
authored
Update for 0.15.x, update tracy to 0.12.4 (#9)
1 parent 367f640 commit 20cf6ff

40 files changed

+4413
-1343
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# [ztracy](https://github.com/zig-gamedev/ztracy)
22

3-
Performance markers for [Tracy 0.11.1](https://github.com/wolfpld/tracy) in Zig
3+
Performance markers for [Tracy 0.12.4](https://github.com/wolfpld/tracy) in Zig
44

55
Initial Zig bindings created by [Martin Wickham](https://github.com/SpexGuy/Zig-Tracy)
66

build.zig

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ pub fn build(b: *std.Build) void {
5151
if (options.callstack > 0) {
5252
translate_c.defineCMacro("TRACY_USE_CALLSTACK", "");
5353
var callstack_buffer: [64]u8 = undefined;
54-
const callstack = std.fmt.bufPrintIntToSlice(&callstack_buffer, @as(u32, options.callstack), 10, .lower, .{});
55-
translate_c.defineCMacro("TRACY_CALLSTACK", callstack);
54+
const callstack_str_len = std.fmt.printInt(&callstack_buffer, @as(u32, options.callstack), 10, .lower, .{});
55+
translate_c.defineCMacro("TRACY_CALLSTACK", callstack_buffer[0..callstack_str_len]);
5656
}
5757

5858
const ztracy = b.addModule("root", .{
@@ -63,30 +63,29 @@ pub fn build(b: *std.Build) void {
6363
});
6464
ztracy.addImport("c", translate_c.createModule());
6565

66-
const tracy = if (options.shared) blk: {
67-
const lib = b.addSharedLibrary(.{
68-
.name = "tracy",
66+
const tracy = b.addLibrary(.{
67+
.name = "tracy",
68+
.linkage = if (options.shared) .dynamic else .static,
69+
.root_module = b.createModule(.{
6970
.target = target,
7071
.optimize = optimize,
71-
});
72-
lib.root_module.addCMacro("TRACY_EXPORTS", "");
73-
break :blk lib;
74-
} else b.addStaticLibrary(.{
75-
.name = "tracy",
76-
.target = target,
77-
.optimize = optimize,
72+
}),
7873
});
7974

75+
if (options.shared) {
76+
tracy.root_module.addCMacro("TRACY_EXPORTS", "");
77+
}
78+
8079
tracy.addIncludePath(b.path("libs/tracy/tracy"));
8180
tracy.addCSourceFile(.{
8281
.file = b.path("libs/tracy/TracyClient.cpp"),
8382
.flags = &.{
84-
if (options.enable_ztracy) "-DTRACY_ENABLE" else "",
85-
if (options.enable_fibers) "-DTRACY_FIBERS" else "",
8683
"-fno-sanitize=undefined",
8784
},
8885
});
8986

87+
if (options.enable_ztracy) tracy.root_module.addCMacro("TRACY_ENABLE", "");
88+
if (options.enable_fibers) tracy.root_module.addCMacro("TRACY_FIBERS", "");
9089
if (options.on_demand) tracy.root_module.addCMacro("TRACY_ON_DEMAND", "");
9190

9291
tracy.linkLibC();
@@ -115,9 +114,11 @@ pub fn build(b: *std.Build) void {
115114

116115
const tests = b.addTest(.{
117116
.name = "ztracy-tests",
118-
.root_source_file = b.path("src/ztracy.zig"),
119-
.target = target,
120-
.optimize = optimize,
117+
.root_module = b.createModule(.{
118+
.root_source_file = b.path("src/ztracy.zig"),
119+
.target = target,
120+
.optimize = optimize,
121+
}),
121122
});
122123
tests.linkLibrary(tracy);
123124
b.installArtifact(tests);

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.name = .ztracy,
33
.fingerprint = 0xf803f1f7ab5272cc,
44
.version = "0.14.0-dev",
5-
.minimum_zig_version = "0.14.0",
5+
.minimum_zig_version = "0.15.1",
66
.paths = .{
77
"build.zig",
88
"build.zig.zon",

libs/tracy/TracyClient.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
#include "client/TracyOverride.cpp"
3333
#include "client/TracyKCore.cpp"
3434

35+
#ifdef TRACY_ROCPROF
36+
# include "client/TracyRocprof.cpp"
37+
#endif
38+
3539
#if defined(TRACY_HAS_CALLSTACK)
3640
# if TRACY_HAS_CALLSTACK == 2 || TRACY_HAS_CALLSTACK == 3 || TRACY_HAS_CALLSTACK == 4 || TRACY_HAS_CALLSTACK == 6
3741
# include "libbacktrace/alloc.cpp"

libs/tracy/client/TracyCallstack.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,12 @@ extern "C"
282282
t_SymFromInlineContext _SymFromInlineContext = 0;
283283
t_SymGetLineFromInlineContext _SymGetLineFromInlineContext = 0;
284284

285-
TRACY_API ___tracy_t_RtlWalkFrameChain ___tracy_RtlWalkFrameChain = 0;
285+
typedef unsigned long (__stdcall *___tracy_t_RtlWalkFrameChain)( void**, unsigned long, unsigned long );
286+
___tracy_t_RtlWalkFrameChain ___tracy_RtlWalkFrameChainPtr = nullptr;
287+
TRACY_API unsigned long ___tracy_RtlWalkFrameChain( void** callers, unsigned long count, unsigned long flags)
288+
{
289+
return ___tracy_RtlWalkFrameChainPtr(callers, count, flags);
290+
}
286291
}
287292

288293
struct ModuleCache
@@ -307,7 +312,7 @@ size_t s_krnlCacheCnt;
307312

308313
void InitCallstackCritical()
309314
{
310-
___tracy_RtlWalkFrameChain = (___tracy_t_RtlWalkFrameChain)GetProcAddress( GetModuleHandleA( "ntdll.dll" ), "RtlWalkFrameChain" );
315+
___tracy_RtlWalkFrameChainPtr = (___tracy_t_RtlWalkFrameChain)GetProcAddress( GetModuleHandleA( "ntdll.dll" ), "RtlWalkFrameChain" );
311316
}
312317

313318
void DbgHelpInit()

libs/tracy/client/TracyCallstack.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
# endif
99

1010
# if defined _WIN32
11-
# include "../common/TracyUwp.hpp"
12-
# ifndef TRACY_UWP
11+
# include "../common/TracyWinFamily.hpp"
12+
# if !defined TRACY_WIN32_NO_DESKTOP
1313
# define TRACY_HAS_CALLSTACK 1
1414
# endif
1515
# elif defined __ANDROID__

libs/tracy/client/TracyCallstack.hpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
namespace tracy
1111
{
12-
static tracy_force_inline void* Callstack( int /*depth*/ ) { return nullptr; }
12+
static constexpr bool has_callstack() { return false; }
13+
static tracy_force_inline void* Callstack( int32_t /*depth*/ ) { return nullptr; }
1314
}
1415

1516
#else
@@ -38,6 +39,8 @@ static tracy_force_inline void* Callstack( int /*depth*/ ) { return nullptr; }
3839
namespace tracy
3940
{
4041

42+
static constexpr bool has_callstack() { return true; }
43+
4144
struct CallstackSymbolData
4245
{
4346
const char* file;
@@ -79,11 +82,10 @@ debuginfod_client* GetDebuginfodClient();
7982

8083
extern "C"
8184
{
82-
typedef unsigned long (__stdcall *___tracy_t_RtlWalkFrameChain)( void**, unsigned long, unsigned long );
83-
TRACY_API extern ___tracy_t_RtlWalkFrameChain ___tracy_RtlWalkFrameChain;
85+
TRACY_API unsigned long ___tracy_RtlWalkFrameChain( void**, unsigned long, unsigned long );
8486
}
8587

86-
static tracy_force_inline void* Callstack( int depth )
88+
static tracy_force_inline void* Callstack( int32_t depth )
8789
{
8890
assert( depth >= 1 && depth < 63 );
8991
auto trace = (uintptr_t*)tracy_malloc( ( 1 + depth ) * sizeof( uintptr_t ) );
@@ -112,7 +114,7 @@ static _Unwind_Reason_Code tracy_unwind_callback( struct _Unwind_Context* ctx, v
112114
return _URC_NO_REASON;
113115
}
114116

115-
static tracy_force_inline void* Callstack( int depth )
117+
static tracy_force_inline void* Callstack( int32_t depth )
116118
{
117119
assert( depth >= 1 && depth < 63 );
118120

@@ -127,7 +129,7 @@ static tracy_force_inline void* Callstack( int depth )
127129

128130
#elif TRACY_HAS_CALLSTACK == 3 || TRACY_HAS_CALLSTACK == 4 || TRACY_HAS_CALLSTACK == 6
129131

130-
static tracy_force_inline void* Callstack( int depth )
132+
static tracy_force_inline void* Callstack( int32_t depth )
131133
{
132134
assert( depth >= 1 );
133135

libs/tracy/client/TracyLock.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,9 @@ class Lockable
219219
m_ctx.CustomName( name, size );
220220
}
221221

222-
private:
223222
T m_lockable;
223+
224+
private:
224225
LockableCtx m_ctx;
225226
};
226227

@@ -535,8 +536,9 @@ class SharedLockable
535536
m_ctx.CustomName( name, size );
536537
}
537538

538-
private:
539539
T m_lockable;
540+
541+
private:
540542
SharedLockableCtx m_ctx;
541543
};
542544

0 commit comments

Comments
 (0)