Skip to content

add Darwin support for detecting maxrss of child process #14957

Description

@andrewrk

Extracted from #14647.

/// 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= .{},
pubconstResourceUsageStatistics=struct {
rusage: @TypeOf(rusage_init) =rusage_init,
/// Returns the peak resident set size of the child process, in bytes,
/// if available.
pubinlinefngetMaxRss(rus: ResourceUsageStatistics) ?usize {
switch (builtin.os.tag) {
.linux=> {
if (rus.rusage) |ru| {
return@intCast(usize, ru.maxrss) *1024;
} else {
returnnull;
}
},
else=>returnnull,
}
}
construsage_init=switch (builtin.os.tag) {
.linux=>@as(?std.os.rusage, null),
else=> {},
};
};

constres: os.WaitPidResult=res: {
if (builtin.os.tag==.linuxandself.request_resource_usage_statistics) {
varru: std.os.rusage=undefined;
constres=os.wait4(self.id, 0, &ru);
self.resource_usage_statistics.rusage=ru;
break :resres;
}
break :resos.waitpid(self.id, 0);
};

Related: #14956

Metadata

Metadata

Assignees

No one assigned

    Labels

    contributor friendlyThis 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.os-macosmacOSstandard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions