Skip to content

Commit 6401747

Browse files
committed
Implemented getMaxRss for Windows
In Windows, the equivalent to maxrss is PeakWorkingSetSize which is found in PROCESS_MEMORY_COUNTERS in bytes. Currently, this is done by calling `GetProcessMemoryInfo` in kernel32.
1 parent 0787b11 commit 6401747

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lib/std/child_process.zig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,20 @@ pub const ChildProcess = struct {
9999
return null;
100100
}
101101
},
102+
.windows => {
103+
if (rus.rusage) |ru| {
104+
return ru.PeakWorkingSetSize;
105+
} else {
106+
return null;
107+
}
108+
},
102109
else => return null,
103110
}
104111
}
105112

106113
const rusage_init = switch (builtin.os.tag) {
107114
.linux => @as(?std.os.rusage, null),
115+
.windows => @as(?windows.PROCESS_MEMORY_COUNTERS, null),
108116
else => {},
109117
};
110118
};
@@ -353,6 +361,12 @@ pub const ChildProcess = struct {
353361
}
354362

355363
fn waitUnwrappedWindows(self: *ChildProcess) !void {
364+
if (self.request_resource_usage_statistics) {
365+
var pmc: windows.PROCESS_MEMORY_COUNTERS = undefined;
366+
if (windows.kernel32.K32GetProcessMemoryInfo(self.id, &pmc, @sizeOf(windows.PROCESS_MEMORY_COUNTERS)) != 0) {
367+
self.resource_usage_statistics.rusage = pmc;
368+
}
369+
}
356370
const result = windows.WaitForSingleObjectEx(self.id, windows.INFINITE, false);
357371

358372
self.term = @as(SpawnError!Term, x: {

0 commit comments

Comments
 (0)