Implement getMaxRss for Windows#15035
Conversation
6401747 to
4600d2f
Compare
|
Thanks for the PR! As I explained in #15039 do you think you could try implementing the |
Certainly. I wasn't initially sure if I should include it in this PR, but I was going to implement Will update this PR as soon as I implement it. |
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.
`GetProcessMemoryInfo` is implemented using `NtQueryInformationProcess` with `ProcessVmCounters` to obtain `VM_COUNTERS`. The structs, enum definitions are found in `winternl.h` or `ntddk.h` in the latest WDK. This should give the same results as using `K32GetProcessMemoryInfo`
|
I tested the const std = @import("std");
const w = std.os.windows;
pub fn main() !void {
const stdout_file = std.io.getStdOut().writer();
var bw = std.io.bufferedWriter(stdout_file);
const stdout = bw.writer();
const pHandle = w.kernel32.GetCurrentProcess();
var pmc: w.PROCESS_MEMORY_COUNTERS = undefined;
var pmc2: w.PROCESS_MEMORY_COUNTERS = undefined;
if (w.kernel32.K32GetProcessMemoryInfo(pHandle, &pmc, @sizeOf(w.PROCESS_MEMORY_COUNTERS)) != 0) {
try stdout.print("K32: MaxRss is {} Bytes!\n", .{pmc.PeakWorkingSetSize});
}
else {
try stdout.print("Something Went Wrong!\n", .{});
}
try w.GetProcessMemoryInfo(pHandle, &pmc2);
try stdout.print("Nt: MaxRss is {} Bytes!\n", .{pmc2.PeakWorkingSetSize});
if (w.kernel32.K32GetProcessMemoryInfo(pHandle, &pmc, @sizeOf(w.PROCESS_MEMORY_COUNTERS)) != 0) {
try stdout.print("K32 Again: MaxRss is {} Bytes!\n", .{pmc.PeakWorkingSetSize});
}
else {
try stdout.print("Something Went Wrong!\n", .{});
}
try bw.flush();
}Both functions reported the same MaxRss. |
This change allows the function to return the process memory info directly instead of copying the result of the underlying Nt function.
|
Could you take a final look at this @squeek502 and if you are happy with this I'll merge it? |
|
Looks good to me 👍 |
closes #14956
As stated in the commit message, this is done using
K32GetProcessMemoryInfoto get PeakWorkingSetSize.Since GetProcessMemoryInfo is used in
(Or Kernel32.dll), I will try to issue a pull request later for aPsapi.dllntdllrefactor to this function.Edit: Switched to kernel32 for compatibility + psapi calls kernel32 anyway.