authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-09-21 01:32:16 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-09-21 01:32:16 -07:00
logbf4bf92cb2914c4b451e2aec44b04d2fffd643af
treebdc8941bc3f6f43b3737acb6571a1bc6e5765162
parent2c9c3f2ce69ec673df72ccad72efb15716dfb980

spall: tidy and add default fields


1 files changed, 17 insertions(+), 29 deletions(-)

src/spall.zig+17-29
......@@ -26,13 +26,7 @@ pub fn init_thread() !void {
2626 file = try std.fs.cwd().createFile(path, .{});
2727 buffered_writer = std.io.bufferedWriter(file.writer());
2828
29 // try buffered_writer.writer().writeInt(u64, 0x0BADF00D, .Little);
30 try buffered_writer.writer().writeStruct(Header{
31 .magic = magic,
32 .version = 1,
33 .timestamp_unit = 1.0,
34 .must_be_0 = 0,
35 });
29 try buffered_writer.writer().writeStruct(Header{});
3630}
3731
3832pub fn deinit_thread() void {
......@@ -44,32 +38,26 @@ pub fn deinit_thread() void {
4438}
4539
4640pub inline fn trace_begin(ctx: tracer.Ctx) void {
41 const fmt = "{s}:{d}:{d} ({s})";
42 const args = .{
43 if (ctx.src.file[0] == '/') ctx.src.file[trim_count..] else ctx.src.file,
44 ctx.src.line,
45 ctx.src.column,
46 ctx.src.fn_name,
47 };
4748 buffered_writer.writer().writeStruct(BeginEvent{
48 .type = .begin,
49 .category = 0,
5049 .pid = @intCast(pid),
5150 .tid = @intCast(tid),
5251 .time = @floatFromInt(std.time.microTimestamp()),
53 .name_len = @intCast(std.fmt.count("{s}:{d}:{d} ({s})", .{
54 if (ctx.src.file[0] == '/') ctx.src.file[trim_count..] else ctx.src.file,
55 ctx.src.line,
56 ctx.src.column,
57 ctx.src.fn_name,
58 })),
52 .name_len = @intCast(std.fmt.count(fmt, args)),
5953 .args_len = 0,
6054 }) catch return;
61 buffered_writer.writer().print("{s}:{d}:{d} ({s})", .{
62 if (ctx.src.file[0] == '/') ctx.src.file[trim_count..] else ctx.src.file,
63 ctx.src.line,
64 ctx.src.column,
65 ctx.src.fn_name,
66 }) catch return;
55 buffered_writer.writer().print(fmt, args) catch return;
6756}
6857
6958pub inline fn trace_end(ctx: tracer.Ctx) void {
7059 _ = ctx;
7160 buffered_writer.writer().writeStruct(EndEvent{
72 .type = .end,
7361 .pid = @intCast(pid),
7462 .tid = @intCast(tid),
7563 .time = @floatFromInt(std.time.microTimestamp()),
......@@ -92,10 +80,10 @@ const magic: u64 = 0x0BADF00D;
9280// must_be_0: u64,
9381// }
9482const Header = extern struct {
95 magic: u64 align(1),
96 version: u64 align(1),
97 timestamp_unit: f64 align(1),
98 must_be_0: u64 align(1),
83 magic: u64 align(1) = magic,
84 version: u64 align(1) = 1,
85 timestamp_unit: f64 align(1) = 1.0,
86 must_be_0: u64 align(1) = 0,
9987};
10088
10189// V1_Event_Type :: enum u8 {
......@@ -127,8 +115,8 @@ const EventType = enum(u8) {
127115// args_len: u8,
128116// }
129117const BeginEvent = extern struct {
130 type: EventType align(1),
131 category: u8 align(1),
118 type: EventType align(1) = .begin,
119 category: u8 align(1) = 0,
132120 pid: u32 align(1),
133121 tid: u32 align(1),
134122 time: f64 align(1),
......@@ -143,7 +131,7 @@ const BeginEvent = extern struct {
143131// time: f64,
144132// }
145133const EndEvent = extern struct {
146 type: EventType align(1),
134 type: EventType align(1) = .end,
147135 pid: u32 align(1),
148136 tid: u32 align(1),
149137 time: f64 align(1),