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.
This commit is contained in:
xEgoist 2023-03-21 09:03:50 -05:00
parent 84b89d7cfe
commit cc44183787

View File

@ -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();