diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-10 11:39:20 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-10 12:19:06 -0300 |
| commit | db923fa823354270217362db06356f2b1a41315e (patch) | |
| tree | 676ad2dbfd59f0677200d85616ef1ed14d058981 /build/kernel.zig | |
| parent | a7504c6bb2ec9e906891e42bc3df28b276e67143 (diff) | |
| download | computeranim-db923fa823354270217362db06356f2b1a41315e.tar.gz computeranim-db923fa823354270217362db06356f2b1a41315e.zip | |
ztrace perf: the kernel's view of a program, unprivileged
perf_event_open on a held child: counters, a sampling profile, every
page fault with its registers, maps, threads, context switches, every
syscall (the per-syscall tracepoints, the only ones open to a user),
and the debug registers as watchpoints and breakpoints that do not stop
the target. One time-ordered stream of Events into a Sink; --threads
follows with a ring per CPU. usdt.zig: the notes of <sys/sdt.h> and
their arguments from a Regs and a memory reader, independent of BPF.
test-kernel runs all of it on targets/kernel_*.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Diffstat (limited to 'build/kernel.zig')
| -rw-r--r-- | build/kernel.zig | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/build/kernel.zig b/build/kernel.zig index d3c7eb3..48c920f 100644 --- a/build/kernel.zig +++ b/build/kernel.zig @@ -1,5 +1,28 @@ +//! The kernel area: perf events, USDT, BPF. Its targets, and its tests on them. +const std = @import("std"); const Ctx = @import("../build.zig").Ctx; pub fn add(ctx: Ctx) void { - _ = ctx; + const b = ctx.b; + const step = ctx.areaTest("test-kernel", "Perf events on real targets, USDT notes against readelf, BPF programs offline"); + + // The tests run these: they get the paths as `@import("targets")`. + const paths = b.addOptions(); + inline for (.{ + .{ "spin", &.{"kernel_spin.c"} }, + .{ "touch", &.{"kernel_touch.c"} }, + .{ "usdt", &.{ "kernel_usdt.c", "kernel_usdt_tick.c" } }, + }) |t| { + const exe = ctx.cTarget("kernel_" ++ t[0], t[1]); + paths.addOptionPath(t[0], exe.getEmittedBin()); + // ... and `zig build` leaves them in zig-out/targets to try things on. + b.getInstallStep().dependOn(&b.addInstallArtifact(exe, .{ .dest_dir = .{ .override = .{ .custom = "targets" } } }).step); + } + const tests = b.addTest(.{ .root_module = b.createModule(.{ + .root_source_file = b.path("src/trace/kernel_test.zig"), + .target = ctx.target, + .optimize = ctx.optimize, + .imports = &.{ .{ .name = "ztrace", .module = ctx.ztrace }, .{ .name = "targets", .module = paths.createModule() } }, + }) }); + step.dependOn(&b.addRunArtifact(tests).step); } |
