authorgravatar for egoist@egoistic.devxEgoist <egoist@egoistic.dev> 2023-03-21 09:03:50-05:00
committergravatar for egoist@egoistic.devxEgoist <egoist@egoistic.dev> 2023-03-22 06:13:11-05:00
logcc44183787adde8b83f9373dd53250f154058dc4
tree9fe93e247b90d07951519f9102e2ae8716f322dc
parent84b89d7cfe452f91fa22f2646ef53a3a7e990456

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 files changed, 15 insertions(+), 0 deletions(-)

lib/std/child_process.zig+15
......@@ -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();