-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.This issue is limited in scope and/or knowledge of Zig internals.enhancementSolving this issue will likely involve adding new logic or components to the codebase.Solving this issue will likely involve adding new logic or components to the codebase.os-macosstandard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.
Milestone
Description
Extracted from #14647.
Lines 75 to 110 in b4d58e9
/// 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 => {}, | |
}; | |
}; |
Lines 374 to 383 in b4d58e9
const res: os.WaitPidResult = res: { | |
if (builtin.os.tag == .linux and self.request_resource_usage_statistics) { | |
var ru: std.os.rusage = undefined; | |
const res = os.wait4(self.id, 0, &ru); | |
self.resource_usage_statistics.rusage = ru; | |
break :res res; | |
} | |
break :res os.waitpid(self.id, 0); | |
}; |
Related: #14956
Metadata
Metadata
Assignees
Labels
contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.This issue is limited in scope and/or knowledge of Zig internals.enhancementSolving this issue will likely involve adding new logic or components to the codebase.Solving this issue will likely involve adding new logic or components to the codebase.os-macosstandard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.