//! 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"), .show = @import("show.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 \\ show print a recording's summary, or the program's state at a moment \\ \\`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, .{}); }