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 {...@@ -99,12 +99,20 @@ pub const ChildProcess = struct {
99 return null;99 return null;
100 }100 }
101 },101 },
102 .windows => {
103 if (rus.rusage) |ru| {
104 return ru.PeakWorkingSetSize;
105 } else {
106 return null;
107 }
108 },
102 else => return null,109 else => return null,
103 }110 }
104 }111 }
105112
106 const rusage_init = switch (builtin.os.tag) {113 const rusage_init = switch (builtin.os.tag) {
107 .linux => @as(?std.os.rusage, null),114 .linux => @as(?std.os.rusage, null),
115 .windows => @as(?windows.PROCESS_MEMORY_COUNTERS, null),
108 else => {},116 else => {},
109 };117 };
110 };118 };
...@@ -364,6 +372,13 @@ pub const ChildProcess = struct {...@@ -364,6 +372,13 @@ pub const ChildProcess = struct {
364 }372 }
365 });373 });
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
367 os.close(self.id);382 os.close(self.id);
368 os.close(self.thread_handle);383 os.close(self.thread_handle);
369 self.cleanupStreams();384 self.cleanupStreams();