| author | |
| committer | |
| log | bf867fae9d292da271537c7f9c7fcbc6848fb50a |
| tree | 52d00402948ecfa9baef08a7e35f92090703edc3 |
| parent | c42ff8d7185789845d5986af43aa66f9fdd90c5a |
| signature |
5 files changed, 23 insertions(+), 19 deletions(-)
src/chrome.zig+7-5| ... | @@ -42,7 +42,7 @@ pub fn deinit_thread() void { | ... | @@ -42,7 +42,7 @@ pub fn deinit_thread() void { |
| 42 | buffered_writer.flush() catch {}; | 42 | buffered_writer.flush() catch {}; |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: anytype) void { | 45 | pub inline fn trace_begin(src: std.builtin.SourceLocation, comptime ifmt: []const u8, iargs: anytype) void { |
| 46 | buffered_writer.print( | 46 | buffered_writer.print( |
| 47 | \\{{"cat":"function", "name":"{s}:{d}:{d} ({s}) | 47 | \\{{"cat":"function", "name":"{s}:{d}:{d} ({s}) |
| 48 | ++ ifmt ++ | 48 | ++ ifmt ++ |
| ... | @@ -50,10 +50,10 @@ pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: any | ... | @@ -50,10 +50,10 @@ pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: any |
| 50 | \\ | 50 | \\ |
| 51 | , | 51 | , |
| 52 | .{ | 52 | .{ |
| 53 | ctx.src.file, | 53 | src.file, |
| 54 | ctx.src.line, | 54 | src.line, |
| 55 | ctx.src.column, | 55 | src.column, |
| 56 | ctx.src.fn_name, | 56 | src.fn_name, |
| 57 | } ++ iargs ++ .{ | 57 | } ++ iargs ++ .{ |
| 58 | pid, | 58 | pid, |
| 59 | tid, | 59 | tid, |
| ... | @@ -75,3 +75,5 @@ pub inline fn trace_end(ctx: tracer.Ctx) void { | ... | @@ -75,3 +75,5 @@ pub inline fn trace_end(ctx: tracer.Ctx) void { |
| 75 | }, | 75 | }, |
| 76 | ) catch {}; | 76 | ) catch {}; |
| 77 | } | 77 | } |
| 78 | |||
| 79 | pub const Data = void; |
src/log.zig+4-2| ... | @@ -14,10 +14,12 @@ pub fn init_thread(args: struct {}) !void { | ... | @@ -14,10 +14,12 @@ pub fn init_thread(args: struct {}) !void { |
| 14 | 14 | ||
| 15 | pub fn deinit_thread() void {} | 15 | pub fn deinit_thread() void {} |
| 16 | 16 | ||
| 17 | pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: anytype) void { | 17 | pub inline fn trace_begin(src: std.builtin.SourceLocation, comptime ifmt: []const u8, iargs: anytype) void { |
| 18 | log.debug("{s}:{d}:{d} ({s})" ++ ifmt, .{ ctx.src.file, ctx.src.line, ctx.src.column, ctx.src.fn_name } ++ iargs); | 18 | log.debug("{s}:{d}:{d} ({s})" ++ ifmt, .{ src.file, src.line, src.column, src.fn_name } ++ iargs); |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | pub inline fn trace_end(ctx: tracer.Ctx) void { | 21 | pub inline fn trace_end(ctx: tracer.Ctx) void { |
| 22 | _ = ctx; | 22 | _ = ctx; |
| 23 | } | 23 | } |
| 24 | |||
| 25 | pub const Data = void; |
src/mod.zig+4-8| ... | @@ -4,8 +4,6 @@ const extras = @import("extras"); | ... | @@ -4,8 +4,6 @@ const extras = @import("extras"); |
| 4 | const nfs = @import("nfs"); | 4 | const nfs = @import("nfs"); |
| 5 | const impl = extras.globalOption("tracer_impl", type) orelse none; | 5 | const impl = extras.globalOption("tracer_impl", type) orelse none; |
| 6 | 6 | ||
| 7 | threadlocal var started = false; | ||
| 8 | |||
| 9 | pub const none = @import("./none.zig"); | 7 | pub const none = @import("./none.zig"); |
| 10 | pub const log = @import("./log.zig"); | 8 | pub const log = @import("./log.zig"); |
| 11 | pub const chrome = @import("./chrome.zig"); | 9 | pub const chrome = @import("./chrome.zig"); |
| ... | @@ -21,26 +19,24 @@ pub fn deinit() void { | ... | @@ -21,26 +19,24 @@ pub fn deinit() void { |
| 21 | 19 | ||
| 22 | pub fn init_thread(args: @typeInfo(@TypeOf(impl.init_thread)).@"fn".params[0].type.?) !void { | 20 | pub fn init_thread(args: @typeInfo(@TypeOf(impl.init_thread)).@"fn".params[0].type.?) !void { |
| 23 | try impl.init_thread(args); | 21 | try impl.init_thread(args); |
| 24 | started = true; | ||
| 25 | } | 22 | } |
| 26 | 23 | ||
| 27 | pub fn deinit_thread() void { | 24 | pub fn deinit_thread() void { |
| 28 | impl.deinit_thread(); | 25 | impl.deinit_thread(); |
| 29 | started = false; | ||
| 30 | } | 26 | } |
| 31 | 27 | ||
| 32 | pub inline fn trace(src: std.builtin.SourceLocation, comptime fmt: []const u8, args: anytype) Ctx { | 28 | pub inline fn trace(src: std.builtin.SourceLocation, comptime fmt: []const u8, args: anytype) Ctx { |
| 33 | const ctx = Ctx{ | 29 | return .{ |
| 34 | .src = src, | 30 | .src = src, |
| 31 | .data = impl.trace_begin(src, fmt, args), | ||
| 35 | }; | 32 | }; |
| 36 | if (started) impl.trace_begin(ctx, fmt, args); | ||
| 37 | return ctx; | ||
| 38 | } | 33 | } |
| 39 | 34 | ||
| 40 | pub const Ctx = struct { | 35 | pub const Ctx = struct { |
| 41 | src: std.builtin.SourceLocation, | 36 | src: std.builtin.SourceLocation, |
| 37 | data: impl.Data, | ||
| 42 | 38 | ||
| 43 | pub inline fn end(self: Ctx) void { | 39 | pub inline fn end(self: Ctx) void { |
| 44 | if (started) impl.trace_end(self); | 40 | impl.trace_end(self); |
| 45 | } | 41 | } |
| 46 | }; | 42 | }; |
src/none.zig+4-2| ... | @@ -14,8 +14,8 @@ pub fn init_thread(args: struct {}) !void { | ... | @@ -14,8 +14,8 @@ pub fn init_thread(args: struct {}) !void { |
| 14 | 14 | ||
| 15 | pub fn deinit_thread() void {} | 15 | pub fn deinit_thread() void {} |
| 16 | 16 | ||
| 17 | pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: anytype) void { | 17 | pub inline fn trace_begin(src: std.builtin.SourceLocation, comptime ifmt: []const u8, iargs: anytype) void { |
| 18 | _ = ctx; | 18 | _ = src; |
| 19 | _ = ifmt; | 19 | _ = ifmt; |
| 20 | _ = iargs; | 20 | _ = iargs; |
| 21 | } | 21 | } |
| ... | @@ -23,3 +23,5 @@ pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: any | ... | @@ -23,3 +23,5 @@ pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: any |
| 23 | pub inline fn trace_end(ctx: tracer.Ctx) void { | 23 | pub inline fn trace_end(ctx: tracer.Ctx) void { |
| 24 | _ = ctx; | 24 | _ = ctx; |
| 25 | } | 25 | } |
| 26 | |||
| 27 | pub const Data = void; |
src/spall.zig+4-2| ... | @@ -41,9 +41,9 @@ pub fn deinit_thread() void { | ... | @@ -41,9 +41,9 @@ pub fn deinit_thread() void { |
| 41 | buffered_writer.flush() catch {}; | 41 | buffered_writer.flush() catch {}; |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: anytype) void { | 44 | pub inline fn trace_begin(src: std.builtin.SourceLocation, comptime ifmt: []const u8, iargs: anytype) void { |
| 45 | const fmt = "{s}:{d}:{d} ({s})" ++ ifmt; | 45 | const fmt = "{s}:{d}:{d} ({s})" ++ ifmt; |
| 46 | const args = .{ ctx.src.file, ctx.src.line, ctx.src.column, ctx.src.fn_name }; | 46 | const args = .{ src.file, src.line, src.column, src.fn_name }; |
| 47 | buffered_writer.writeStruct(BeginEvent{ | 47 | buffered_writer.writeStruct(BeginEvent{ |
| 48 | .pid = @intCast(pid), | 48 | .pid = @intCast(pid), |
| 49 | .tid = @intCast(tid), | 49 | .tid = @intCast(tid), |
| ... | @@ -63,6 +63,8 @@ pub inline fn trace_end(ctx: tracer.Ctx) void { | ... | @@ -63,6 +63,8 @@ pub inline fn trace_end(ctx: tracer.Ctx) void { |
| 63 | }) catch return; | 63 | }) catch return; |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | pub const Data = void; | ||
| 67 | |||
| 66 | // https://github.com/colrdavidson/spall-web/blob/1d4610a1fe9aaaf2e071327a1142a498f3436bdc/formats/spall/spall.odin | 68 | // https://github.com/colrdavidson/spall-web/blob/1d4610a1fe9aaaf2e071327a1142a498f3436bdc/formats/spall/spall.odin |
| 67 | // https://github.com/colrdavidson/spall-web/blob/1d4610a1fe9aaaf2e071327a1142a498f3436bdc/tools/json2bin/json2bin.odin | 69 | // https://github.com/colrdavidson/spall-web/blob/1d4610a1fe9aaaf2e071327a1142a498f3436bdc/tools/json2bin/json2bin.odin |
| 68 | // https://github.com/colrdavidson/spall-web/blob/1d4610a1fe9aaaf2e071327a1142a498f3436bdc/tools/upconvert/main.odin | 70 | // https://github.com/colrdavidson/spall-web/blob/1d4610a1fe9aaaf2e071327a1142a498f3436bdc/tools/upconvert/main.odin |