|
/// Set to true to obtain rusage information for the child process. |
|
/// Depending on the target platform and implementation status, the |
|
/// requested statistics may or may not be available. If they are |
|
/// available, then the `resource_usage_statistics` field will be populated |
|
/// after calling `wait`. |
|
/// On Linux, this obtains rusage statistics from wait4(). |
|
request_resource_usage_statistics: bool = false, |
|
|
|
/// This is available after calling wait if |
|
/// `request_resource_usage_statistics` was set to `true` before calling |
|
/// `spawn`. |
|
resource_usage_statistics: ResourceUsageStatistics = .{}, |
|
|
|
pub const ResourceUsageStatistics = struct { |
|
rusage: @TypeOf(rusage_init) = rusage_init, |
|
|
|
/// Returns the peak resident set size of the child process, in bytes, |
|
/// if available. |
|
pub inline fn getMaxRss(rus: ResourceUsageStatistics) ?usize { |
|
switch (builtin.os.tag) { |
|
.linux => { |
|
if (rus.rusage) |ru| { |
|
return @intCast(usize, ru.maxrss) * 1024; |
|
} else { |
|
return null; |
|
} |
|
}, |
|
else => return null, |
|
} |
|
} |
|
|
|
const rusage_init = switch (builtin.os.tag) { |
|
.linux => @as(?std.os.rusage, null), |
|
else => {}, |
|
}; |
|
}; |
Extracted from #14647.
zig/lib/std/child_process.zig
Lines 75 to 110 in b4d58e9
zig/lib/std/child_process.zig
Lines 374 to 383 in b4d58e9
Related: #14956