diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-10-31 17:55:29 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-31 17:55:29 -0400 |
| commit | 8346e011c9ecbd7d462f0948d2e9dfc7e4067482 (patch) | |
| tree | 65b594fbf4e9a1df9e9d3c3006897ff7fd7b92ea /src | |
| parent | 91d93b6395bf4a5718cffe18d4a9351b2ff06492 (diff) | |
| parent | 2d1efba8c51327a37ac5fe13dda252b362dc467f (diff) | |
| download | zig-8346e011c9ecbd7d462f0948d2e9dfc7e4067482.tar.gz zig-8346e011c9ecbd7d462f0948d2e9dfc7e4067482.zip | |
Merge pull request #10068 from leecannon/tracy_improvements
stage2: tracy integration improvements
Diffstat (limited to 'src')
| -rw-r--r-- | src/Compilation.zig | 121 | ||||
| -rw-r--r-- | src/main.zig | 10 | ||||
| -rw-r--r-- | src/tracy.zig | 312 |
3 files changed, 401 insertions, 42 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index 719daabbaa..48d422fad2 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -13,7 +13,8 @@ const Type = @import("type.zig").Type; const target_util = @import("target.zig"); const Package = @import("Package.zig"); const link = @import("link.zig"); -const trace = @import("tracy.zig").trace; +const tracy = @import("tracy.zig"); +const trace = tracy.trace; const Liveness = @import("Liveness.zig"); const build_options = @import("build_options"); const LibCInstallation = @import("libc_installation.zig").LibCInstallation; @@ -1726,8 +1727,8 @@ pub fn getTarget(self: Compilation) Target { /// Detect changes to source files, perform semantic analysis, and update the output files. pub fn update(self: *Compilation) !void { - const tracy = trace(@src()); - defer tracy.end(); + const t = trace(@src()); + defer t.end(); self.clearMiscFailures(); @@ -2111,6 +2112,9 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor defer self.work_queue_wait_group.wait(); { + const astgen_frame = tracy.namedFrame("astgen"); + defer astgen_frame.end(); + self.astgen_wait_group.reset(); defer self.astgen_wait_group.wait(); @@ -2138,6 +2142,9 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor const use_stage1 = build_options.is_stage1 and self.bin_file.options.use_stage1; if (!use_stage1) { + const outdated_and_deleted_decls_frame = tracy.namedFrame("outdated_and_deleted_decls"); + defer outdated_and_deleted_decls_frame.end(); + // Iterate over all the files and look for outdated and deleted declarations. if (self.bin_file.options.module) |mod| { try mod.processOutdatedAndDeletedDecls(); @@ -2181,6 +2188,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress => return, .complete, .codegen_failure_retryable => { + const named_frame = tracy.namedFrame("codegen_decl"); + defer named_frame.end(); + if (build_options.omit_stage2) @panic("sadly stage2 is omitted from this build to save memory on the CI server"); @@ -2230,6 +2240,10 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress defer tmp_arena.deinit(); const sema_arena = &tmp_arena.allocator; + const sema_frame = tracy.namedFrame("sema"); + var sema_frame_ended = false; + errdefer if (!sema_frame_ended) sema_frame.end(); + var air = module.analyzeFnBody(decl, func, sema_arena) catch |err| switch (err) { error.AnalysisFail => { assert(func.state != .in_progress); @@ -2239,16 +2253,29 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress }; defer air.deinit(gpa); + sema_frame.end(); + sema_frame_ended = true; + + const liveness_frame = tracy.namedFrame("liveness"); + var liveness_frame_ended = false; + errdefer if (!liveness_frame_ended) liveness_frame.end(); + log.debug("analyze liveness of {s}", .{decl.name}); var liveness = try Liveness.analyze(gpa, air, decl.getFileScope().zir); defer liveness.deinit(gpa); + liveness_frame.end(); + liveness_frame_ended = true; + if (builtin.mode == .Debug and comp.verbose_air) { std.debug.print("# Begin Function AIR: {s}:\n", .{decl.name}); @import("print_air.zig").dump(gpa, air, decl.getFileScope().zir, liveness); std.debug.print("# End Function AIR: {s}\n\n", .{decl.name}); } + const named_frame = tracy.namedFrame("codegen"); + defer named_frame.end(); + comp.bin_file.updateFunc(module, func, air, liveness) catch |err| switch (err) { error.OutOfMemory => return error.OutOfMemory, error.AnalysisFail => { @@ -2284,6 +2311,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress // emit-h only requires semantic analysis of the Decl to be complete, // it does not depend on machine code generation to succeed. .codegen_failure, .codegen_failure_retryable, .complete => { + const named_frame = tracy.namedFrame("emit_h_decl"); + defer named_frame.end(); + if (build_options.omit_stage2) @panic("sadly stage2 is omitted from this build to save memory on the CI server"); const gpa = comp.gpa; @@ -2321,6 +2351,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress }, }, .analyze_decl => |decl| { + const named_frame = tracy.namedFrame("analyze_decl"); + defer named_frame.end(); + if (build_options.omit_stage2) @panic("sadly stage2 is omitted from this build to save memory on the CI server"); const module = comp.bin_file.options.module.?; @@ -2330,6 +2363,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress }; }, .update_embed_file => |embed_file| { + const named_frame = tracy.namedFrame("update_embed_file"); + defer named_frame.end(); + if (build_options.omit_stage2) @panic("sadly stage2 is omitted from this build to save memory on the CI server"); const module = comp.bin_file.options.module.?; @@ -2339,6 +2375,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress }; }, .update_line_number => |decl| { + const named_frame = tracy.namedFrame("update_line_number"); + defer named_frame.end(); + if (build_options.omit_stage2) @panic("sadly stage2 is omitted from this build to save memory on the CI server"); const gpa = comp.gpa; @@ -2355,6 +2394,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress }; }, .analyze_pkg => |pkg| { + const named_frame = tracy.namedFrame("analyze_pkg"); + defer named_frame.end(); + if (build_options.omit_stage2) @panic("sadly stage2 is omitted from this build to save memory on the CI server"); const module = comp.bin_file.options.module.?; @@ -2371,6 +2413,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress }; }, .glibc_crt_file => |crt_file| { + const named_frame = tracy.namedFrame("glibc_crt_file"); + defer named_frame.end(); + glibc.buildCRTFile(comp, crt_file) catch |err| { // TODO Surface more error details. try comp.setMiscFailure(.glibc_crt_file, "unable to build glibc CRT file: {s}", .{ @@ -2379,6 +2424,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress }; }, .glibc_shared_objects => { + const named_frame = tracy.namedFrame("glibc_shared_objects"); + defer named_frame.end(); + glibc.buildSharedObjects(comp) catch |err| { // TODO Surface more error details. try comp.setMiscFailure( @@ -2389,6 +2437,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress }; }, .musl_crt_file => |crt_file| { + const named_frame = tracy.namedFrame("musl_crt_file"); + defer named_frame.end(); + musl.buildCRTFile(comp, crt_file) catch |err| { // TODO Surface more error details. try comp.setMiscFailure( @@ -2399,6 +2450,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress }; }, .mingw_crt_file => |crt_file| { + const named_frame = tracy.namedFrame("mingw_crt_file"); + defer named_frame.end(); + mingw.buildCRTFile(comp, crt_file) catch |err| { // TODO Surface more error details. try comp.setMiscFailure( @@ -2409,6 +2463,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress }; }, .windows_import_lib => |index| { + const named_frame = tracy.namedFrame("windows_import_lib"); + defer named_frame.end(); + const link_lib = comp.bin_file.options.system_libs.keys()[index]; mingw.buildImportLib(comp, link_lib) catch |err| { // TODO Surface more error details. @@ -2420,6 +2477,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress }; }, .libunwind => { + const named_frame = tracy.namedFrame("libunwind"); + defer named_frame.end(); + libunwind.buildStaticLib(comp) catch |err| { // TODO Surface more error details. try comp.setMiscFailure( @@ -2430,6 +2490,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress }; }, .libcxx => { + const named_frame = tracy.namedFrame("libcxx"); + defer named_frame.end(); + libcxx.buildLibCXX(comp) catch |err| { // TODO Surface more error details. try comp.setMiscFailure( @@ -2440,6 +2503,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress }; }, .libcxxabi => { + const named_frame = tracy.namedFrame("libcxxabi"); + defer named_frame.end(); + libcxx.buildLibCXXABI(comp) catch |err| { // TODO Surface more error details. try comp.setMiscFailure( @@ -2450,6 +2516,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress }; }, .libtsan => { + const named_frame = tracy.namedFrame("libtsan"); + defer named_frame.end(); + libtsan.buildTsan(comp) catch |err| { // TODO Surface more error details. try comp.setMiscFailure( @@ -2460,6 +2529,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress }; }, .wasi_libc_crt_file => |crt_file| { + const named_frame = tracy.namedFrame("wasi_libc_crt_file"); + defer named_frame.end(); + wasi_libc.buildCRTFile(comp, crt_file) catch |err| { // TODO Surface more error details. try comp.setMiscFailure( @@ -2470,6 +2542,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress }; }, .compiler_rt_lib => { + const named_frame = tracy.namedFrame("compiler_rt_lib"); + defer named_frame.end(); + comp.buildOutputFromZig( "compiler_rt.zig", .Lib, @@ -2486,6 +2561,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress }; }, .compiler_rt_obj => { + const named_frame = tracy.namedFrame("compiler_rt_obj"); + defer named_frame.end(); + comp.buildOutputFromZig( "compiler_rt.zig", .Obj, @@ -2502,6 +2580,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress }; }, .libssp => { + const named_frame = tracy.namedFrame("libssp"); + defer named_frame.end(); + comp.buildOutputFromZig( "ssp.zig", .Lib, @@ -2518,6 +2599,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress }; }, .zig_libc => { + const named_frame = tracy.namedFrame("zig_libc"); + defer named_frame.end(); + comp.buildOutputFromZig( "c.zig", .Lib, @@ -2534,6 +2618,9 @@ fn processOneJob(comp: *Compilation, job: Job, main_progress_node: *std.Progress }; }, .stage1_module => { + const named_frame = tracy.namedFrame("stage1_module"); + defer named_frame.end(); + if (!build_options.is_stage1) unreachable; @@ -2674,8 +2761,8 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult { if (!build_options.have_llvm) return error.ZigCompilerNotBuiltWithLLVMExtensions; - const tracy = trace(@src()); - defer tracy.end(); + const t = trace(@src()); + defer t.end(); const cimport_zig_basename = "cimport.zig"; @@ -2929,8 +3016,8 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P const self_exe_path = comp.self_exe_path orelse return comp.failCObj(c_object, "clang compilation disabled", .{}); - const tracy = trace(@src()); - defer tracy.end(); + const t = trace(@src()); + defer t.end(); log.debug("updating C object: {s}", .{c_object.src.src_path}); @@ -3828,8 +3915,8 @@ fn wantBuildLibUnwindFromSource(comp: *Compilation) bool { } fn updateBuiltinZigFile(comp: *Compilation, mod: *Module) Allocator.Error!void { - const tracy = trace(@src()); - defer tracy.end(); + const t = trace(@src()); + defer t.end(); const source = try comp.generateBuiltinZigSource(comp.gpa); defer comp.gpa.free(source); @@ -3866,8 +3953,8 @@ pub fn dump_argv(argv: []const []const u8) void { } pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) Allocator.Error![]u8 { - const tracy = trace(@src()); - defer tracy.end(); + const t = trace(@src()); + defer t.end(); var buffer = std.ArrayList(u8).init(allocator); defer buffer.deinit(); @@ -4112,8 +4199,8 @@ fn buildOutputFromZig( out: *?CRTFile, misc_task_tag: MiscTask, ) !void { - const tracy = trace(@src()); - defer tracy.end(); + const t = trace(@src()); + defer t.end(); std.debug.assert(output_mode != .Exe); const special_sub = "std" ++ std.fs.path.sep_str ++ "special"; @@ -4211,8 +4298,8 @@ fn buildOutputFromZig( } fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node) !void { - const tracy = trace(@src()); - defer tracy.end(); + const t = trace(@src()); + defer t.end(); var arena_allocator = std.heap.ArenaAllocator.init(comp.gpa); defer arena_allocator.deinit(); @@ -4564,8 +4651,8 @@ pub fn build_crt_file( output_mode: std.builtin.OutputMode, c_source_files: []const Compilation.CSourceFile, ) !void { - const tracy = trace(@src()); - defer tracy.end(); + const t = trace(@src()); + defer t.end(); const target = comp.getTarget(); const basename = try std.zig.binNameAlloc(comp.gpa, .{ diff --git a/src/main.zig b/src/main.zig index 280a69a425..e88e5dc91e 100644 --- a/src/main.zig +++ b/src/main.zig @@ -10,6 +10,7 @@ const ArrayList = std.ArrayList; const Ast = std.zig.Ast; const warn = std.log.warn; +const tracy = @import("tracy.zig"); const Compilation = @import("Compilation.zig"); const link = @import("link.zig"); const Package = @import("Package.zig"); @@ -155,6 +156,12 @@ pub fn main() anyerror!void { const arena = &arena_instance.allocator; const args = try process.argsAlloc(arena); + + if (tracy.enable_allocation) { + var gpa_tracy = tracy.tracyAllocator(gpa); + return mainArgs(&gpa_tracy.allocator, arena, args); + } + return mainArgs(gpa, arena, args); } @@ -2297,6 +2304,7 @@ fn buildOutputType( last_cmd = cmd; switch (cmd) { .update => { + tracy.frameMark(); if (output_mode == .Exe) { try comp.makeBinFileWritable(); } @@ -2309,6 +2317,7 @@ fn buildOutputType( try stderr.writeAll(repl_help); }, .run => { + tracy.frameMark(); try runOrTest( comp, gpa, @@ -2325,6 +2334,7 @@ fn buildOutputType( ); }, .update_and_run => { + tracy.frameMark(); if (output_mode == .Exe) { try comp.makeBinFileWritable(); } diff --git a/src/tracy.zig b/src/tracy.zig index 96f5fd998c..3ef2df7ca0 100644 --- a/src/tracy.zig +++ b/src/tracy.zig @@ -2,47 +2,309 @@ const std = @import("std"); const builtin = @import("builtin"); pub const enable = if (builtin.is_test) false else @import("build_options").enable_tracy; +pub const enable_allocation = enable and @import("build_options").enable_tracy_allocation; +pub const enable_callstack = enable and @import("build_options").enable_tracy_callstack; -extern fn ___tracy_emit_zone_begin_callstack( - srcloc: *const ___tracy_source_location_data, - depth: c_int, - active: c_int, -) ___tracy_c_zone_context; - -extern fn ___tracy_emit_zone_end(ctx: ___tracy_c_zone_context) void; - -pub const ___tracy_source_location_data = extern struct { - name: ?[*:0]const u8, - function: [*:0]const u8, - file: [*:0]const u8, - line: u32, - color: u32, -}; +// TODO: make this configurable +const callstack_depth = 10; -pub const ___tracy_c_zone_context = extern struct { +const ___tracy_c_zone_context = extern struct { id: u32, active: c_int, - pub fn end(self: ___tracy_c_zone_context) void { + pub inline fn end(self: @This()) void { ___tracy_emit_zone_end(self); } + + pub inline fn addText(self: @This(), text: []const u8) void { + ___tracy_emit_zone_text(self, text.ptr, text.len); + } + + pub inline fn setName(self: @This(), name: []const u8) void { + ___tracy_emit_zone_name(self, name.ptr, name.len); + } + + pub inline fn setColor(self: @This(), color: u32) void { + ___tracy_emit_zone_color(self, color); + } + + pub inline fn setValue(self: @This(), value: u64) void { + ___tracy_emit_zone_value(self, value); + } }; pub const Ctx = if (enable) ___tracy_c_zone_context else struct { - pub fn end(self: Ctx) void { + pub inline fn end(self: @This()) void { + _ = self; + } + + pub inline fn addText(self: @This(), text: []const u8) void { _ = self; + _ = text; + } + + pub inline fn setName(self: @This(), name: []const u8) void { + _ = self; + _ = name; + } + + pub inline fn setColor(self: @This(), color: u32) void { + _ = self; + _ = color; + } + + pub inline fn setValue(self: @This(), value: u64) void { + _ = self; + _ = value; } }; pub inline fn trace(comptime src: std.builtin.SourceLocation) Ctx { if (!enable) return .{}; - const loc: ___tracy_source_location_data = .{ - .name = null, - .function = src.fn_name.ptr, - .file = src.file.ptr, - .line = src.line, - .color = 0, + if (enable_callstack) { + return ___tracy_emit_zone_begin_callstack(&.{ + .name = null, + .function = src.fn_name.ptr, + .file = src.file.ptr, + .line = src.line, + .color = 0, + }, callstack_depth, 1); + } else { + return ___tracy_emit_zone_begin(&.{ + .name = null, + .function = src.fn_name.ptr, + .file = src.file.ptr, + .line = src.line, + .color = 0, + }, 1); + } +} + +pub inline fn traceNamed(comptime src: std.builtin.SourceLocation, comptime name: [:0]const u8) Ctx { + if (!enable) return .{}; + + if (enable_callstack) { + return ___tracy_emit_zone_begin_callstack(&.{ + .name = name.ptr, + .function = src.fn_name.ptr, + .file = src.file.ptr, + .line = src.line, + .color = 0, + }, callstack_depth, 1); + } else { + return ___tracy_emit_zone_begin(&.{ + .name = name.ptr, + .function = src.fn_name.ptr, + .file = src.file.ptr, + .line = src.line, + .color = 0, + }, 1); + } +} + +pub fn tracyAllocator(allocator: *std.mem.Allocator) TracyAllocator(null) { + return TracyAllocator(null).init(allocator); +} + +pub fn TracyAllocator(comptime name: ?[:0]const u8) type { + return struct { + allocator: std.mem.Allocator, + parent_allocator: *std.mem.Allocator, + + const Self = @This(); + + pub fn init(allocator: *std.mem.Allocator) Self { + return .{ + .parent_allocator = allocator, + .allocator = .{ + .allocFn = allocFn, + .resizeFn = resizeFn, + }, + }; + } + + fn allocFn(allocator: *std.mem.Allocator, len: usize, ptr_align: u29, len_align: u29, ret_addr: usize) std.mem.Allocator.Error![]u8 { + const self = @fieldParentPtr(Self, "allocator", allocator); + const result = self.parent_allocator.allocFn(self.parent_allocator, len, ptr_align, len_align, ret_addr); + if (result) |data| { + if (data.len != 0) { + if (name) |n| { + allocNamed(data.ptr, data.len, n); + } else { + alloc(data.ptr, data.len); + } + } + } else |_| { + messageColor("allocation failed", 0xFF0000); + } + return result; + } + + fn resizeFn(allocator: *std.mem.Allocator, buf: []u8, buf_align: u29, new_len: usize, len_align: u29, ret_addr: usize) std.mem.Allocator.Error!usize { + const self = @fieldParentPtr(Self, "allocator", allocator); + + if (self.parent_allocator.resizeFn(self.parent_allocator, buf, buf_align, new_len, len_align, ret_addr)) |resized_len| { + // this condition is to handle free being called on an empty slice that was never even allocated + // example case: `std.process.getSelfExeSharedLibPaths` can return `&[_][:0]u8{}` + if (buf.len != 0) { + if (name) |n| { + freeNamed(buf.ptr, n); + } else { + free(buf.ptr); + } + } + + if (resized_len != 0) { + // this was a shrink or a resize + if (name) |n| { + allocNamed(buf.ptr, resized_len, n); + } else { + alloc(buf.ptr, resized_len); + } + } + + return resized_len; + } else |err| { + // this is not really an error condition, during normal operation the compiler hits this case thousands of times + // due to this emitting messages for it is both slow and causes clutter + // messageColor("allocation resize failed", 0xFF0000); + return err; + } + } + }; +} + +// This function only accepts comptime known strings, see `messageCopy` for runtime strings +pub inline fn message(comptime msg: [:0]const u8) void { + if (!enable) return; + ___tracy_emit_messageL(msg.ptr, if (enable_callstack) callstack_depth else 0); +} + +// This function only accepts comptime known strings, see `messageColorCopy` for runtime strings +pub inline fn messageColor(comptime msg: [:0]const u8, color: u32) void { + if (!enable) return; + ___tracy_emit_messageLC(msg.ptr, color, if (enable_callstack) callstack_depth else 0); +} + +pub inline fn messageCopy(msg: []const u8) void { + if (!enable) return; + ___tracy_emit_message(msg.ptr, msg.len, if (enable_callstack) callstack_depth else 0); +} + +pub inline fn messageColorCopy(msg: [:0]const u8, color: u32) void { + if (!enable) return; + ___tracy_emit_messageC(msg.ptr, msg.len, color, if (enable_callstack) callstack_depth else 0); +} + +pub inline fn frameMark() void { + if (!enable) return; + ___tracy_emit_frame_mark(null); +} + +pub inline fn frameMarkNamed(comptime name: [:0]const u8) void { + if (!enable) return; + ___tracy_emit_frame_mark(name.ptr); +} + +pub inline fn namedFrame(comptime name: [:0]const u8) Frame(name) { + frameMarkStart(name); + return .{}; +} + +pub fn Frame(comptime name: [:0]const u8) type { + return struct { + pub fn end(_: @This()) void { + frameMarkEnd(name); + } }; - return ___tracy_emit_zone_begin_callstack(&loc, 1, 1); } + +inline fn frameMarkStart(comptime name: [:0]const u8) void { + if (!enable) return; + ___tracy_emit_frame_mark_start(name.ptr); +} + +inline fn frameMarkEnd(comptime name: [:0]const u8) void { + if (!enable) return; + ___tracy_emit_frame_mark_end(name.ptr); +} + +extern fn ___tracy_emit_frame_mark_start(name: [*:0]const u8) void; +extern fn ___tracy_emit_frame_mark_end(name: [*:0]const u8) void; + +inline fn alloc(ptr: [*]u8, len: usize) void { + if (!enable) return; + + if (enable_callstack) { + ___tracy_emit_memory_alloc_callstack(ptr, len, callstack_depth, 0); + } else { + ___tracy_emit_memory_alloc(ptr, len, 0); + } +} + +inline fn allocNamed(ptr: [*]u8, len: usize, comptime name: [:0]const u8) void { + if (!enable) return; + + if (enable_callstack) { + ___tracy_emit_memory_alloc_callstack_named(ptr, len, callstack_depth, 0, name.ptr); + } else { + ___tracy_emit_memory_alloc_named(ptr, len, 0, name.ptr); + } +} + +inline fn free(ptr: [*]u8) void { + if (!enable) return; + + if (enable_callstack) { + ___tracy_emit_memory_free_callstack(ptr, callstack_depth, 0); + } else { + ___tracy_emit_memory_free(ptr, 0); + } +} + +inline fn freeNamed(ptr: [*]u8, comptime name: [:0]const u8) void { + if (!enable) return; + + if (enable_callstack) { + ___tracy_emit_memory_free_callstack_named(ptr, callstack_depth, 0, name.ptr); + } else { + ___tracy_emit_memory_free_named(ptr, 0, name.ptr); + } +} + +extern fn ___tracy_emit_zone_begin( + srcloc: *const ___tracy_source_location_data, + active: c_int, +) ___tracy_c_zone_context; +extern fn ___tracy_emit_zone_begin_callstack( + srcloc: *const ___tracy_source_location_data, + depth: c_int, + active: c_int, +) ___tracy_c_zone_context; +extern fn ___tracy_emit_zone_text(ctx: ___tracy_c_zone_context, txt: [*]const u8, size: usize) void; +extern fn ___tracy_emit_zone_name(ctx: ___tracy_c_zone_context, txt: [*]const u8, size: usize) void; +extern fn ___tracy_emit_zone_color(ctx: ___tracy_c_zone_context, color: u32) void; +extern fn ___tracy_emit_zone_value(ctx: ___tracy_c_zone_context, value: u64) void; +extern fn ___tracy_emit_zone_end(ctx: ___tracy_c_zone_context) void; +extern fn ___tracy_emit_memory_alloc(ptr: *const c_void, size: usize, secure: c_int) void; +extern fn ___tracy_emit_memory_alloc_callstack(ptr: *const c_void, size: usize, depth: c_int, secure: c_int) void; +extern fn ___tracy_emit_memory_free(ptr: *const c_void, secure: c_int) void; +extern fn ___tracy_emit_memory_free_callstack(ptr: *const c_void, depth: c_int, secure: c_int) void; +extern fn ___tracy_emit_memory_alloc_named(ptr: *const c_void, size: usize, secure: c_int, name: [*:0]const u8) void; +extern fn ___tracy_emit_memory_alloc_callstack_named(ptr: *const c_void, size: usize, depth: c_int, secure: c_int, name: [*:0]const u8) void; +extern fn ___tracy_emit_memory_free_named(ptr: *const c_void, secure: c_int, name: [*:0]const u8) void; +extern fn ___tracy_emit_memory_free_callstack_named(ptr: *const c_void, depth: c_int, secure: c_int, name: [*:0]const u8) void; +extern fn ___tracy_emit_message(txt: [*]const u8, size: usize, callstack: c_int) void; +extern fn ___tracy_emit_messageL(txt: [*:0]const u8, callstack: c_int) void; +extern fn ___tracy_emit_messageC(txt: [*]const u8, size: usize, color: u32, callstack: c_int) void; +extern fn ___tracy_emit_messageLC(txt: [*:0]const u8, color: u32, callstack: c_int) void; +extern fn ___tracy_emit_frame_mark(name: ?[*:0]const u8) void; + +const ___tracy_source_location_data = extern struct { + name: ?[*:0]const u8, + function: [*:0]const u8, + file: [*:0]const u8, + line: u32, + color: u32, +}; |
