diff --git a/src/chrome.zig b/src/chrome.zig index db54400d5ebfe61c19d3836de084c39683e1b33b..c58a4a4b939ac6d7ffbd8fb4e71966ce35f0a878 100644 --- a/src/chrome.zig +++ b/src/chrome.zig @@ -42,7 +42,7 @@ pub fn deinit_thread() void { buffered_writer.flush() catch {}; } -pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: anytype) void { +pub inline fn trace_begin(src: std.builtin.SourceLocation, comptime ifmt: []const u8, iargs: anytype) void { buffered_writer.print( \\{{"cat":"function", "name":"{s}:{d}:{d} ({s}) ++ ifmt ++ @@ -50,10 +50,10 @@ pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: any \\ , .{ - ctx.src.file, - ctx.src.line, - ctx.src.column, - ctx.src.fn_name, + src.file, + src.line, + src.column, + src.fn_name, } ++ iargs ++ .{ pid, tid, @@ -75,3 +75,5 @@ pub inline fn trace_end(ctx: tracer.Ctx) void { }, ) catch {}; } + +pub const Data = void; diff --git a/src/log.zig b/src/log.zig index 5eb0b88e55e8b9e3a570f4cc4cc9e5bd5ca12f52..3bd006c2a6ed8c4215b36af6e79ac45e05e5bab4 100644 --- a/src/log.zig +++ b/src/log.zig @@ -14,10 +14,12 @@ pub fn init_thread(args: struct {}) !void { pub fn deinit_thread() void {} -pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: anytype) void { - log.debug("{s}:{d}:{d} ({s})" ++ ifmt, .{ ctx.src.file, ctx.src.line, ctx.src.column, ctx.src.fn_name } ++ iargs); +pub inline fn trace_begin(src: std.builtin.SourceLocation, comptime ifmt: []const u8, iargs: anytype) void { + log.debug("{s}:{d}:{d} ({s})" ++ ifmt, .{ src.file, src.line, src.column, src.fn_name } ++ iargs); } pub inline fn trace_end(ctx: tracer.Ctx) void { _ = ctx; } + +pub const Data = void; diff --git a/src/mod.zig b/src/mod.zig index ba675c05440cad2ceeb77f6f18230e6e3b21537a..5676eb5928b145fe066386adc46a5c79598d5dc8 100644 --- a/src/mod.zig +++ b/src/mod.zig @@ -4,8 +4,6 @@ const extras = @import("extras"); const nfs = @import("nfs"); const impl = extras.globalOption("tracer_impl", type) orelse none; -threadlocal var started = false; - pub const none = @import("./none.zig"); pub const log = @import("./log.zig"); pub const chrome = @import("./chrome.zig"); @@ -21,26 +19,24 @@ pub fn deinit() void { pub fn init_thread(args: @typeInfo(@TypeOf(impl.init_thread)).@"fn".params[0].type.?) !void { try impl.init_thread(args); - started = true; } pub fn deinit_thread() void { impl.deinit_thread(); - started = false; } pub inline fn trace(src: std.builtin.SourceLocation, comptime fmt: []const u8, args: anytype) Ctx { - const ctx = Ctx{ + return .{ .src = src, + .data = impl.trace_begin(src, fmt, args), }; - if (started) impl.trace_begin(ctx, fmt, args); - return ctx; } pub const Ctx = struct { src: std.builtin.SourceLocation, + data: impl.Data, pub inline fn end(self: Ctx) void { - if (started) impl.trace_end(self); + impl.trace_end(self); } }; diff --git a/src/none.zig b/src/none.zig index e9034a9e3b978fa44ce3b6b2220a89c4305754ff..842ca9f741985f73f461982219bdf0b95f4be788 100644 --- a/src/none.zig +++ b/src/none.zig @@ -14,8 +14,8 @@ pub fn init_thread(args: struct {}) !void { pub fn deinit_thread() void {} -pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: anytype) void { - _ = ctx; +pub inline fn trace_begin(src: std.builtin.SourceLocation, comptime ifmt: []const u8, iargs: anytype) void { + _ = src; _ = ifmt; _ = iargs; } @@ -23,3 +23,5 @@ pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: any pub inline fn trace_end(ctx: tracer.Ctx) void { _ = ctx; } + +pub const Data = void; diff --git a/src/spall.zig b/src/spall.zig index 406c9e1c996cb5420971116b43b3e52a2da57705..1ed28330f3084366d199950997adb45e840bc676 100644 --- a/src/spall.zig +++ b/src/spall.zig @@ -41,9 +41,9 @@ pub fn deinit_thread() void { buffered_writer.flush() catch {}; } -pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: anytype) void { +pub inline fn trace_begin(src: std.builtin.SourceLocation, comptime ifmt: []const u8, iargs: anytype) void { const fmt = "{s}:{d}:{d} ({s})" ++ ifmt; - const args = .{ ctx.src.file, ctx.src.line, ctx.src.column, ctx.src.fn_name }; + const args = .{ src.file, src.line, src.column, src.fn_name }; buffered_writer.writeStruct(BeginEvent{ .pid = @intCast(pid), .tid = @intCast(tid), @@ -63,6 +63,8 @@ pub inline fn trace_end(ctx: tracer.Ctx) void { }) catch return; } +pub const Data = void; + // https://github.com/colrdavidson/spall-web/blob/1d4610a1fe9aaaf2e071327a1142a498f3436bdc/formats/spall/spall.odin // https://github.com/colrdavidson/spall-web/blob/1d4610a1fe9aaaf2e071327a1142a498f3436bdc/tools/json2bin/json2bin.odin // https://github.com/colrdavidson/spall-web/blob/1d4610a1fe9aaaf2e071327a1142a498f3436bdc/tools/upconvert/main.odin