Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# [ztracy](https://github.com/zig-gamedev/ztracy)

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

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

Expand Down
35 changes: 18 additions & 17 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ pub fn build(b: *std.Build) void {
if (options.callstack > 0) {
translate_c.defineCMacro("TRACY_USE_CALLSTACK", "");
var callstack_buffer: [64]u8 = undefined;
const callstack = std.fmt.bufPrintIntToSlice(&callstack_buffer, @as(u32, options.callstack), 10, .lower, .{});
translate_c.defineCMacro("TRACY_CALLSTACK", callstack);
const callstack_str_len = std.fmt.printInt(&callstack_buffer, @as(u32, options.callstack), 10, .lower, .{});
translate_c.defineCMacro("TRACY_CALLSTACK", callstack_buffer[0..callstack_str_len]);
}

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

const tracy = if (options.shared) blk: {
const lib = b.addSharedLibrary(.{
.name = "tracy",
const tracy = b.addLibrary(.{
.name = "tracy",
.linkage = if (options.shared) .dynamic else .static,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
});
lib.root_module.addCMacro("TRACY_EXPORTS", "");
break :blk lib;
} else b.addStaticLibrary(.{
.name = "tracy",
.target = target,
.optimize = optimize,
}),
});

if (options.shared) {
tracy.root_module.addCMacro("TRACY_EXPORTS", "");
}

tracy.addIncludePath(b.path("libs/tracy/tracy"));
tracy.addCSourceFile(.{
.file = b.path("libs/tracy/TracyClient.cpp"),
.flags = &.{
if (options.enable_ztracy) "-DTRACY_ENABLE" else "",
if (options.enable_fibers) "-DTRACY_FIBERS" else "",
"-fno-sanitize=undefined",
},
});

if (options.enable_ztracy) tracy.root_module.addCMacro("TRACY_ENABLE", "");
if (options.enable_fibers) tracy.root_module.addCMacro("TRACY_FIBERS", "");
if (options.on_demand) tracy.root_module.addCMacro("TRACY_ON_DEMAND", "");

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

const tests = b.addTest(.{
.name = "ztracy-tests",
.root_source_file = b.path("src/ztracy.zig"),
.target = target,
.optimize = optimize,
.root_module = b.createModule(.{
.root_source_file = b.path("src/ztracy.zig"),
.target = target,
.optimize = optimize,
}),
});
tests.linkLibrary(tracy);
b.installArtifact(tests);
Expand Down
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.name = .ztracy,
.fingerprint = 0xf803f1f7ab5272cc,
.version = "0.14.0-dev",
.minimum_zig_version = "0.14.0",
.minimum_zig_version = "0.15.1",
.paths = .{
"build.zig",
"build.zig.zon",
Expand Down
4 changes: 4 additions & 0 deletions libs/tracy/TracyClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
#include "client/TracyOverride.cpp"
#include "client/TracyKCore.cpp"

#ifdef TRACY_ROCPROF
# include "client/TracyRocprof.cpp"
#endif

#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"
Expand Down
9 changes: 7 additions & 2 deletions libs/tracy/client/TracyCallstack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,12 @@ extern "C"
t_SymFromInlineContext _SymFromInlineContext = 0;
t_SymGetLineFromInlineContext _SymGetLineFromInlineContext = 0;

TRACY_API ___tracy_t_RtlWalkFrameChain ___tracy_RtlWalkFrameChain = 0;
typedef unsigned long (__stdcall *___tracy_t_RtlWalkFrameChain)( void**, unsigned long, unsigned long );
___tracy_t_RtlWalkFrameChain ___tracy_RtlWalkFrameChainPtr = nullptr;
TRACY_API unsigned long ___tracy_RtlWalkFrameChain( void** callers, unsigned long count, unsigned long flags)
{
return ___tracy_RtlWalkFrameChainPtr(callers, count, flags);
}
}

struct ModuleCache
Expand All @@ -307,7 +312,7 @@ size_t s_krnlCacheCnt;

void InitCallstackCritical()
{
___tracy_RtlWalkFrameChain = (___tracy_t_RtlWalkFrameChain)GetProcAddress( GetModuleHandleA( "ntdll.dll" ), "RtlWalkFrameChain" );
___tracy_RtlWalkFrameChainPtr = (___tracy_t_RtlWalkFrameChain)GetProcAddress( GetModuleHandleA( "ntdll.dll" ), "RtlWalkFrameChain" );
}

void DbgHelpInit()
Expand Down
4 changes: 2 additions & 2 deletions libs/tracy/client/TracyCallstack.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
# endif

# if defined _WIN32
# include "../common/TracyUwp.hpp"
# ifndef TRACY_UWP
# include "../common/TracyWinFamily.hpp"
# if !defined TRACY_WIN32_NO_DESKTOP
# define TRACY_HAS_CALLSTACK 1
# endif
# elif defined __ANDROID__
Expand Down
14 changes: 8 additions & 6 deletions libs/tracy/client/TracyCallstack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

namespace tracy
{
static tracy_force_inline void* Callstack( int /*depth*/ ) { return nullptr; }
static constexpr bool has_callstack() { return false; }
static tracy_force_inline void* Callstack( int32_t /*depth*/ ) { return nullptr; }
}

#else
Expand Down Expand Up @@ -38,6 +39,8 @@ static tracy_force_inline void* Callstack( int /*depth*/ ) { return nullptr; }
namespace tracy
{

static constexpr bool has_callstack() { return true; }

struct CallstackSymbolData
{
const char* file;
Expand Down Expand Up @@ -79,11 +82,10 @@ debuginfod_client* GetDebuginfodClient();

extern "C"
{
typedef unsigned long (__stdcall *___tracy_t_RtlWalkFrameChain)( void**, unsigned long, unsigned long );
TRACY_API extern ___tracy_t_RtlWalkFrameChain ___tracy_RtlWalkFrameChain;
TRACY_API unsigned long ___tracy_RtlWalkFrameChain( void**, unsigned long, unsigned long );
}

static tracy_force_inline void* Callstack( int depth )
static tracy_force_inline void* Callstack( int32_t depth )
{
assert( depth >= 1 && depth < 63 );
auto trace = (uintptr_t*)tracy_malloc( ( 1 + depth ) * sizeof( uintptr_t ) );
Expand Down Expand Up @@ -112,7 +114,7 @@ static _Unwind_Reason_Code tracy_unwind_callback( struct _Unwind_Context* ctx, v
return _URC_NO_REASON;
}

static tracy_force_inline void* Callstack( int depth )
static tracy_force_inline void* Callstack( int32_t depth )
{
assert( depth >= 1 && depth < 63 );

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

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

static tracy_force_inline void* Callstack( int depth )
static tracy_force_inline void* Callstack( int32_t depth )
{
assert( depth >= 1 );

Expand Down
6 changes: 4 additions & 2 deletions libs/tracy/client/TracyLock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,9 @@ class Lockable
m_ctx.CustomName( name, size );
}

private:
T m_lockable;

private:
LockableCtx m_ctx;
};

Expand Down Expand Up @@ -535,8 +536,9 @@ class SharedLockable
m_ctx.CustomName( name, size );
}

private:
T m_lockable;

private:
SharedLockableCtx m_ctx;
};

Expand Down
Loading
Loading