Refactored GetProcessMemoryInfo to return VM_COUNTERS

This change allows the function to return the process memory info
directly instead of copying the result of the underlying Nt function.
This commit is contained in:
xEgoist 2023-03-23 06:13:26 -05:00
parent 70469d428d
commit 2f5af6c972
2 changed files with 4 additions and 19 deletions

View File

@ -112,7 +112,7 @@ pub const ChildProcess = struct {
const rusage_init = switch (builtin.os.tag) {
.linux => @as(?std.os.rusage, null),
.windows => @as(?windows.PROCESS_MEMORY_COUNTERS, null),
.windows => @as(?windows.VM_COUNTERS, null),
else => {},
};
};
@ -374,9 +374,7 @@ pub const ChildProcess = struct {
});
if (self.request_resource_usage_statistics) {
var pmc: windows.PROCESS_MEMORY_COUNTERS = undefined;
try windows.GetProcessMemoryInfo(self.id, &pmc);
self.resource_usage_statistics.rusage = pmc;
self.resource_usage_statistics.rusage = try windows.GetProcessMemoryInfo(self.id);
}
os.close(self.id);

View File

@ -3994,24 +3994,11 @@ pub const GetProcessMemoryInfoError = error{
Unexpected,
};
pub fn GetProcessMemoryInfo(hProcess: HANDLE, out: *PROCESS_MEMORY_COUNTERS) GetProcessMemoryInfoError!void {
pub fn GetProcessMemoryInfo(hProcess: HANDLE) GetProcessMemoryInfoError!VM_COUNTERS {
var vmc: VM_COUNTERS = undefined;
const rc = ntdll.NtQueryInformationProcess(hProcess, .ProcessVmCounters, &vmc, @sizeOf(VM_COUNTERS), null);
switch (rc) {
.SUCCESS => {
out.* = PROCESS_MEMORY_COUNTERS{
.cb = @sizeOf(PROCESS_MEMORY_COUNTERS),
.PageFaultCount = vmc.PageFaultCount,
.PeakWorkingSetSize = vmc.PeakWorkingSetSize,
.WorkingSetSize = vmc.WorkingSetSize,
.QuotaPeakPagedPoolUsage = vmc.QuotaPeakPagedPoolUsage,
.QuotaPagedPoolUsage = vmc.QuotaPagedPoolUsage,
.QuotaPeakNonPagedPoolUsage = vmc.QuotaPeakNonPagedPoolUsage,
.QuotaNonPagedPoolUsage = vmc.QuotaNonPagedPoolUsage,
.PagefileUsage = vmc.PagefileUsage,
.PeakPagefileUsage = vmc.PeakPagefileUsage,
};
},
.SUCCESS => return vmc,
.ACCESS_DENIED => return error.AccessDenied,
.INVALID_HANDLE => return error.InvalidHandle,
.INVALID_PARAMETER => unreachable,