authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-25 20:44:51-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-25 20:44:51-07:00
logc9619d7086a4aa61b1bd69faff4ce58a7f9c811c
treed0786c1ba8c0d7e3079a9212bb13c16743985bb7
parent1d750d7067e6e24af00aadc19379cd913652d80e

Maker: print amount of arena memory used only when --debug-maker-leaks


1 files changed, 10 insertions(+), 6 deletions(-)

lib/compiler/Maker.zig+10-6
......@@ -50,7 +50,6 @@ memory_blocked_steps: std.ArrayList(Configuration.Step.Index),
5050/// Allocated into `gpa`.
5151step_stack: std.AutoArrayHashMapUnmanaged(Configuration.Step.Index, void),
5252pkg_config: PkgConfig,
53debug_maker_leaks: bool,
5453
5554error_style: ErrorStyle,
5655multiline_errors: MultilineErrors,
......@@ -73,8 +72,8 @@ pub fn main(init: process.Init.Minimal) !void {
7372 // ...but we'll back our arena by `std.heap.page_allocator` for efficiency.
7473 var arena_instance: std.heap.ArenaAllocator = .init(std.heap.page_allocator);
7574 defer arena_instance.deinit();
75 defer if (debugMakerLeaks()) log.debug("used {Bi} of arena", .{arena_instance.queryCapacity()});
7676 const arena = arena_instance.allocator();
77 defer log.info("used {Bi} of arena", .{arena_instance.queryCapacity()});
7877
7978 const args = try init.args.toSlice(arena);
8079
......@@ -153,7 +152,6 @@ pub fn main(init: process.Init.Minimal) !void {
153152 var debounce_interval_ms: u16 = 50;
154153 var webui_listen: ?Io.net.IpAddress = null;
155154 var debug_pkg_config = false;
156 var debug_maker_leaks = false;
157155 var run_args: ?[]const []const u8 = null;
158156
159157 if (std.zig.EnvVar.ZIG_BUILD_ERROR_STYLE.get(&graph.environ_map)) |str| {
......@@ -300,7 +298,7 @@ pub fn main(init: process.Init.Minimal) !void {
300298 } else if (mem.cutPrefix(u8, arg, "--debug-rt=")) |rest| {
301299 graph.debug_compiler_runtime_libs = std.meta.stringToEnum(std.builtin.OptimizeMode, rest) orelse
302300 fatal("unrecognized optimization mode: {s}", .{rest});
303 } else if (mem.eql(u8, arg, "--debug-maker-leaks")) {
301 } else if (is_debug_mode and mem.eql(u8, arg, "--debug-maker-leaks")) {
304302 debug_maker_leaks = true;
305303 } else if (mem.eql(u8, arg, "--libc-runtimes") or mem.eql(u8, arg, "--glibc-runtimes")) {
306304 // --glibc-runtimes was the old name of the flag; kept for compatibility for now.
......@@ -543,7 +541,6 @@ pub fn main(init: process.Init.Minimal) !void {
543541 .memory_blocked_steps = .empty,
544542 .step_stack = .empty,
545543 .pkg_config = .{ .debug = debug_pkg_config },
546 .debug_maker_leaks = debug_maker_leaks,
547544
548545 .error_style = error_style,
549546 .multiline_errors = multiline_errors,
......@@ -1011,7 +1008,7 @@ fn makeStepNames(
10111008 };
10121009 if (code == 0) {
10131010 removePoisonedConfiguration(io, maker.scanned_config);
1014 if (builtin.mode == .Debug and maker.debug_maker_leaks) return deinit(maker);
1011 if (debugMakerLeaks()) return deinit(maker);
10151012 }
10161013 cleanup_task.await(io); // There is a defer above but an exit below.
10171014 _ = io.lockStderr(&.{}, graph.stderr_mode) catch {};
......@@ -2045,3 +2042,10 @@ fn removePoisonedConfiguration(io: Io, scanned_config: *const ScannedConfig) voi
20452042 log.warn("failed deleting poisoned configuration file {s}: {t}", .{ scanned_config.path, err });
20462043 }
20472044}
2045
2046const is_debug_mode = builtin.mode == .Debug;
2047var debug_maker_leaks: bool = false;
2048inline fn debugMakerLeaks() bool {
2049 if (!is_debug_mode) return false;
2050 return debug_maker_leaks;
2051}