Uh oh!
There was an error while loading. Please reload this page.
Conversation
kubkon
commented
Mar 21, 2023
Thanks for the PR! As I explained in #15039 do you think you could try implementing the |
ghost
commented
Mar 21, 2023
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`
ghost
commented
Mar 22, 2023
I tested the conststd=@import("std");
constw=std.os.windows;
pubfnmain() !void {
conststdout_file=std.io.getStdOut().writer();
varbw=std.io.bufferedWriter(stdout_file);
conststdout=bw.writer();
constpHandle=w.kernel32.GetCurrentProcess();
varpmc: w.PROCESS_MEMORY_COUNTERS=undefined;
varpmc2: w.PROCESS_MEMORY_COUNTERS=undefined;
if (w.kernel32.K32GetProcessMemoryInfo(pHandle, &pmc, @sizeOf(w.PROCESS_MEMORY_COUNTERS)) !=0) {
trystdout.print("K32: MaxRss is {} Bytes!\n", .{pmc.PeakWorkingSetSize});
}
else {
trystdout.print("Something Went Wrong!\n", .{});
}
tryw.GetProcessMemoryInfo(pHandle, &pmc2);
trystdout.print("Nt: MaxRss is {} Bytes!\n", .{pmc2.PeakWorkingSetSize}); if (w.kernel32.K32GetProcessMemoryInfo(pHandle, &pmc, @sizeOf(w.PROCESS_MEMORY_COUNTERS)) !=0) {
trystdout.print("K32 Again: MaxRss is {} Bytes!\n", .{pmc.PeakWorkingSetSize});
} else {
trystdout.print("Something Went Wrong!\n", .{});
}
trybw.flush();
}Both functions reported the same MaxRss. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This change allows the function to return the process memory info directly instead of copying the result of the underlying Nt function.
kubkon
commented
Mar 23, 2023
Could you take a final look at this @squeek502 and if you are happy with this I'll merge it? |
Uh oh!
There was an error while loading. Please reload this page.
squeek502
commented
Mar 23, 2023
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.