authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-04-27 20:58:58 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-04-27 20:59:51 -07:00
logbf867fae9d292da271537c7f9c7fcbc6848fb50a
tree52d00402948ecfa9baef08a7e35f92090703edc3
parentc42ff8d7185789845d5986af43aa66f9fdd90c5a
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

rework a bit for better flexibility


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}
4444
45pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: anytype) void {45pub 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
79pub 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 {
1414
15pub fn deinit_thread() void {}15pub fn deinit_thread() void {}
1616
17pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: anytype) void {17pub 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}
2020
21pub inline fn trace_end(ctx: tracer.Ctx) void {21pub inline fn trace_end(ctx: tracer.Ctx) void {
22 _ = ctx;22 _ = ctx;
23}23}
24
25pub const Data = void;
src/mod.zig+4-8
...@@ -4,8 +4,6 @@ const extras = @import("extras");...@@ -4,8 +4,6 @@ const extras = @import("extras");
4const nfs = @import("nfs");4const nfs = @import("nfs");
5const impl = extras.globalOption("tracer_impl", type) orelse none;5const impl = extras.globalOption("tracer_impl", type) orelse none;
66
7threadlocal var started = false;
8
9pub const none = @import("./none.zig");7pub const none = @import("./none.zig");
10pub const log = @import("./log.zig");8pub const log = @import("./log.zig");
11pub const chrome = @import("./chrome.zig");9pub const chrome = @import("./chrome.zig");
...@@ -21,26 +19,24 @@ pub fn deinit() void {...@@ -21,26 +19,24 @@ pub fn deinit() void {
2119
22pub fn init_thread(args: @typeInfo(@TypeOf(impl.init_thread)).@"fn".params[0].type.?) !void {20pub 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}
2623
27pub fn deinit_thread() void {24pub fn deinit_thread() void {
28 impl.deinit_thread();25 impl.deinit_thread();
29 started = false;
30}26}
3127
32pub inline fn trace(src: std.builtin.SourceLocation, comptime fmt: []const u8, args: anytype) Ctx {28pub 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}
3934
40pub const Ctx = struct {35pub const Ctx = struct {
41 src: std.builtin.SourceLocation,36 src: std.builtin.SourceLocation,
37 data: impl.Data,
4238
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 {
1414
15pub fn deinit_thread() void {}15pub fn deinit_thread() void {}
1616
17pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: anytype) void {17pub 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
23pub inline fn trace_end(ctx: tracer.Ctx) void {23pub inline fn trace_end(ctx: tracer.Ctx) void {
24 _ = ctx;24 _ = ctx;
25}25}
26
27pub 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}
4343
44pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: anytype) void {44pub 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}
6565
66pub const Data = void;
67
66// https://github.com/colrdavidson/spall-web/blob/1d4610a1fe9aaaf2e071327a1142a498f3436bdc/formats/spall/spall.odin68// https://github.com/colrdavidson/spall-web/blob/1d4610a1fe9aaaf2e071327a1142a498f3436bdc/formats/spall/spall.odin
67// https://github.com/colrdavidson/spall-web/blob/1d4610a1fe9aaaf2e071327a1142a498f3436bdc/tools/json2bin/json2bin.odin69// https://github.com/colrdavidson/spall-web/blob/1d4610a1fe9aaaf2e071327a1142a498f3436bdc/tools/json2bin/json2bin.odin
68// https://github.com/colrdavidson/spall-web/blob/1d4610a1fe9aaaf2e071327a1142a498f3436bdc/tools/upconvert/main.odin70// https://github.com/colrdavidson/spall-web/blob/1d4610a1fe9aaaf2e071327a1142a498f3436bdc/tools/upconvert/main.odin