authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-11-21 10:37:30 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-11-21 10:37:30 -08:00
logf05ca52eca588ffba16ca04f352e26933194b6dc
treefe05cfc73a52be41b2500c97807f39791c511383
parent406a484b904ba2e77e995544a2aa891c7aeae4a7

fix chrome backend and make sure it has test coverage


3 files changed, 9 insertions(+), 4 deletions(-)

build.zig+1
......@@ -9,6 +9,7 @@ pub fn build(b: *std.Build) void {
99 addTest(b, target, mode, mod, 0);
1010 addTest(b, target, mode, mod, 1);
1111 addTest(b, target, mode, mod, 2);
12 addTest(b, target, mode, mod, 3);
1213}
1314
1415fn addTest(b: *std.Build, target: std.zig.CrossTarget, mode: std.builtin.Mode, mod: *std.build.Module, comptime backend: u8) void {
src/chrome.zig+7-4
......@@ -22,7 +22,7 @@ pub fn deinit() void {
2222pub fn init_thread() !void {
2323 tid = std.os.linux.gettid();
2424
25 path = try std.fmt.allocPrint(alloc, "/data/trace.{d}.{d}.spall.json", .{ pid, tid });
25 path = try std.fmt.allocPrint(alloc, "/data/trace.{d}.{d}.chrome.json", .{ pid, tid });
2626 file = try std.fs.cwd().createFile(path, .{});
2727 buffered_writer = std.io.bufferedWriter(file.writer());
2828
......@@ -38,16 +38,19 @@ pub fn deinit_thread() void {
3838 log.debug("{s}", .{path});
3939}
4040
41pub inline fn trace_begin(ctx: tracer.Ctx) void {
41pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: anytype) void {
4242 buffered_writer.writer().print(
43 \\{{"cat":"function", "name":"{s}:{d}:{d} ({s})", "ph": "B", "pid": {d}, "tid": {d}, "ts": {d}}},
44 \\
43 \\{{"cat":"function", "name":"{s}:{d}:{d} ({s})
44 ++ ifmt ++
45 \\", "ph": "B", "pid": {d}, "tid": {d}, "ts": {d}}},
46 \\
4547 ,
4648 .{
4749 if (ctx.src.file[0] == '/') ctx.src.file[trim_count..] else ctx.src.file,
4850 ctx.src.line,
4951 ctx.src.column,
5052 ctx.src.fn_name,
53 } ++ iargs ++ .{
5154 pid,
5255 tid,
5356 std.time.microTimestamp(),
src/main.zig+1
......@@ -6,6 +6,7 @@ pub const tracer_impl = switch (build_options.backend) {
66 0 => tracer.none,
77 1 => tracer.log,
88 2 => tracer.spall,
9 3 => tracer.chrome,
910 else => unreachable,
1011};
1112