| author | |
| committer | |
| log | 3e61b8f598cfd209c142911db15077fb3e0ff1b7 |
| tree | 804f26b8e8315028eb5ab2d515fb31d3aa2967a4 |
| parent | 16783577405277a465ac95f2b524fc5f5e959533 |
3 files changed, 71 insertions(+), 71 deletions(-)
src/chrome.zig created+70| ... | @@ -0,0 +1,70 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const tracer = @import("./mod.zig"); | ||
| 3 | const alloc = std.heap.c_allocator; | ||
| 4 | const log = std.log.scoped(.tracer); | ||
| 5 | const root = @import("root"); | ||
| 6 | const trim_count = root.build_options.src_file_trimlen; | ||
| 7 | |||
| 8 | var pid: std.os.linux.pid_t = undefined; | ||
| 9 | threadlocal var tid: std.os.linux.pid_t = undefined; | ||
| 10 | threadlocal var path: []const u8 = undefined; | ||
| 11 | threadlocal var file: std.fs.File = undefined; | ||
| 12 | threadlocal var buffered_writer: std.io.BufferedWriter(4096, std.fs.File.Writer) = undefined; | ||
| 13 | |||
| 14 | pub fn init() !void { | ||
| 15 | pid = std.os.linux.getpid(); | ||
| 16 | } | ||
| 17 | |||
| 18 | pub fn deinit() void { | ||
| 19 | // | ||
| 20 | } | ||
| 21 | |||
| 22 | pub fn init_thread() !void { | ||
| 23 | tid = std.os.linux.gettid(); | ||
| 24 | |||
| 25 | path = try std.fmt.allocPrint(alloc, "/data/trace.{d}.{d}.spall.json", .{ pid, tid }); | ||
| 26 | file = try std.fs.cwd().createFile(path, .{}); | ||
| 27 | buffered_writer = std.io.bufferedWriter(file.writer()); | ||
| 28 | |||
| 29 | try buffered_writer.writer().writeAll("[\n"); | ||
| 30 | } | ||
| 31 | |||
| 32 | pub fn deinit_thread() void { | ||
| 33 | defer alloc.free(path); | ||
| 34 | defer file.close(); | ||
| 35 | |||
| 36 | buffered_writer.writer().writeAll("]\n") catch {}; | ||
| 37 | buffered_writer.flush() catch {}; | ||
| 38 | log.debug("{s}", .{path}); | ||
| 39 | } | ||
| 40 | |||
| 41 | pub inline fn trace_begin(ctx: tracer.Ctx) void { | ||
| 42 | buffered_writer.writer().print( | ||
| 43 | \\{{"cat":"function", "name":"{s}:{d}:{d} ({s})", "ph": "B", "pid": {d}, "tid": {d}, "ts": {d}}}, | ||
| 44 | \\ | ||
| 45 | , | ||
| 46 | .{ | ||
| 47 | if (ctx.src.file[0] == '/') ctx.src.file[trim_count..] else ctx.src.file, | ||
| 48 | ctx.src.line, | ||
| 49 | ctx.src.column, | ||
| 50 | ctx.src.fn_name, | ||
| 51 | pid, | ||
| 52 | tid, | ||
| 53 | std.time.microTimestamp(), | ||
| 54 | }, | ||
| 55 | ) catch {}; | ||
| 56 | } | ||
| 57 | |||
| 58 | pub inline fn trace_end(ctx: tracer.Ctx) void { | ||
| 59 | _ = ctx; | ||
| 60 | buffered_writer.writer().print( | ||
| 61 | \\{{"cat":"function", "ph": "E", "pid": {d}, "tid": {d}, "ts": {d}}}, | ||
| 62 | \\ | ||
| 63 | , | ||
| 64 | .{ | ||
| 65 | pid, | ||
| 66 | tid, | ||
| 67 | std.time.microTimestamp(), | ||
| 68 | }, | ||
| 69 | ) catch {}; | ||
| 70 | } | ||
src/mod.zig+1-1| ... | @@ -6,7 +6,7 @@ var started = false; | ... | @@ -6,7 +6,7 @@ var started = false; |
| 6 | 6 | ||
| 7 | pub const none = @import("./none.zig"); | 7 | pub const none = @import("./none.zig"); |
| 8 | pub const log = @import("./log.zig"); | 8 | pub const log = @import("./log.zig"); |
| 9 | pub const spall = @import("./spall.zig"); | 9 | pub const chrome = @import("./chrome.zig"); |
| 10 | 10 | ||
| 11 | pub fn init() !void { | 11 | pub fn init() !void { |
| 12 | try impl.init(); | 12 | try impl.init(); |
src/spall.zig deleted-70| ... | @@ -1,70 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const tracer = @import("./mod.zig"); | ||
| 3 | const alloc = std.heap.c_allocator; | ||
| 4 | const log = std.log.scoped(.tracer); | ||
| 5 | const root = @import("root"); | ||
| 6 | const trim_count = root.build_options.src_file_trimlen; | ||
| 7 | |||
| 8 | var pid: std.os.linux.pid_t = undefined; | ||
| 9 | threadlocal var tid: std.os.linux.pid_t = undefined; | ||
| 10 | threadlocal var path: []const u8 = undefined; | ||
| 11 | threadlocal var file: std.fs.File = undefined; | ||
| 12 | threadlocal var buffered_writer: std.io.BufferedWriter(4096, std.fs.File.Writer) = undefined; | ||
| 13 | |||
| 14 | pub fn init() !void { | ||
| 15 | pid = std.os.linux.getpid(); | ||
| 16 | } | ||
| 17 | |||
| 18 | pub fn deinit() void { | ||
| 19 | // | ||
| 20 | } | ||
| 21 | |||
| 22 | pub fn init_thread() !void { | ||
| 23 | tid = std.os.linux.gettid(); | ||
| 24 | |||
| 25 | path = try std.fmt.allocPrint(alloc, "/data/trace.{d}.{d}.spall.json", .{ pid, tid }); | ||
| 26 | file = try std.fs.cwd().createFile(path, .{}); | ||
| 27 | buffered_writer = std.io.bufferedWriter(file.writer()); | ||
| 28 | |||
| 29 | try buffered_writer.writer().writeAll("[\n"); | ||
| 30 | } | ||
| 31 | |||
| 32 | pub fn deinit_thread() void { | ||
| 33 | defer alloc.free(path); | ||
| 34 | defer file.close(); | ||
| 35 | |||
| 36 | buffered_writer.writer().writeAll("]\n") catch {}; | ||
| 37 | buffered_writer.flush() catch {}; | ||
| 38 | log.debug("{s}", .{path}); | ||
| 39 | } | ||
| 40 | |||
| 41 | pub inline fn trace_begin(ctx: tracer.Ctx) void { | ||
| 42 | buffered_writer.writer().print( | ||
| 43 | \\{{"cat":"function", "name":"{s}:{d}:{d} ({s})", "ph": "B", "pid": {d}, "tid": {d}, "ts": {d}}}, | ||
| 44 | \\ | ||
| 45 | , | ||
| 46 | .{ | ||
| 47 | if (ctx.src.file[0] == '/') ctx.src.file[trim_count..] else ctx.src.file, | ||
| 48 | ctx.src.line, | ||
| 49 | ctx.src.column, | ||
| 50 | ctx.src.fn_name, | ||
| 51 | pid, | ||
| 52 | tid, | ||
| 53 | std.time.microTimestamp(), | ||
| 54 | }, | ||
| 55 | ) catch {}; | ||
| 56 | } | ||
| 57 | |||
| 58 | pub inline fn trace_end(ctx: tracer.Ctx) void { | ||
| 59 | _ = ctx; | ||
| 60 | buffered_writer.writer().print( | ||
| 61 | \\{{"cat":"function", "ph": "E", "pid": {d}, "tid": {d}, "ts": {d}}}, | ||
| 62 | \\ | ||
| 63 | , | ||
| 64 | .{ | ||
| 65 | pid, | ||
| 66 | tid, | ||
| 67 | std.time.microTimestamp(), | ||
| 68 | }, | ||
| 69 | ) catch {}; | ||
| 70 | } | ||