authorgravatar for leecannon@leecannon.xyzLee Cannon <leecannon@leecannon.xyz> 2021-10-31 14:16:59+00:00
committergravatar for leecannon@leecannon.xyzLee Cannon <leecannon@leecannon.xyz> 2021-10-31 14:16:59+00:00
log49d8723408233ac1c8942eca0a52ca12188040ce
tree047a8af4189c44dfb51c4f8de503ea8af0c45fa6
parent10c9fa0e080763faa1d952f635deb8e4cc1a23e2

add functionality to trace allocations


3 files changed, 11 insertions(+), 1 deletions(-)

build.zig+2
......@@ -111,6 +111,7 @@ pub fn build(b: *Builder) !void {
111111
112112 const tracy = b.option([]const u8, "tracy", "Enable Tracy integration. Supply path to Tracy source");
113113 const tracy_callstack = b.option(bool, "tracy-callstack", "Include callstack information with Tracy data. Does nothing if -Dtracy is not provided") orelse false;
114 const tracy_allocation = b.option(bool, "tracy-allocation", "Include allocation information with Tracy data. Does nothing if -Dtracy is not provided") orelse false;
114115 const link_libc = b.option(bool, "force-link-libc", "Force self-hosted compiler to link libc") orelse enable_llvm;
115116 const strip = b.option(bool, "strip", "Omit debug information") orelse false;
116117
......@@ -266,6 +267,7 @@ pub fn build(b: *Builder) !void {
266267 exe_options.addOption(bool, "enable_link_snapshots", enable_link_snapshots);
267268 exe_options.addOption(bool, "enable_tracy", tracy != null);
268269 exe_options.addOption(bool, "enable_tracy_callstack", tracy_callstack);
270 exe_options.addOption(bool, "enable_tracy_allocation", tracy_allocation);
269271 exe_options.addOption(bool, "is_stage1", is_stage1);
270272 exe_options.addOption(bool, "omit_stage2", omit_stage2);
271273 if (tracy) |tracy_path| {
src/main.zig+7
......@@ -10,6 +10,7 @@ const ArrayList = std.ArrayList;
1010const Ast = std.zig.Ast;
1111const warn = std.log.warn;
1212
13const tracy = @import("tracy.zig");
1314const Compilation = @import("Compilation.zig");
1415const link = @import("link.zig");
1516const Package = @import("Package.zig");
......@@ -155,6 +156,12 @@ pub fn main() anyerror!void {
155156 const arena = &arena_instance.allocator;
156157
157158 const args = try process.argsAlloc(arena);
159
160 if (tracy.enable_allocation) {
161 var gpa_tracy = tracy.tracyAllocator(gpa);
162 return mainArgs(&gpa_tracy.allocator, arena, args);
163 }
164
158165 return mainArgs(gpa, arena, args);
159166}
160167
src/tracy.zig+2-1
......@@ -2,7 +2,8 @@ const std = @import("std");
22const builtin = @import("builtin");
33
44pub const enable = if (builtin.is_test) false else @import("build_options").enable_tracy;
5const enable_callstack = @import("build_options").enable_tracy_callstack;
5pub const enable_allocation = enable and @import("build_options").enable_tracy_allocation;
6pub const enable_callstack = enable and @import("build_options").enable_tracy_callstack;
67
78// TODO: make this configurable
89const callstack_depth = 10;