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 {...@@ -375,6 +375,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
375 &.{ "o", &digest, placeholder.output.basename },375 &.{ "o", &digest, placeholder.output.basename },
376 );376 );
377 }377 }
378 step.result_cached = true;
378 return;379 return;
379 }380 }
380381
...@@ -580,6 +581,9 @@ fn runCommand(self: *RunStep, argv: []const []const u8, has_side_effects: bool)...@@ -580,6 +581,9 @@ fn runCommand(self: *RunStep, argv: []const []const u8, has_side_effects: bool)
580 return step.fail("unable to spawn {s}: {s}", .{ argv[0], @errorName(err) });581 return step.fail("unable to spawn {s}: {s}", .{ argv[0], @errorName(err) });
581 };582 };
582583
584 step.result_duration_ns = result.elapsed_ns;
585 step.result_peak_rss = result.peak_rss;
586
583 switch (self.stdio) {587 switch (self.stdio) {
584 .check => |checks| for (checks.items) |check| switch (check) {588 .check => |checks| for (checks.items) |check| switch (check) {
585 .expect_stderr_exact => |expected_bytes| {589 .expect_stderr_exact => |expected_bytes| {
...@@ -678,6 +682,8 @@ const ChildProcResult = struct {...@@ -678,6 +682,8 @@ const ChildProcResult = struct {
678 stdout_null: bool,682 stdout_null: bool,
679 stderr_null: bool,683 stderr_null: bool,
680 term: std.process.Child.Term,684 term: std.process.Child.Term,
685 elapsed_ns: u64,
686 peak_rss: usize,
681};687};
682688
683fn spawnChildAndCollect(689fn spawnChildAndCollect(
...@@ -696,6 +702,7 @@ fn spawnChildAndCollect(...@@ -696,6 +702,7 @@ fn spawnChildAndCollect(
696 child.cwd_dir = b.build_root.handle;702 child.cwd_dir = b.build_root.handle;
697 }703 }
698 child.env_map = self.env_map orelse b.env_map;704 child.env_map = self.env_map orelse b.env_map;
705 child.request_resource_usage_statistics = true;
699706
700 child.stdin_behavior = switch (self.stdio) {707 child.stdin_behavior = switch (self.stdio) {
701 .infer_from_args => if (has_side_effects) .Inherit else .Ignore,708 .infer_from_args => if (has_side_effects) .Inherit else .Ignore,
...@@ -716,6 +723,7 @@ fn spawnChildAndCollect(...@@ -716,6 +723,7 @@ fn spawnChildAndCollect(
716 child.spawn() catch |err| return self.step.fail("unable to spawn {s}: {s}", .{723 child.spawn() catch |err| return self.step.fail("unable to spawn {s}: {s}", .{
717 argv[0], @errorName(err),724 argv[0], @errorName(err),
718 });725 });
726 var timer = try std.time.Timer.start();
719727
720 // These are not optionals, as a workaround for728 // These are not optionals, as a workaround for
721 // https://github.com/ziglang/zig/issues/14783729 // https://github.com/ziglang/zig/issues/14783
...@@ -762,12 +770,17 @@ fn spawnChildAndCollect(...@@ -762,12 +770,17 @@ fn spawnChildAndCollect(
762 }770 }
763 }771 }
764772
773 const term = try child.wait();
774 const elapsed_ns = timer.read();
775
765 return .{776 return .{
766 .stdout = stdout_bytes,777 .stdout = stdout_bytes,
767 .stderr = stderr_bytes,778 .stderr = stderr_bytes,
768 .stdout_null = stdout_null,779 .stdout_null = stdout_null,
769 .stderr_null = stderr_null,780 .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,
771 };784 };
772}785}
773786