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 {...@@ -26,13 +26,7 @@ pub fn init_thread() !void {
26 file = try std.fs.cwd().createFile(path, .{});26 file = try std.fs.cwd().createFile(path, .{});
27 buffered_writer = std.io.bufferedWriter(file.writer());27 buffered_writer = std.io.bufferedWriter(file.writer());
2828
29 // try buffered_writer.writer().writeInt(u64, 0x0BADF00D, .Little);29 try buffered_writer.writer().writeStruct(Header{});
30 try buffered_writer.writer().writeStruct(Header{
31 .magic = magic,
32 .version = 1,
33 .timestamp_unit = 1.0,
34 .must_be_0 = 0,
35 });
36}30}
3731
38pub fn deinit_thread() void {32pub fn deinit_thread() void {
...@@ -44,32 +38,26 @@ pub fn deinit_thread() void {...@@ -44,32 +38,26 @@ pub fn deinit_thread() void {
44}38}
4539
46pub inline fn trace_begin(ctx: tracer.Ctx) void {40pub 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 };
47 buffered_writer.writer().writeStruct(BeginEvent{48 buffered_writer.writer().writeStruct(BeginEvent{
48 .type = .begin,
49 .category = 0,
50 .pid = @intCast(pid),49 .pid = @intCast(pid),
51 .tid = @intCast(tid),50 .tid = @intCast(tid),
52 .time = @floatFromInt(std.time.microTimestamp()),51 .time = @floatFromInt(std.time.microTimestamp()),
53 .name_len = @intCast(std.fmt.count("{s}:{d}:{d} ({s})", .{52 .name_len = @intCast(std.fmt.count(fmt, args)),
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 })),
59 .args_len = 0,53 .args_len = 0,
60 }) catch return;54 }) catch return;
61 buffered_writer.writer().print("{s}:{d}:{d} ({s})", .{55 buffered_writer.writer().print(fmt, args) catch return;
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;
67}56}
6857
69pub inline fn trace_end(ctx: tracer.Ctx) void {58pub inline fn trace_end(ctx: tracer.Ctx) void {
70 _ = ctx;59 _ = ctx;
71 buffered_writer.writer().writeStruct(EndEvent{60 buffered_writer.writer().writeStruct(EndEvent{
72 .type = .end,
73 .pid = @intCast(pid),61 .pid = @intCast(pid),
74 .tid = @intCast(tid),62 .tid = @intCast(tid),
75 .time = @floatFromInt(std.time.microTimestamp()),63 .time = @floatFromInt(std.time.microTimestamp()),
...@@ -92,10 +80,10 @@ const magic: u64 = 0x0BADF00D;...@@ -92,10 +80,10 @@ const magic: u64 = 0x0BADF00D;
92// must_be_0: u64,80// must_be_0: u64,
93// }81// }
94const Header = extern struct {82const Header = extern struct {
95 magic: u64 align(1),83 magic: u64 align(1) = magic,
96 version: u64 align(1),84 version: u64 align(1) = 1,
97 timestamp_unit: f64 align(1),85 timestamp_unit: f64 align(1) = 1.0,
98 must_be_0: u64 align(1),86 must_be_0: u64 align(1) = 0,
99};87};
10088
101// V1_Event_Type :: enum u8 {89// V1_Event_Type :: enum u8 {
...@@ -127,8 +115,8 @@ const EventType = enum(u8) {...@@ -127,8 +115,8 @@ const EventType = enum(u8) {
127// args_len: u8,115// args_len: u8,
128// }116// }
129const BeginEvent = extern struct {117const BeginEvent = extern struct {
130 type: EventType align(1),118 type: EventType align(1) = .begin,
131 category: u8 align(1),119 category: u8 align(1) = 0,
132 pid: u32 align(1),120 pid: u32 align(1),
133 tid: u32 align(1),121 tid: u32 align(1),
134 time: f64 align(1),122 time: f64 align(1),
...@@ -143,7 +131,7 @@ const BeginEvent = extern struct {...@@ -143,7 +131,7 @@ const BeginEvent = extern struct {
143// time: f64,131// time: f64,
144// }132// }
145const EndEvent = extern struct {133const EndEvent = extern struct {
146 type: EventType align(1),134 type: EventType align(1) = .end,
147 pid: u32 align(1),135 pid: u32 align(1),
148 tid: u32 align(1),136 tid: u32 align(1),
149 time: f64 align(1),137 time: f64 align(1),