//! 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"), .dbg = @import("dbg.zig"), .run = @import("run.zig"), .perf = @import("perf.zig"), .probe = @import("probe.zig"), .dump = @import("dump.zig"), .show = @import("show.zig"), .cc = @import("cc.zig"), }; const usage = \\usage: ztrace COMMAND ... \\ \\ record run a program under ptrace into a recording \\ dbg debug a program, recording it: step, break, look, go back \\ run record a program that carries a ring producer (agent, instrumentation) \\ perf record what the kernel sees of a program at full speed (perf events) \\ probe ... with BPF programs on syscalls, scheduling, kprobes, uprobes, USDT (root) \\ dump print a recording's events \\ show print a recording's summary, or the program's state at a moment \\ cc compile a program with instrumentation that records it \\ \\`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, .{}); }