summaryrefslogtreecommitdiff
path: root/test/perf.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/perf.zig')
-rw-r--r--test/perf.zig50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/perf.zig b/test/perf.zig
index 4793da78..31a48cc7 100644
--- a/test/perf.zig
+++ b/test/perf.zig
@@ -1138,10 +1138,56 @@ fn liveSetup(io: std.Io) !Live {
}
fn liveCleanup(io: std.Io, l: *Live) void {
+ liveSweep(io);
std.Io.Dir.cwd().deleteTree(io, l.dir) catch {};
if (std.c.getenv("XDG_RUNTIME_DIR")) |run| std.Io.Dir.cwd().deleteTree(io, std.mem.span(run)) catch {};
}
+/// Every process a live run started that is still there, ended: a tty stub
+/// killed since phase 3 detaches its session rather than ending it, and an
+/// exe that is a wrapper may start sessions of its own (`--detach`). Each
+/// inherited the run's private runtime directory, which no other process
+/// has: TERM, then KILL what is left. After every cell, and in the cleanup
+/// every path takes.
+fn liveSweep(io: std.Io) void {
+ const run = std.mem.span(std.c.getenv("XDG_RUNTIME_DIR") orelse return);
+ var want_buf: [512]u8 = undefined;
+ const want = std.fmt.bufPrint(&want_buf, "XDG_RUNTIME_DIR={s}", .{run}) catch return;
+ const env = gpa.alloc(u8, 1 << 20) catch return;
+ defer gpa.free(env);
+ const self = libc.getpid();
+ for ([_]@TypeOf(libc.SIG.TERM){ .TERM, .KILL }) |sig| {
+ var left: usize = 0;
+ var proc = std.Io.Dir.cwd().openDir(io, "/proc", .{ .iterate = true }) catch return;
+ defer proc.close(io);
+ var it = proc.iterate();
+ while (it.next(io) catch null) |entry| {
+ const pid = std.fmt.parseInt(libc.pid_t, entry.name, 10) catch continue;
+ if (pid == self) continue;
+ var path_buf: [64]u8 = undefined;
+ const path = std.fmt.bufPrintSentinel(&path_buf, "/proc/{d}/environ", .{pid}, 0) catch continue;
+ const fd = libc.open(path, .{ .ACCMODE = .RDONLY });
+ if (fd < 0) continue;
+ var n: usize = 0;
+ while (n < env.len) {
+ const got = libc.read(fd, env.ptr + n, env.len - n);
+ if (got <= 0) break;
+ n += @intCast(got);
+ }
+ _ = libc.close(fd);
+ var vars = std.mem.splitScalar(u8, env[0..n], 0);
+ while (vars.next()) |v| if (std.mem.eql(u8, v, want)) {
+ _ = libc.kill(pid, sig);
+ left += 1;
+ break;
+ };
+ }
+ if (left == 0) return;
+ // A session ends on TERM (it detaches nothing then): a moment for it.
+ if (sig == .TERM) io.sleep(.fromMilliseconds(300), .awake) catch {};
+ }
+}
+
/// The bytes a terminal sends for a step of FrameStats.keys.
fn stepBytes(buf: *[32]u8, step: pardes.FrameStats.Step) []const u8 {
return switch (step.act) {
@@ -1331,11 +1377,15 @@ fn measureLive(io: std.Io, exe: []const u8, gui: bool, reps: usize, json: bool)
for (0..reps) |_| {
if (gui) {
try liveKeysGui(&l, exe_z);
+ liveSweep(io);
continue;
}
try liveKeysTty(&l, exe_z);
+ liveSweep(io);
try liveYes(&l, exe_z);
+ liveSweep(io);
try liveOpen(&l, exe_z);
+ liveSweep(io);
}
const frontend = if (gui) "gui" else "tty";
const out = std.Io.File.stdout();