| ... | @@ -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()); |
| 28 | | 28 | |
| 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 | } |
| 37 | | 31 | |
| 38 | pub fn deinit_thread() void { | 32 | pub fn deinit_thread() void { |
| ... | @@ -44,32 +38,26 @@ pub fn deinit_thread() void { | ... | @@ -44,32 +38,26 @@ pub fn deinit_thread() void { |
| 44 | } | 38 | } |
| 45 | | 39 | |
| 46 | pub inline fn trace_begin(ctx: tracer.Ctx) void { | 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 | 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 | } |
| 68 | | 57 | |
| 69 | pub inline fn trace_end(ctx: tracer.Ctx) void { | 58 | pub 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 | // } |
| 94 | const Header = extern struct { | 82 | const 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 | }; |
| 100 | | 88 | |
| 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 | // } |
| 129 | const BeginEvent = extern struct { | 117 | const 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 | // } |
| 145 | const EndEvent = extern struct { | 133 | const 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), |