Skip to content

Commit 2f5af6c

Browse files
committed
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.
1 parent 70469d4 commit 2f5af6c

File tree

2 files changed

+4
-19
lines changed

2 files changed

+4
-19
lines changed

lib/std/child_process.zig

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3994,24 +3994,11 @@ pub const GetProcessMemoryInfoError = error{
39943994
Unexpected,
39953995
};
39963996

3997-
pub fn GetProcessMemoryInfo(hProcess: HANDLE, out: *PROCESS_MEMORY_COUNTERS) GetProcessMemoryInfoError!void {
3997+
pub 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,

0 commit comments

Comments
 (0)