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 {...@@ -111,6 +111,7 @@ pub fn build(b: *Builder) !void {
111111
112 const tracy = b.option([]const u8, "tracy", "Enable Tracy integration. Supply path to Tracy source");112 const tracy = b.option([]const u8, "tracy", "Enable Tracy integration. Supply path to Tracy source");
113 const tracy_callstack = b.option(bool, "tracy-callstack", "Include callstack information with Tracy data. Does nothing if -Dtracy is not provided") orelse false;113 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;
114 const link_libc = b.option(bool, "force-link-libc", "Force self-hosted compiler to link libc") orelse enable_llvm;115 const link_libc = b.option(bool, "force-link-libc", "Force self-hosted compiler to link libc") orelse enable_llvm;
115 const strip = b.option(bool, "strip", "Omit debug information") orelse false;116 const strip = b.option(bool, "strip", "Omit debug information") orelse false;
116117
...@@ -266,6 +267,7 @@ pub fn build(b: *Builder) !void {...@@ -266,6 +267,7 @@ pub fn build(b: *Builder) !void {
266 exe_options.addOption(bool, "enable_link_snapshots", enable_link_snapshots);267 exe_options.addOption(bool, "enable_link_snapshots", enable_link_snapshots);
267 exe_options.addOption(bool, "enable_tracy", tracy != null);268 exe_options.addOption(bool, "enable_tracy", tracy != null);
268 exe_options.addOption(bool, "enable_tracy_callstack", tracy_callstack);269 exe_options.addOption(bool, "enable_tracy_callstack", tracy_callstack);
270 exe_options.addOption(bool, "enable_tracy_allocation", tracy_allocation);
269 exe_options.addOption(bool, "is_stage1", is_stage1);271 exe_options.addOption(bool, "is_stage1", is_stage1);
270 exe_options.addOption(bool, "omit_stage2", omit_stage2);272 exe_options.addOption(bool, "omit_stage2", omit_stage2);
271 if (tracy) |tracy_path| {273 if (tracy) |tracy_path| {
src/main.zig+7
...@@ -10,6 +10,7 @@ const ArrayList = std.ArrayList;...@@ -10,6 +10,7 @@ const ArrayList = std.ArrayList;
10const Ast = std.zig.Ast;10const Ast = std.zig.Ast;
11const warn = std.log.warn;11const warn = std.log.warn;
1212
13const tracy = @import("tracy.zig");
13const Compilation = @import("Compilation.zig");14const Compilation = @import("Compilation.zig");
14const link = @import("link.zig");15const link = @import("link.zig");
15const Package = @import("Package.zig");16const Package = @import("Package.zig");
...@@ -155,6 +156,12 @@ pub fn main() anyerror!void {...@@ -155,6 +156,12 @@ pub fn main() anyerror!void {
155 const arena = &arena_instance.allocator;156 const arena = &arena_instance.allocator;
156157
157 const args = try process.argsAlloc(arena);158 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
158 return mainArgs(gpa, arena, args);165 return mainArgs(gpa, arena, args);
159}166}
160167
src/tracy.zig+2-1
...@@ -2,7 +2,8 @@ const std = @import("std");...@@ -2,7 +2,8 @@ const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub const enable = if (builtin.is_test) false else @import("build_options").enable_tracy;4pub 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
7// TODO: make this configurable8// TODO: make this configurable
8const callstack_depth = 10;9const callstack_depth = 10;