motiejus/zig

fork of https://codeberg.org/ziglang/zig
git clone https://git.jakstys.lt/motiejus/zig.git
Log | Tree | Refs | README | LICENSE

commit cc44183787adde8b83f9373dd53250f154058dc4 (tree)
parent 84b89d7cfe452f91fa22f2646ef53a3a7e990456
Author: xEgoist <egoist@egoistic.dev>
Date:   Tue, 21 Mar 2023 09:03:50 -0500

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.

Diffstat:
Mlib/std/child_process.zig | 15+++++++++++++++
1 file changed, 15 insertions(+), 0 deletions(-)

diff --git a/lib/std/child_process.zig b/lib/std/child_process.zig @@ -99,12 +99,20 @@ pub const ChildProcess = struct { return null; } }, + .windows => { + if (rus.rusage) |ru| { + return ru.PeakWorkingSetSize; + } else { + return null; + } + }, else => return null, } } const rusage_init = switch (builtin.os.tag) { .linux => @as(?std.os.rusage, null), + .windows => @as(?windows.PROCESS_MEMORY_COUNTERS, null), else => {}, }; }; @@ -364,6 +372,13 @@ pub const ChildProcess = struct { } }); + if (self.request_resource_usage_statistics) { + var pmc: windows.PROCESS_MEMORY_COUNTERS = undefined; + if (windows.kernel32.K32GetProcessMemoryInfo(self.id, &pmc, @sizeOf(windows.PROCESS_MEMORY_COUNTERS)) != 0) { + self.resource_usage_statistics.rusage = pmc; + } + } + os.close(self.id); os.close(self.thread_handle); self.cleanupStreams();