1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
//! 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, .{});
}
|