Skip to content

Commit 4600d2f

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 4600d2f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lib/std/child_process.zig

Lines changed: 15 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
};
@@ -364,6 +372,13 @@ pub const ChildProcess = struct {
364372
}
365373
});
366374

375+
if (self.request_resource_usage_statistics) {
376+
var pmc: windows.PROCESS_MEMORY_COUNTERS = undefined;
377+
if (windows.kernel32.K32GetProcessMemoryInfo(self.id, &pmc, @sizeOf(windows.PROCESS_MEMORY_COUNTERS)) != 0) {
378+
self.resource_usage_statistics.rusage = pmc;
379+
}
380+
}
381+
367382
os.close(self.id);
368383
os.close(self.thread_handle);
369384
self.cleanupStreams();

0 commit comments

Comments
 (0)