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 {
112112
113113 const rusage_init = switch (builtin.os.tag) {
114114 .linux => @as(?std.os.rusage, null),
115 .windows => @as(?windows.PROCESS_MEMORY_COUNTERS, null),
115 .windows => @as(?windows.VM_COUNTERS, null),
116116 else => {},
117117 };
118118 };
......@@ -374,9 +374,7 @@ pub const ChildProcess = struct {
374374 });
375375
376376 if (self.request_resource_usage_statistics) {
377 var pmc: windows.PROCESS_MEMORY_COUNTERS = undefined;
378 try windows.GetProcessMemoryInfo(self.id, &pmc);
379 self.resource_usage_statistics.rusage = pmc;
377 self.resource_usage_statistics.rusage = try windows.GetProcessMemoryInfo(self.id);
380378 }
381379
382380 os.close(self.id);
lib/std/os/windows.zig+2-15
......@@ -3994,24 +3994,11 @@ pub const GetProcessMemoryInfoError = error{
39943994 Unexpected,
39953995};
39963996
3997pub fn GetProcessMemoryInfo(hProcess: HANDLE, out: *PROCESS_MEMORY_COUNTERS) GetProcessMemoryInfoError!void {
3997pub fn GetProcessMemoryInfo(hProcess: HANDLE) GetProcessMemoryInfoError!VM_COUNTERS {
39983998 var vmc: VM_COUNTERS = undefined;
39993999 const rc = ntdll.NtQueryInformationProcess(hProcess, .ProcessVmCounters, &vmc, @sizeOf(VM_COUNTERS), null);
40004000 switch (rc) {
4001 .SUCCESS => {
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 },
4001 .SUCCESS => return vmc,
40154002 .ACCESS_DENIED => return error.AccessDenied,
40164003 .INVALID_HANDLE => return error.InvalidHandle,
40174004 .INVALID_PARAMETER => unreachable,