summaryrefslogtreecommitdiff
path: root/src/cli/main.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-10 11:08:49 -0300
committerGabriel Schneider <[email protected]>2026-11-10 11:08:49 -0300
commit0b29354e1ddf6cf75ac4c426a00dd3435ace5069 (patch)
tree918e6f6810a9b8b5a8ed17e698085e92018333b9 /src/cli/main.zig
downloadcomputeranim-0b29354e1ddf6cf75ac4c426a00dd3435ace5069.tar.gz
computeranim-0b29354e1ddf6cf75ac4c426a00dd3435ace5069.zip
ztrace: the event, the ring, the recording, a ptrace loop
One 64-byte Event for every backend; a shared-memory ring from target to tracer with stop/resume; a Recorder that folds events into xitdb moments (registers, memory in 64-byte chunks with known-byte masks, strings) and a Trace that reads any moment back; a minimal ptrace Process; ztrace record, run and dump. Per-area build files so the areas grow apart.
Diffstat (limited to 'src/cli/main.zig')
-rw-r--r--src/cli/main.zig37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/cli/main.zig b/src/cli/main.zig
new file mode 100644
index 0000000..498f8d4
--- /dev/null
+++ b/src/cli/main.zig
@@ -0,0 +1,37 @@
+//! ztrace: many ways to watch a program, one recording.
+const std = @import("std");
+const util = @import("util.zig");
+
+/// A command is a file with `usage` and `run(init, args)`.
+const commands = .{
+ .record = @import("record.zig"),
+ .run = @import("run.zig"),
+ .dump = @import("dump.zig"),
+};
+
+const usage =
+ \\usage: ztrace COMMAND ...
+ \\
+ \\ record run a program under ptrace into a recording
+ \\ run record a program that carries a ring producer (agent, instrumentation)
+ \\ dump print a recording's events
+ \\
+ \\`ztrace COMMAND --help` for each.
+ \\
+;
+
+pub fn main(init: std.process.Init) !void {
+ const args = try init.minimal.args.toSlice(init.arena.allocator());
+ if (args.len < 2) util.fail(usage, .{});
+ inline for (@typeInfo(@TypeOf(commands)).@"struct".field_names) |name| {
+ if (std.mem.eql(u8, args[1], name)) {
+ const command = @field(commands, name);
+ if (args.len > 2 and std.mem.eql(u8, args[2], "--help")) {
+ std.debug.print("{s}", .{command.usage});
+ return;
+ }
+ return command.run(init, args[2..]);
+ }
+ }
+ util.fail(usage, .{});
+}