this repo has no description
1const std = @import("std");
2const builtin = @import("builtin");
3const native_os = builtin.os;
4
5const args = @import("args");
6const austin = @import("austin");
7
8const util = @import("util.zig");
9
10pub const std_options = std.Options{
11 .log_level = .debug,
12 .logFn = util.logFn,
13};
14
15const Options = struct {
16 help: bool = false,
17 output: ?[]const u8 = null,
18 format: austin.Formats = .chrome,
19
20 pub const shorthands = .{
21 .h = "help",
22 .o = "output",
23 .f = "format",
24 };
25
26 pub const meta = .{
27 .name = "austin-converter",
28 .usage_summary = "[options] [input file]",
29 .option_docs = .{
30 .output = "output file (default: stdout)",
31 .format = "format to convert to (options: chrome, spall; default: chrome)",
32 .help = "",
33 },
34 };
35};
36
37var debug_allocator: std.heap.DebugAllocator(.{}) = .init;
38
39pub fn main() !void {
40 const gpa, const is_debug = gpa: {
41 if (native_os.tag == .wasi) break :gpa .{ std.heap.wasm_allocator, false };
42 break :gpa switch (builtin.mode) {
43 .Debug, .ReleaseSafe => .{ debug_allocator.allocator(), true },
44 .ReleaseFast, .ReleaseSmall => .{ std.heap.smp_allocator, false },
45 };
46 };
47 defer if (is_debug) {
48 std.debug.assert(debug_allocator.deinit() == .ok);
49 };
50
51 const options = args.parseForCurrentProcess(
52 Options,
53 gpa,
54 .print,
55 ) catch return;
56 defer options.deinit();
57
58 if (options.options.help) {
59 try args.printHelp(
60 Options,
61 Options.meta.name,
62 std.fs.File.stderr().deprecatedWriter(),
63 );
64 return;
65 }
66
67 try convert(gpa, &options);
68}
69
70fn convert(allocator: std.mem.Allocator, opts: *const args.ParseArgsResult(Options, null)) !void {
71 var progress = std.Progress.start(.{ .root_name = "Austin Converter" });
72 defer progress.end();
73
74 var parser: austin.austin.Parser = try .init(allocator);
75 var profile: austin.austin.Profile = undefined;
76 defer profile.deinit();
77
78 {
79 var node = progress.start("Parsing Austin file", 0);
80 defer node.end();
81
82 if (opts.positionals.len == 0) {
83 profile = try parser.parse(std.fs.File.stdin().deprecatedReader(), &node);
84 } else {
85 const path = std.fs.cwd().realpathAlloc(allocator, opts.positionals[0]) catch |err| {
86 std.log.err("Invalid file path ({}): {s}", .{ err, opts.positionals[0] });
87 return;
88 };
89 defer allocator.free(path);
90
91 const file = try std.fs.openFileAbsolute(path, .{});
92 defer file.close();
93
94 profile = try parser.parse(file.deprecatedReader(), &node);
95 }
96 }
97
98 for (profile.frames, 0..) |*frame, id| {
99 std.log.debug(
100 "Frame ID: {} => {{\n\tmodule = {s}\n\tfunction = {s}\n\tline number = {}\n}}\n",
101 .{ id, frame.module, frame.function, frame.line_number },
102 );
103 }
104
105 for (profile.processes, 0..) |*process, id| {
106 std.log.debug(
107 "Process ID: {} => {{\n\tPID = {}\n\tIID = {}\n\tTID = {}\n}}\n",
108 .{ id, process.pid, process.iid, process.tid },
109 );
110 }
111
112 std.log.info(
113 "num samples: {} - num frames: {} - meta: {}",
114 .{ profile.samples.len, profile.frames.len, profile.meta },
115 );
116
117 while (true) {}
118}