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 {
4242 buffered_writer.flush() catch {};
4343}
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 {
4646 buffered_writer.print(
4747 \\{{"cat":"function", "name":"{s}:{d}:{d} ({s})
4848 ++ ifmt ++
......@@ -50,10 +50,10 @@ pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: any
5050 \\
5151 ,
5252 .{
53 ctx.src.file,
54 ctx.src.line,
55 ctx.src.column,
56 ctx.src.fn_name,
53 src.file,
54 src.line,
55 src.column,
56 src.fn_name,
5757 } ++ iargs ++ .{
5858 pid,
5959 tid,
......@@ -75,3 +75,5 @@ pub inline fn trace_end(ctx: tracer.Ctx) void {
7575 },
7676 ) catch {};
7777}
78
79pub const Data = void;
src/log.zig+4-2
......@@ -14,10 +14,12 @@ pub fn init_thread(args: struct {}) !void {
1414
1515pub fn deinit_thread() void {}
1616
17pub inline fn trace_begin(ctx: tracer.Ctx, 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);
17pub inline fn trace_begin(src: std.builtin.SourceLocation, comptime ifmt: []const u8, iargs: anytype) void {
18 log.debug("{s}:{d}:{d} ({s})" ++ ifmt, .{ src.file, src.line, src.column, src.fn_name } ++ iargs);
1919}
2020
2121pub inline fn trace_end(ctx: tracer.Ctx) void {
2222 _ = ctx;
2323}
24
25pub const Data = void;
src/mod.zig+4-8
......@@ -4,8 +4,6 @@ const extras = @import("extras");
44const nfs = @import("nfs");
55const impl = extras.globalOption("tracer_impl", type) orelse none;
66
7threadlocal var started = false;
8
97pub const none = @import("./none.zig");
108pub const log = @import("./log.zig");
119pub const chrome = @import("./chrome.zig");
......@@ -21,26 +19,24 @@ pub fn deinit() void {
2119
2220pub fn init_thread(args: @typeInfo(@TypeOf(impl.init_thread)).@"fn".params[0].type.?) !void {
2321 try impl.init_thread(args);
24 started = true;
2522}
2623
2724pub fn deinit_thread() void {
2825 impl.deinit_thread();
29 started = false;
3026}
3127
3228pub inline fn trace(src: std.builtin.SourceLocation, comptime fmt: []const u8, args: anytype) Ctx {
33 const ctx = Ctx{
29 return .{
3430 .src = src,
31 .data = impl.trace_begin(src, fmt, args),
3532 };
36 if (started) impl.trace_begin(ctx, fmt, args);
37 return ctx;
3833}
3934
4035pub const Ctx = struct {
4136 src: std.builtin.SourceLocation,
37 data: impl.Data,
4238
4339 pub inline fn end(self: Ctx) void {
44 if (started) impl.trace_end(self);
40 impl.trace_end(self);
4541 }
4642};
src/none.zig+4-2
......@@ -14,8 +14,8 @@ pub fn init_thread(args: struct {}) !void {
1414
1515pub fn deinit_thread() void {}
1616
17pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: anytype) void {
18 _ = ctx;
17pub inline fn trace_begin(src: std.builtin.SourceLocation, comptime ifmt: []const u8, iargs: anytype) void {
18 _ = src;
1919 _ = ifmt;
2020 _ = iargs;
2121}
......@@ -23,3 +23,5 @@ pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: any
2323pub inline fn trace_end(ctx: tracer.Ctx) void {
2424 _ = ctx;
2525}
26
27pub const Data = void;
src/spall.zig+4-2
......@@ -41,9 +41,9 @@ pub fn deinit_thread() void {
4141 buffered_writer.flush() catch {};
4242}
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 {
4545 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 };
4747 buffered_writer.writeStruct(BeginEvent{
4848 .pid = @intCast(pid),
4949 .tid = @intCast(tid),
......@@ -63,6 +63,8 @@ pub inline fn trace_end(ctx: tracer.Ctx) void {
6363 }) catch return;
6464}
6565
66pub const Data = void;
67
6668// https://github.com/colrdavidson/spall-web/blob/1d4610a1fe9aaaf2e071327a1142a498f3436bdc/formats/spall/spall.odin
6769// https://github.com/colrdavidson/spall-web/blob/1d4610a1fe9aaaf2e071327a1142a498f3436bdc/tools/json2bin/json2bin.odin
6870// https://github.com/colrdavidson/spall-web/blob/1d4610a1fe9aaaf2e071327a1142a498f3436bdc/tools/upconvert/main.odin