authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-12-03 03:30:06+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-12-04 03:46:36+01:00
log9eed87f93ea9afeb16bede0b3c162a7055d89a76
treef4d34763d1f2cf553854697423166892657073c1
parente270c97ed119fb179bf0156caad6c6ea31453bd5
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.process.Child: enable rusage collection for freebsd, illumos, serenity


1 files changed, 25 insertions(+), 3 deletions(-)

lib/std/process/Child.zig+25-3
...@@ -122,7 +122,7 @@ pub const ResourceUsageStatistics = struct {...@@ -122,7 +122,7 @@ pub const ResourceUsageStatistics = struct {
122 /// if available.122 /// if available.
123 pub inline fn getMaxRss(rus: ResourceUsageStatistics) ?usize {123 pub inline fn getMaxRss(rus: ResourceUsageStatistics) ?usize {
124 switch (native_os) {124 switch (native_os) {
125 .linux => {125 .freebsd, .illumos, .linux, .serenity => {
126 if (rus.rusage) |ru| {126 if (rus.rusage) |ru| {
127 return @as(usize, @intCast(ru.maxrss)) * 1024;127 return @as(usize, @intCast(ru.maxrss)) * 1024;
128 } else {128 } else {
...@@ -149,7 +149,18 @@ pub const ResourceUsageStatistics = struct {...@@ -149,7 +149,18 @@ pub const ResourceUsageStatistics = struct {
149 }149 }
150150
151 const rusage_init = switch (native_os) {151 const rusage_init = switch (native_os) {
152 .linux, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => @as(?posix.rusage, null),152 .freebsd,
153 .illumos,
154 .linux,
155 .serenity,
156 .driverkit,
157 .ios,
158 .maccatalyst,
159 .macos,
160 .tvos,
161 .visionos,
162 .watchos,
163 => @as(?posix.rusage, null),
153 .windows => @as(?windows.VM_COUNTERS, null),164 .windows => @as(?windows.VM_COUNTERS, null),
154 else => {},165 else => {},
155 };166 };
...@@ -486,7 +497,18 @@ fn waitUnwrappedPosix(self: *ChildProcess) void {...@@ -486,7 +497,18 @@ fn waitUnwrappedPosix(self: *ChildProcess) void {
486 const res: posix.WaitPidResult = res: {497 const res: posix.WaitPidResult = res: {
487 if (self.request_resource_usage_statistics) {498 if (self.request_resource_usage_statistics) {
488 switch (native_os) {499 switch (native_os) {
489 .linux, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => {500 .freebsd,
501 .illumos,
502 .linux,
503 .serenity,
504 .driverkit,
505 .ios,
506 .maccatalyst,
507 .macos,
508 .tvos,
509 .visionos,
510 .watchos,
511 => {
490 var ru: posix.rusage = undefined;512 var ru: posix.rusage = undefined;
491 const res = posix.wait4(self.id, 0, &ru);513 const res = posix.wait4(self.id, 0, &ru);
492 self.resource_usage_statistics.rusage = ru;514 self.resource_usage_statistics.rusage = ru;