| ... | ... | @@ -26,13 +26,7 @@ pub fn init_thread() !void { |
| 26 | 26 | file = try std.fs.cwd().createFile(path, .{}); |
| 27 | 27 | buffered_writer = std.io.bufferedWriter(file.writer()); |
| 28 | 28 | |
| 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{}); |
| 36 | 30 | } |
| 37 | 31 | |
| 38 | 32 | pub fn deinit_thread() void { |
| ... | ... | @@ -44,32 +38,26 @@ pub fn deinit_thread() void { |
| 44 | 38 | } |
| 45 | 39 | |
| 46 | 40 | pub 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 | 48 | buffered_writer.writer().writeStruct(BeginEvent{ |
| 48 | | .type = .begin, |
| 49 | | .category = 0, |
| 50 | 49 | .pid = @intCast(pid), |
| 51 | 50 | .tid = @intCast(tid), |
| 52 | 51 | .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)), |
| 59 | 53 | .args_len = 0, |
| 60 | 54 | }) 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; |
| 67 | 56 | } |
| 68 | 57 | |
| 69 | 58 | pub inline fn trace_end(ctx: tracer.Ctx) void { |
| 70 | 59 | _ = ctx; |
| 71 | 60 | buffered_writer.writer().writeStruct(EndEvent{ |
| 72 | | .type = .end, |
| 73 | 61 | .pid = @intCast(pid), |
| 74 | 62 | .tid = @intCast(tid), |
| 75 | 63 | .time = @floatFromInt(std.time.microTimestamp()), |
| ... | ... | @@ -92,10 +80,10 @@ const magic: u64 = 0x0BADF00D; |
| 92 | 80 | // must_be_0: u64, |
| 93 | 81 | // } |
| 94 | 82 | const 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, |
| 99 | 87 | }; |
| 100 | 88 | |
| 101 | 89 | // V1_Event_Type :: enum u8 { |
| ... | ... | @@ -127,8 +115,8 @@ const EventType = enum(u8) { |
| 127 | 115 | // args_len: u8, |
| 128 | 116 | // } |
| 129 | 117 | const 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, |
| 132 | 120 | pid: u32 align(1), |
| 133 | 121 | tid: u32 align(1), |
| 134 | 122 | time: f64 align(1), |
| ... | ... | @@ -143,7 +131,7 @@ const BeginEvent = extern struct { |
| 143 | 131 | // time: f64, |
| 144 | 132 | // } |
| 145 | 133 | const EndEvent = extern struct { |
| 146 | | type: EventType align(1), |
| 134 | type: EventType align(1) = .end, |
| 147 | 135 | pid: u32 align(1), |
| 148 | 136 | tid: u32 align(1), |
| 149 | 137 | time: f64 align(1), |