diff --git a/src/log.zig b/src/log.zig index 229baca472dfade5e4fbeed1b9434f2349e70b49..056529e536cfcb36f0a2de9e762d2ddd49eb2229 100644 --- a/src/log.zig +++ b/src/log.zig @@ -10,8 +10,8 @@ pub fn init_thread() !void {} pub fn deinit_thread() void {} -pub inline fn trace_begin(ctx: tracer.Ctx) void { - log.debug("{s}:{d}:{d} ({s})", .{ ctx.src.file, ctx.src.line, ctx.src.column, ctx.src.fn_name }); +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_end(ctx: tracer.Ctx) void { diff --git a/src/main.zig b/src/main.zig index 6c8e7c9b6795607975c2c193029f0ad9db36d213..b86d2f8aa6334af2d0bf009436199b78cf466add 100644 --- a/src/main.zig +++ b/src/main.zig @@ -24,6 +24,6 @@ pub fn main() !void { } fn handler() void { - const t = tracer.trace(@src()); + const t = tracer.trace(@src(), "", .{}); defer t.end(); } diff --git a/src/mod.zig b/src/mod.zig index 6393c726b8196551d4e2c55ae87bf0453c61e652..f4674b0b6ec79a4e2e39617b15c58eb8b105d6cf 100644 --- a/src/mod.zig +++ b/src/mod.zig @@ -26,11 +26,11 @@ pub fn deinit_thread() void { impl.deinit_thread(); } -pub inline fn trace(src: std.builtin.SourceLocation) Ctx { +pub inline fn trace(src: std.builtin.SourceLocation, comptime fmt: []const u8, args: anytype) Ctx { const ctx = Ctx{ .src = src, }; - if (started) impl.trace_begin(ctx); + if (started) impl.trace_begin(ctx, fmt, args); return ctx; } diff --git a/src/none.zig b/src/none.zig index 20cbe73be18a2d3ec1292495b3be49ee725750d4..29ef21951d60822d6bd22926aebe5f7b9f656c96 100644 --- a/src/none.zig +++ b/src/none.zig @@ -10,8 +10,10 @@ pub fn init_thread() !void {} pub fn deinit_thread() void {} -pub inline fn trace_begin(ctx: tracer.Ctx) void { +pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: anytype) void { _ = ctx; + _ = ifmt; + _ = iargs; } pub inline fn trace_end(ctx: tracer.Ctx) void { diff --git a/src/spall.zig b/src/spall.zig index 3429ad5152b51124c76d8e95ce2db2fe72ca16b9..fe48e99b0888ac949667aa57038dac9a542043b0 100644 --- a/src/spall.zig +++ b/src/spall.zig @@ -37,8 +37,8 @@ pub fn deinit_thread() void { log.debug("{s}", .{path}); } -pub inline fn trace_begin(ctx: tracer.Ctx) void { - const fmt = "{s}:{d}:{d} ({s})"; +pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: anytype) void { + const fmt = "{s}:{d}:{d} ({s})" ++ ifmt; const args = .{ if (ctx.src.file[0] == '/') ctx.src.file[trim_count..] else ctx.src.file, ctx.src.line, @@ -49,10 +49,10 @@ pub inline fn trace_begin(ctx: tracer.Ctx) void { .pid = @intCast(pid), .tid = @intCast(tid), .time = @floatFromInt(std.time.microTimestamp()), - .name_len = @intCast(std.fmt.count(fmt, args)), + .name_len = @intCast(std.fmt.count(fmt, args ++ iargs)), .args_len = 0, }) catch return; - buffered_writer.writer().print(fmt, args) catch return; + buffered_writer.writer().print(fmt, args ++ iargs) catch return; } pub inline fn trace_end(ctx: tracer.Ctx) void {