summaryrefslogtreecommitdiff
path: root/src/trace/perf.zig
diff options
context:
space:
mode:
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);
+ }
}
}