summaryrefslogtreecommitdiff
path: root/src/trace/perf.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-10 12:17:50 -0300
committerGabriel Schneider <[email protected]>2026-11-10 12:19:28 -0300
commit2e01933dc5c0c1903c1b7f86e453829fee9a541b (patch)
treee3f1599a7c7bfafc4ebbc6a0b13e0134b4436706 /src/trace/perf.zig
parent297943b01e18bb3d1dd41a8d3e220811de25228b (diff)
downloadcomputeranim-2e01933dc5c0c1903c1b7f86e453829fee9a541b.tar.gz
computeranim-2e01933dc5c0c1903c1b7f86e453829fee9a541b.zip
kernel: smaller BPF records, syscall tracepoints sorted out in place, the README
Syscall entries and kprobes send the event alone (a kernel function's registers are not the thread's; a syscall's are its arguments), a probe's event is not inherited (it failed the target's clone). The per-syscall tracepoints are told entry from exit on the events themselves, not on a second set. The VM has two CPUs and a time limit. README: the kernel's view, with what each mode costs. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Diffstat (limited to 'src/trace/perf.zig')
-rw-r--r--src/trace/perf.zig18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/trace/perf.zig b/src/trace/perf.zig
index c251741..36eaaf8 100644
--- a/src/trace/perf.zig
+++ b/src/trace/perf.zig
@@ -281,17 +281,19 @@ pub const Session = struct {
}
// shortcut: ids below 4096; scan further if a kernel has more trace events than that.
for (0..4096) |id| {
- var attr: linux.perf_event_attr = .{ .type = .TRACEPOINT, .config = id, .sample_period_or_freq = 1, .sample_type = PERF.SAMPLE.RAW };
- // Only a syscall's exit has a field `ret`: a filter on it is
- // accepted there and nowhere else. On an event of its own, since
- // a filter cannot be taken off again.
- const probe = perfOpen(&attr, s.pid, -1) catch |err| switch (err) {
+ s.add(.{ .type = .TRACEPOINT, .config = id, .sample_period_or_freq = 1, .sample_type = PERF.SAMPLE.RAW }, .syscall_enter) catch |err| switch (err) {
error.PerfAccess, error.PerfNoSuchEvent => continue,
else => |e| return e,
};
- const is_exit = linux.errno(linux.ioctl(probe, PERF.EVENT_IOC.SET_FILTER, @intFromPtr("ret==0"))) == .SUCCESS;
- _ = linux.close(probe);
- try s.add(attr, if (is_exit) .syscall_exit else .syscall_enter);
+ // Entry or exit? Only an exit has a field `ret`: a filter on it
+ // is accepted there and nowhere else. It cannot be taken off
+ // again, so it is one that every exit passes.
+ for (s.fds.items[s.fds.items.len - s.rings.len ..]) |fd| {
+ if (linux.errno(linux.ioctl(fd, PERF.EVENT_IOC.SET_FILTER, @intFromPtr("ret >= 0 || ret < 0"))) != .SUCCESS) break;
+ var event_id: u64 = 0;
+ _ = linux.ioctl(fd, PERF.EVENT_IOC.ID, @intFromPtr(&event_id));
+ try s.sources.put(s.gpa, event_id, .syscall_exit);
+ }
}
}