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 {...@@ -9,6 +9,7 @@ pub fn build(b: *std.Build) void {
9 addTest(b, target, mode, mod, 0);9 addTest(b, target, mode, mod, 0);
10 addTest(b, target, mode, mod, 1);10 addTest(b, target, mode, mod, 1);
11 addTest(b, target, mode, mod, 2);11 addTest(b, target, mode, mod, 2);
12 addTest(b, target, mode, mod, 3);
12}13}
1314
14fn addTest(b: *std.Build, target: std.zig.CrossTarget, mode: std.builtin.Mode, mod: *std.build.Module, comptime backend: u8) void {15fn 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 {...@@ -22,7 +22,7 @@ pub fn deinit() void {
22pub fn init_thread() !void {22pub fn init_thread() !void {
23 tid = std.os.linux.gettid();23 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 });
26 file = try std.fs.cwd().createFile(path, .{});26 file = try std.fs.cwd().createFile(path, .{});
27 buffered_writer = std.io.bufferedWriter(file.writer());27 buffered_writer = std.io.bufferedWriter(file.writer());
2828
...@@ -38,16 +38,19 @@ pub fn deinit_thread() void {...@@ -38,16 +38,19 @@ pub fn deinit_thread() void {
38 log.debug("{s}", .{path});38 log.debug("{s}", .{path});
39}39}
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 {
42 buffered_writer.writer().print(42 buffered_writer.writer().print(
43 \\{{"cat":"function", "name":"{s}:{d}:{d} ({s})", "ph": "B", "pid": {d}, "tid": {d}, "ts": {d}}},43 \\{{"cat":"function", "name":"{s}:{d}:{d} ({s})
44 \\44 ++ ifmt ++
45 \\", "ph": "B", "pid": {d}, "tid": {d}, "ts": {d}}},
46 \\
45 ,47 ,
46 .{48 .{
47 if (ctx.src.file[0] == '/') ctx.src.file[trim_count..] else ctx.src.file,49 if (ctx.src.file[0] == '/') ctx.src.file[trim_count..] else ctx.src.file,
48 ctx.src.line,50 ctx.src.line,
49 ctx.src.column,51 ctx.src.column,
50 ctx.src.fn_name,52 ctx.src.fn_name,
53 } ++ iargs ++ .{
51 pid,54 pid,
52 tid,55 tid,
53 std.time.microTimestamp(),56 std.time.microTimestamp(),
src/main.zig+1
...@@ -6,6 +6,7 @@ pub const tracer_impl = switch (build_options.backend) {...@@ -6,6 +6,7 @@ pub const tracer_impl = switch (build_options.backend) {
6 0 => tracer.none,6 0 => tracer.none,
7 1 => tracer.log,7 1 => tracer.log,
8 2 => tracer.spall,8 2 => tracer.spall,
9 3 => tracer.chrome,
9 else => unreachable,10 else => unreachable,
10};11};
1112