| ... | ... | @@ -17,7 +17,6 @@ const Os = std.builtin.Os; |
| 17 | 17 | const TailQueue = std.TailQueue; |
| 18 | 18 | const maxInt = std.math.maxInt; |
| 19 | 19 | const assert = std.debug.assert; |
| 20 | | const is_darwin = builtin.target.isDarwin(); |
| 21 | 20 | |
| 22 | 21 | pub const ChildProcess = struct { |
| 23 | 22 | pub const Id = switch (builtin.os.tag) { |
| ... | ... | @@ -77,7 +76,7 @@ pub const ChildProcess = struct { |
| 77 | 76 | /// requested statistics may or may not be available. If they are |
| 78 | 77 | /// available, then the `resource_usage_statistics` field will be populated |
| 79 | 78 | /// after calling `wait`. |
| 80 | | /// On Linux, this obtains rusage statistics from wait4(). |
| 79 | /// On Linux and Darwin, this obtains rusage statistics from wait4(). |
| 81 | 80 | request_resource_usage_statistics: bool = false, |
| 82 | 81 | |
| 83 | 82 | /// This is available after calling wait if |
| ... | ... | @@ -106,12 +105,20 @@ pub const ChildProcess = struct { |
| 106 | 105 | return null; |
| 107 | 106 | } |
| 108 | 107 | }, |
| 108 | .macos, .ios => { |
| 109 | if (rus.rusage) |ru| { |
| 110 | // Darwin oddly reports in bytes instead of kilobytes. |
| 111 | return @intCast(usize, ru.maxrss); |
| 112 | } else { |
| 113 | return null; |
| 114 | } |
| 115 | }, |
| 109 | 116 | else => return null, |
| 110 | 117 | } |
| 111 | 118 | } |
| 112 | 119 | |
| 113 | 120 | const rusage_init = switch (builtin.os.tag) { |
| 114 | | .linux => @as(?std.os.rusage, null), |
| 121 | .linux, .macos, .ios => @as(?std.os.rusage, null), |
| 115 | 122 | .windows => @as(?windows.VM_COUNTERS, null), |
| 116 | 123 | else => {}, |
| 117 | 124 | }; |
| ... | ... | @@ -385,11 +392,16 @@ pub const ChildProcess = struct { |
| 385 | 392 | |
| 386 | 393 | fn waitUnwrapped(self: *ChildProcess) !void { |
| 387 | 394 | const res: os.WaitPidResult = res: { |
| 388 | | if (builtin.os.tag == .linux and self.request_resource_usage_statistics) { |
| 389 | | var ru: std.os.rusage = undefined; |
| 390 | | const res = os.wait4(self.id, 0, &ru); |
| 391 | | self.resource_usage_statistics.rusage = ru; |
| 392 | | break :res res; |
| 395 | if (self.request_resource_usage_statistics) { |
| 396 | switch (builtin.os.tag) { |
| 397 | .linux, .macos, .ios => { |
| 398 | var ru: std.os.rusage = undefined; |
| 399 | const res = os.wait4(self.id, 0, &ru); |
| 400 | self.resource_usage_statistics.rusage = ru; |
| 401 | break :res res; |
| 402 | }, |
| 403 | else => {}, |
| 404 | } |
| 393 | 405 | } |
| 394 | 406 | |
| 395 | 407 | break :res os.waitpid(self.id, 0); |