structstd.process.Child.ResourceUsageStatistics[src]

Fields

rusage: @TypeOf(rusage_init) = rusage_init

Functions

FunctiongetMaxRss[src]

pub inline fn getMaxRss(rus: ResourceUsageStatistics) ?usize

Returns the peak resident set size of the child process, in bytes, if available.

Source Code

Source code
pub inline fn getMaxRss(rus: ResourceUsageStatistics) ?usize {
    switch (native_os) {
        .linux => {
            if (rus.rusage) |ru| {
                return @as(usize, @intCast(ru.maxrss)) * 1024;
            } else {
                return null;
            }
        },
        .windows => {
            if (rus.rusage) |ru| {
                return ru.PeakWorkingSetSize;
            } else {
                return null;
            }
        },
        .macos, .ios => {
            if (rus.rusage) |ru| {
                // Darwin oddly reports in bytes instead of kilobytes.
                return @as(usize, @intCast(ru.maxrss));
            } else {
                return null;
            }
        },
        else => return null,
    }
}

Source Code

Source code
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 (native_os) {
            .linux => {
                if (rus.rusage) |ru| {
                    return @as(usize, @intCast(ru.maxrss)) * 1024;
                } else {
                    return null;
                }
            },
            .windows => {
                if (rus.rusage) |ru| {
                    return ru.PeakWorkingSetSize;
                } else {
                    return null;
                }
            },
            .macos, .ios => {
                if (rus.rusage) |ru| {
                    // Darwin oddly reports in bytes instead of kilobytes.
                    return @as(usize, @intCast(ru.maxrss));
                } else {
                    return null;
                }
            },
            else => return null,
        }
    }

    const rusage_init = switch (native_os) {
        .linux, .macos, .ios => @as(?posix.rusage, null),
        .windows => @as(?windows.VM_COUNTERS, null),
        else => {},
    };
}