| ... | @@ -17,7 +17,6 @@ const Os = std.builtin.Os; | ... | @@ -17,7 +17,6 @@ const Os = std.builtin.Os; |
| 17 | const TailQueue = std.TailQueue; | 17 | const TailQueue = std.TailQueue; |
| 18 | const maxInt = std.math.maxInt; | 18 | const maxInt = std.math.maxInt; |
| 19 | const assert = std.debug.assert; | 19 | const assert = std.debug.assert; |
| 20 | const is_darwin = builtin.target.isDarwin(); | | |
| 21 | | 20 | |
| 22 | pub const ChildProcess = struct { | 21 | pub const ChildProcess = struct { |
| 23 | pub const Id = switch (builtin.os.tag) { | 22 | pub const Id = switch (builtin.os.tag) { |
| ... | @@ -77,7 +76,7 @@ pub const ChildProcess = struct { | ... | @@ -77,7 +76,7 @@ pub const ChildProcess = struct { |
| 77 | /// requested statistics may or may not be available. If they are | 76 | /// requested statistics may or may not be available. If they are |
| 78 | /// available, then the `resource_usage_statistics` field will be populated | 77 | /// available, then the `resource_usage_statistics` field will be populated |
| 79 | /// after calling `wait`. | 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 | request_resource_usage_statistics: bool = false, | 80 | request_resource_usage_statistics: bool = false, |
| 82 | | 81 | |
| 83 | /// This is available after calling wait if | 82 | /// This is available after calling wait if |
| ... | @@ -106,12 +105,20 @@ pub const ChildProcess = struct { | ... | @@ -106,12 +105,20 @@ pub const ChildProcess = struct { |
| 106 | return null; | 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 | else => return null, | 116 | else => return null, |
| 110 | } | 117 | } |
| 111 | } | 118 | } |
| 112 | | 119 | |
| 113 | const rusage_init = switch (builtin.os.tag) { | 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 | .windows => @as(?windows.VM_COUNTERS, null), | 122 | .windows => @as(?windows.VM_COUNTERS, null), |
| 116 | else => {}, | 123 | else => {}, |
| 117 | }; | 124 | }; |
| ... | @@ -385,11 +392,16 @@ pub const ChildProcess = struct { | ... | @@ -385,11 +392,16 @@ pub const ChildProcess = struct { |
| 385 | | 392 | |
| 386 | fn waitUnwrapped(self: *ChildProcess) !void { | 393 | fn waitUnwrapped(self: *ChildProcess) !void { |
| 387 | const res: os.WaitPidResult = res: { | 394 | const res: os.WaitPidResult = res: { |
| 388 | if (builtin.os.tag == .linux and self.request_resource_usage_statistics) { | 395 | if (self.request_resource_usage_statistics) { |
| 389 | var ru: std.os.rusage = undefined; | 396 | switch (builtin.os.tag) { |
| 390 | const res = os.wait4(self.id, 0, &ru); | 397 | .linux, .macos, .ios => { |
| 391 | self.resource_usage_statistics.rusage = ru; | 398 | var ru: std.os.rusage = undefined; |
| 392 | break :res res; | 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 | break :res os.waitpid(self.id, 0); | 407 | break :res os.waitpid(self.id, 0); |