authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-03-03 15:29:02-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-03-15 10:48:13-07:00
log2b23625510e4f250ae925f9a3a4b090fba69f6a8
tree41e75a0ec3fc31f854cc590eda8682990f38f644
parentd695f36e70f162e4e84087df1ccad5430e53d786

std.Build.RunStep: report duration and cached status


1 files changed, 14 insertions(+), 1 deletions(-)

lib/std/Build/RunStep.zig+14-1
......@@ -375,6 +375,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
375375 &.{ "o", &digest, placeholder.output.basename },
376376 );
377377 }
378 step.result_cached = true;
378379 return;
379380 }
380381
......@@ -580,6 +581,9 @@ fn runCommand(self: *RunStep, argv: []const []const u8, has_side_effects: bool)
580581 return step.fail("unable to spawn {s}: {s}", .{ argv[0], @errorName(err) });
581582 };
582583
584 step.result_duration_ns = result.elapsed_ns;
585 step.result_peak_rss = result.peak_rss;
586
583587 switch (self.stdio) {
584588 .check => |checks| for (checks.items) |check| switch (check) {
585589 .expect_stderr_exact => |expected_bytes| {
......@@ -678,6 +682,8 @@ const ChildProcResult = struct {
678682 stdout_null: bool,
679683 stderr_null: bool,
680684 term: std.process.Child.Term,
685 elapsed_ns: u64,
686 peak_rss: usize,
681687};
682688
683689fn spawnChildAndCollect(
......@@ -696,6 +702,7 @@ fn spawnChildAndCollect(
696702 child.cwd_dir = b.build_root.handle;
697703 }
698704 child.env_map = self.env_map orelse b.env_map;
705 child.request_resource_usage_statistics = true;
699706
700707 child.stdin_behavior = switch (self.stdio) {
701708 .infer_from_args => if (has_side_effects) .Inherit else .Ignore,
......@@ -716,6 +723,7 @@ fn spawnChildAndCollect(
716723 child.spawn() catch |err| return self.step.fail("unable to spawn {s}: {s}", .{
717724 argv[0], @errorName(err),
718725 });
726 var timer = try std.time.Timer.start();
719727
720728 // These are not optionals, as a workaround for
721729 // https://github.com/ziglang/zig/issues/14783
......@@ -762,12 +770,17 @@ fn spawnChildAndCollect(
762770 }
763771 }
764772
773 const term = try child.wait();
774 const elapsed_ns = timer.read();
775
765776 return .{
766777 .stdout = stdout_bytes,
767778 .stderr = stderr_bytes,
768779 .stdout_null = stdout_null,
769780 .stderr_null = stderr_null,
770 .term = try child.wait(),
781 .term = term,
782 .elapsed_ns = elapsed_ns,
783 .peak_rss = child.resource_usage_statistics.getMaxRss() orelse 0,
771784 };
772785}
773786