add functionality to trace allocations

This commit is contained in:
Lee Cannon 2021-10-31 14:16:59 +00:00
parent 10c9fa0e08
commit 49d8723408
3 changed files with 11 additions and 1 deletions

View File

@ -111,6 +111,7 @@ pub fn build(b: *Builder) !void {
const tracy = b.option([]const u8, "tracy", "Enable Tracy integration. Supply path to Tracy source");
const tracy_callstack = b.option(bool, "tracy-callstack", "Include callstack information with Tracy data. Does nothing if -Dtracy is not provided") orelse false;
const tracy_allocation = b.option(bool, "tracy-allocation", "Include allocation information with Tracy data. Does nothing if -Dtracy is not provided") orelse false;
const link_libc = b.option(bool, "force-link-libc", "Force self-hosted compiler to link libc") orelse enable_llvm;
const strip = b.option(bool, "strip", "Omit debug information") orelse false;
@ -266,6 +267,7 @@ pub fn build(b: *Builder) !void {
exe_options.addOption(bool, "enable_link_snapshots", enable_link_snapshots);
exe_options.addOption(bool, "enable_tracy", tracy != null);
exe_options.addOption(bool, "enable_tracy_callstack", tracy_callstack);
exe_options.addOption(bool, "enable_tracy_allocation", tracy_allocation);
exe_options.addOption(bool, "is_stage1", is_stage1);
exe_options.addOption(bool, "omit_stage2", omit_stage2);
if (tracy) |tracy_path| {

View File

@ -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);
}

View File

@ -2,7 +2,8 @@ const std = @import("std");
const builtin = @import("builtin");
pub const enable = if (builtin.is_test) false else @import("build_options").enable_tracy;
const enable_callstack = @import("build_options").enable_tracy_callstack;
pub const enable_allocation = enable and @import("build_options").enable_tracy_allocation;
pub const enable_callstack = enable and @import("build_options").enable_tracy_callstack;
// TODO: make this configurable
const callstack_depth = 10;