authorgravatar for egoist@egoistic.devxEgoist <egoist@egoistic.dev> 2023-03-23 06:13:26-05:00
committergravatar for egoist@egoistic.devxEgoist <egoist@egoistic.dev> 2023-03-23 06:13:26-05:00
log2f5af6c9721a125f3308b55f5a8059d62e5d2ec7
treef0409ea0892b8de64612b38d49c0e676f74de7fe
parent70469d428dd94693295b320a975b1ddf904dda3b

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.

2 files changed, 4 insertions(+), 19 deletions(-)

lib/std/child_process.zig+2-4
...@@ -112,7 +112,7 @@ pub const ChildProcess = struct {...@@ -112,7 +112,7 @@ pub const ChildProcess = struct {
112112
113 const rusage_init = switch (builtin.os.tag) {113 const rusage_init = switch (builtin.os.tag) {
114 .linux => @as(?std.os.rusage, null),114 .linux => @as(?std.os.rusage, null),
115 .windows => @as(?windows.PROCESS_MEMORY_COUNTERS, null),115 .windows => @as(?windows.VM_COUNTERS, null),
116 else => {},116 else => {},
117 };117 };
118 };118 };
...@@ -374,9 +374,7 @@ pub const ChildProcess = struct {...@@ -374,9 +374,7 @@ pub const ChildProcess = struct {
374 });374 });
375375
376 if (self.request_resource_usage_statistics) {376 if (self.request_resource_usage_statistics) {
377 var pmc: windows.PROCESS_MEMORY_COUNTERS = undefined;377 self.resource_usage_statistics.rusage = try windows.GetProcessMemoryInfo(self.id);
378 try windows.GetProcessMemoryInfo(self.id, &pmc);
379 self.resource_usage_statistics.rusage = pmc;
380 }378 }
381379
382 os.close(self.id);380 os.close(self.id);
lib/std/os/windows.zig+2-15
...@@ -3994,24 +3994,11 @@ pub const GetProcessMemoryInfoError = error{...@@ -3994,24 +3994,11 @@ pub const GetProcessMemoryInfoError = error{
3994 Unexpected,3994 Unexpected,
3995};3995};
39963996
3997pub fn GetProcessMemoryInfo(hProcess: HANDLE, out: *PROCESS_MEMORY_COUNTERS) GetProcessMemoryInfoError!void {3997pub fn GetProcessMemoryInfo(hProcess: HANDLE) GetProcessMemoryInfoError!VM_COUNTERS {
3998 var vmc: VM_COUNTERS = undefined;3998 var vmc: VM_COUNTERS = undefined;
3999 const rc = ntdll.NtQueryInformationProcess(hProcess, .ProcessVmCounters, &vmc, @sizeOf(VM_COUNTERS), null);3999 const rc = ntdll.NtQueryInformationProcess(hProcess, .ProcessVmCounters, &vmc, @sizeOf(VM_COUNTERS), null);
4000 switch (rc) {4000 switch (rc) {
4001 .SUCCESS => {4001 .SUCCESS => return vmc,
4002 out.* = PROCESS_MEMORY_COUNTERS{
4003 .cb = @sizeOf(PROCESS_MEMORY_COUNTERS),
4004 .PageFaultCount = vmc.PageFaultCount,
4005 .PeakWorkingSetSize = vmc.PeakWorkingSetSize,
4006 .WorkingSetSize = vmc.WorkingSetSize,
4007 .QuotaPeakPagedPoolUsage = vmc.QuotaPeakPagedPoolUsage,
4008 .QuotaPagedPoolUsage = vmc.QuotaPagedPoolUsage,
4009 .QuotaPeakNonPagedPoolUsage = vmc.QuotaPeakNonPagedPoolUsage,
4010 .QuotaNonPagedPoolUsage = vmc.QuotaNonPagedPoolUsage,
4011 .PagefileUsage = vmc.PagefileUsage,
4012 .PeakPagefileUsage = vmc.PeakPagefileUsage,
4013 };
4014 },
4015 .ACCESS_DENIED => return error.AccessDenied,4002 .ACCESS_DENIED => return error.AccessDenied,
4016 .INVALID_HANDLE => return error.InvalidHandle,4003 .INVALID_HANDLE => return error.InvalidHandle,
4017 .INVALID_PARAMETER => unreachable,4004 .INVALID_PARAMETER => unreachable,