Commit cc44183787

xEgoist <egoist@egoistic.dev>
2023-03-21 15:03:50
Implemented getMaxRss for Windows
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.
1 parent 84b89d7
Changed files (1)
lib/std/child_process.zig
@@ -99,12 +99,20 @@ pub const ChildProcess = struct {
                         return null;
                     }
                 },
+                .windows => {
+                    if (rus.rusage) |ru| {
+                        return ru.PeakWorkingSetSize;
+                    } else {
+                        return null;
+                    }
+                },
                 else => return null,
             }
         }
 
         const rusage_init = switch (builtin.os.tag) {
             .linux => @as(?std.os.rusage, null),
+            .windows => @as(?windows.PROCESS_MEMORY_COUNTERS, null),
             else => {},
         };
     };
@@ -364,6 +372,13 @@ pub const ChildProcess = struct {
             }
         });
 
+        if (self.request_resource_usage_statistics) {
+            var pmc: windows.PROCESS_MEMORY_COUNTERS = undefined;
+            if (windows.kernel32.K32GetProcessMemoryInfo(self.id, &pmc, @sizeOf(windows.PROCESS_MEMORY_COUNTERS)) != 0) {
+                self.resource_usage_statistics.rusage = pmc;
+            }
+        }
+
         os.close(self.id);
         os.close(self.thread_handle);
         self.cleanupStreams();