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),...@@ -50,7 +50,6 @@ memory_blocked_steps: std.ArrayList(Configuration.Step.Index),
50/// Allocated into `gpa`.50/// Allocated into `gpa`.
51step_stack: std.AutoArrayHashMapUnmanaged(Configuration.Step.Index, void),51step_stack: std.AutoArrayHashMapUnmanaged(Configuration.Step.Index, void),
52pkg_config: PkgConfig,52pkg_config: PkgConfig,
53debug_maker_leaks: bool,
5453
55error_style: ErrorStyle,54error_style: ErrorStyle,
56multiline_errors: MultilineErrors,55multiline_errors: MultilineErrors,
...@@ -73,8 +72,8 @@ pub fn main(init: process.Init.Minimal) !void {...@@ -73,8 +72,8 @@ pub fn main(init: process.Init.Minimal) !void {
73 // ...but we'll back our arena by `std.heap.page_allocator` for efficiency.72 // ...but we'll back our arena by `std.heap.page_allocator` for efficiency.
74 var arena_instance: std.heap.ArenaAllocator = .init(std.heap.page_allocator);73 var arena_instance: std.heap.ArenaAllocator = .init(std.heap.page_allocator);
75 defer arena_instance.deinit();74 defer arena_instance.deinit();
75 defer if (debugMakerLeaks()) log.debug("used {Bi} of arena", .{arena_instance.queryCapacity()});
76 const arena = arena_instance.allocator();76 const arena = arena_instance.allocator();
77 defer log.info("used {Bi} of arena", .{arena_instance.queryCapacity()});
7877
79 const args = try init.args.toSlice(arena);78 const args = try init.args.toSlice(arena);
8079
...@@ -153,7 +152,6 @@ pub fn main(init: process.Init.Minimal) !void {...@@ -153,7 +152,6 @@ pub fn main(init: process.Init.Minimal) !void {
153 var debounce_interval_ms: u16 = 50;152 var debounce_interval_ms: u16 = 50;
154 var webui_listen: ?Io.net.IpAddress = null;153 var webui_listen: ?Io.net.IpAddress = null;
155 var debug_pkg_config = false;154 var debug_pkg_config = false;
156 var debug_maker_leaks = false;
157 var run_args: ?[]const []const u8 = null;155 var run_args: ?[]const []const u8 = null;
158156
159 if (std.zig.EnvVar.ZIG_BUILD_ERROR_STYLE.get(&graph.environ_map)) |str| {157 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 {...@@ -300,7 +298,7 @@ pub fn main(init: process.Init.Minimal) !void {
300 } else if (mem.cutPrefix(u8, arg, "--debug-rt=")) |rest| {298 } else if (mem.cutPrefix(u8, arg, "--debug-rt=")) |rest| {
301 graph.debug_compiler_runtime_libs = std.meta.stringToEnum(std.builtin.OptimizeMode, rest) orelse299 graph.debug_compiler_runtime_libs = std.meta.stringToEnum(std.builtin.OptimizeMode, rest) orelse
302 fatal("unrecognized optimization mode: {s}", .{rest});300 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")) {
304 debug_maker_leaks = true;302 debug_maker_leaks = true;
305 } else if (mem.eql(u8, arg, "--libc-runtimes") or mem.eql(u8, arg, "--glibc-runtimes")) {303 } else if (mem.eql(u8, arg, "--libc-runtimes") or mem.eql(u8, arg, "--glibc-runtimes")) {
306 // --glibc-runtimes was the old name of the flag; kept for compatibility for now.304 // --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 {...@@ -543,7 +541,6 @@ pub fn main(init: process.Init.Minimal) !void {
543 .memory_blocked_steps = .empty,541 .memory_blocked_steps = .empty,
544 .step_stack = .empty,542 .step_stack = .empty,
545 .pkg_config = .{ .debug = debug_pkg_config },543 .pkg_config = .{ .debug = debug_pkg_config },
546 .debug_maker_leaks = debug_maker_leaks,
547544
548 .error_style = error_style,545 .error_style = error_style,
549 .multiline_errors = multiline_errors,546 .multiline_errors = multiline_errors,
...@@ -1011,7 +1008,7 @@ fn makeStepNames(...@@ -1011,7 +1008,7 @@ fn makeStepNames(
1011 };1008 };
1012 if (code == 0) {1009 if (code == 0) {
1013 removePoisonedConfiguration(io, maker.scanned_config);1010 removePoisonedConfiguration(io, maker.scanned_config);
1014 if (builtin.mode == .Debug and maker.debug_maker_leaks) return deinit(maker);1011 if (debugMakerLeaks()) return deinit(maker);
1015 }1012 }
1016 cleanup_task.await(io); // There is a defer above but an exit below.1013 cleanup_task.await(io); // There is a defer above but an exit below.
1017 _ = io.lockStderr(&.{}, graph.stderr_mode) catch {};1014 _ = io.lockStderr(&.{}, graph.stderr_mode) catch {};
...@@ -2045,3 +2042,10 @@ fn removePoisonedConfiguration(io: Io, scanned_config: *const ScannedConfig) voi...@@ -2045,3 +2042,10 @@ fn removePoisonedConfiguration(io: Io, scanned_config: *const ScannedConfig) voi
2045 log.warn("failed deleting poisoned configuration file {s}: {t}", .{ scanned_config.path, err });2042 log.warn("failed deleting poisoned configuration file {s}: {t}", .{ scanned_config.path, err });
2046 }2043 }
2047}2044}
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}