| author | |
| committer | |
| log | af18634753b3671d998ad6064e1f6c3ad9bbc6eb |
| tree | d7490a3a2a81efb36ac6957c29c0cf37461ac288 |
| parent | 75d814d188bc5969d066ab3b5e19aa55f5aa2434 |
| signature |
8 files changed, 45 insertions(+), 25 deletions(-)
licenses.txt+6| ... | ... | @@ -3,6 +3,12 @@ MIT: |
| 3 | 3 | - This |
| 4 | 4 | - git https://github.com/nektro/zig-extras |
| 5 | 5 | - git https://github.com/nektro/zig-sys-linux |
| 6 | - git https://github.com/nektro/zig-time | |
| 7 | ||
| 8 | MPL-2.0: | |
| 9 | = https://spdx.org/licenses/MPL-2.0 | |
| 10 | - git https://github.com/nektro/zig-nfs | |
| 11 | - git https://github.com/nektro/zig-nio | |
| 6 | 12 | |
| 7 | 13 | Unspecified: |
| 8 | 14 | - system_lib c |
src/chrome.zig+12-10| ... | ... | @@ -3,13 +3,15 @@ const tracer = @import("./mod.zig"); |
| 3 | 3 | const alloc = std.heap.c_allocator; |
| 4 | 4 | const log = std.log.scoped(.tracer); |
| 5 | 5 | const root = @import("root"); |
| 6 | const nfs = @import("nfs"); | |
| 7 | const nio = @import("nio"); | |
| 6 | 8 | const linux = @import("sys-linux"); |
| 7 | 9 | |
| 8 | 10 | var pid: linux.pid_t = undefined; |
| 9 | 11 | threadlocal var tid: 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; | |
| 12 | threadlocal var path: [:0]const u8 = undefined; | |
| 13 | threadlocal var file: nfs.File = undefined; | |
| 14 | threadlocal var buffered_writer: nio.BufferedWriter(4096, nfs.File) = undefined; | |
| 13 | 15 | |
| 14 | 16 | pub fn init() !void { |
| 15 | 17 | pid = linux.getpid(); |
| ... | ... | @@ -19,26 +21,26 @@ pub fn deinit() void { |
| 19 | 21 | // |
| 20 | 22 | } |
| 21 | 23 | |
| 22 | pub fn init_thread(dir: std.fs.Dir) !void { | |
| 24 | pub fn init_thread(dir: nfs.Dir) !void { | |
| 23 | 25 | tid = linux.gettid(); |
| 24 | 26 | |
| 25 | path = try std.fmt.allocPrint(alloc, "trace.{d}.{d}.chrome.json", .{ pid, tid }); | |
| 27 | path = try std.fmt.allocPrintZ(alloc, "trace.{d}.{d}.chrome.json", .{ pid, tid }); | |
| 26 | 28 | file = try dir.createFile(path, .{}); |
| 27 | buffered_writer = std.io.bufferedWriter(file.writer()); | |
| 29 | buffered_writer = .init(file); | |
| 28 | 30 | |
| 29 | try buffered_writer.writer().writeAll("[\n"); | |
| 31 | try buffered_writer.writeAll("[\n"); | |
| 30 | 32 | } |
| 31 | 33 | |
| 32 | 34 | pub fn deinit_thread() void { |
| 33 | 35 | defer alloc.free(path); |
| 34 | 36 | defer file.close(); |
| 35 | 37 | |
| 36 | buffered_writer.writer().writeAll("]\n") catch {}; | |
| 38 | buffered_writer.writeAll("]\n") catch {}; | |
| 37 | 39 | buffered_writer.flush() catch {}; |
| 38 | 40 | } |
| 39 | 41 | |
| 40 | 42 | pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: anytype) void { |
| 41 | buffered_writer.writer().print( | |
| 43 | buffered_writer.print( | |
| 42 | 44 | \\{{"cat":"function", "name":"{s}:{d}:{d} ({s}) |
| 43 | 45 | ++ ifmt ++ |
| 44 | 46 | \\", "ph": "B", "pid": {d}, "tid": {d}, "ts": {d}}}, |
| ... | ... | @@ -59,7 +61,7 @@ pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: any |
| 59 | 61 | |
| 60 | 62 | pub inline fn trace_end(ctx: tracer.Ctx) void { |
| 61 | 63 | _ = ctx; |
| 62 | buffered_writer.writer().print( | |
| 64 | buffered_writer.print( | |
| 63 | 65 | \\{{"cat":"function", "ph": "E", "pid": {d}, "tid": {d}, "ts": {d}}}, |
| 64 | 66 | \\ |
| 65 | 67 | , |
src/log.zig+2-1| ... | ... | @@ -1,12 +1,13 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const tracer = @import("./mod.zig"); |
| 3 | 3 | const log = std.log.scoped(.tracer); |
| 4 | const nfs = @import("nfs"); | |
| 4 | 5 | |
| 5 | 6 | pub fn init() !void {} |
| 6 | 7 | |
| 7 | 8 | pub fn deinit() void {} |
| 8 | 9 | |
| 9 | pub fn init_thread(dir: std.fs.Dir) !void { | |
| 10 | pub fn init_thread(dir: nfs.Dir) !void { | |
| 10 | 11 | _ = dir; |
| 11 | 12 | } |
| 12 | 13 |
src/main.zig+3-1| ... | ... | @@ -1,5 +1,7 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const tracer = @import("tracer"); |
| 3 | const nfs = @import("nfs"); | |
| 4 | ||
| 3 | 5 | pub const build_options = @import("build_options"); |
| 4 | 6 | |
| 5 | 7 | pub const tracer_impl = switch (build_options.backend) { |
| ... | ... | @@ -18,7 +20,7 @@ pub fn main() !void { |
| 18 | 20 | var go = false; |
| 19 | 21 | _ = &go; |
| 20 | 22 | while (go) { |
| 21 | try tracer.init_thread(std.fs.cwd()); | |
| 23 | try tracer.init_thread(nfs.cwd()); | |
| 22 | 24 | defer tracer.deinit_thread(); |
| 23 | 25 | |
| 24 | 26 | handler(); |
src/mod.zig+3-2| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const root = @import("root"); |
| 3 | 3 | const extras = @import("extras"); |
| 4 | const nfs = @import("nfs"); | |
| 4 | 5 | const impl = extras.globalOption("tracer_impl", type) orelse none; |
| 5 | 6 | |
| 6 | 7 | threadlocal var started = false; |
| ... | ... | @@ -18,8 +19,8 @@ pub fn deinit() void { |
| 18 | 19 | impl.deinit(); |
| 19 | 20 | } |
| 20 | 21 | |
| 21 | pub fn init_thread(dir: ?std.fs.Dir) !void { | |
| 22 | try impl.init_thread(dir orelse std.fs.cwd()); | |
| 22 | pub fn init_thread(dir: ?nfs.Dir) !void { | |
| 23 | try impl.init_thread(dir orelse nfs.cwd()); | |
| 23 | 24 | started = true; |
| 24 | 25 | } |
| 25 | 26 |
src/none.zig+2-1| ... | ... | @@ -1,12 +1,13 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const tracer = @import("./mod.zig"); |
| 3 | 3 | const log = std.log.scoped(.tracer); |
| 4 | const nfs = @import("nfs"); | |
| 4 | 5 | |
| 5 | 6 | pub fn init() !void {} |
| 6 | 7 | |
| 7 | 8 | pub fn deinit() void {} |
| 8 | 9 | |
| 9 | pub fn init_thread(dir: std.fs.Dir) !void { | |
| 10 | pub fn init_thread(dir: nfs.Dir) !void { | |
| 10 | 11 | _ = dir; |
| 11 | 12 | } |
| 12 | 13 |
src/spall.zig+12-10| ... | ... | @@ -3,13 +3,15 @@ const tracer = @import("./mod.zig"); |
| 3 | 3 | const alloc = std.heap.c_allocator; |
| 4 | 4 | const log = std.log.scoped(.tracer); |
| 5 | 5 | const root = @import("root"); |
| 6 | const nfs = @import("nfs"); | |
| 7 | const nio = @import("nio"); | |
| 6 | 8 | const linux = @import("sys-linux"); |
| 7 | 9 | |
| 8 | 10 | var pid: linux.pid_t = undefined; |
| 9 | 11 | threadlocal var tid: 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; | |
| 12 | threadlocal var path: [:0]const u8 = undefined; | |
| 13 | threadlocal var file: nfs.File = undefined; | |
| 14 | threadlocal var buffered_writer: nio.BufferedWriter(4096, nfs.File) = undefined; | |
| 13 | 15 | |
| 14 | 16 | pub fn init() !void { |
| 15 | 17 | pid = linux.getpid(); |
| ... | ... | @@ -19,14 +21,14 @@ pub fn deinit() void { |
| 19 | 21 | // |
| 20 | 22 | } |
| 21 | 23 | |
| 22 | pub fn init_thread(dir: std.fs.Dir) !void { | |
| 24 | pub fn init_thread(dir: nfs.Dir) !void { | |
| 23 | 25 | tid = linux.gettid(); |
| 24 | 26 | |
| 25 | path = try std.fmt.allocPrint(alloc, "{d}.{d}.spall", .{ pid, tid }); | |
| 27 | path = try std.fmt.allocPrintZ(alloc, "{d}.{d}.spall", .{ pid, tid }); | |
| 26 | 28 | file = try dir.createFile(path, .{}); |
| 27 | buffered_writer = std.io.bufferedWriter(file.writer()); | |
| 29 | buffered_writer = .init(file); | |
| 28 | 30 | |
| 29 | try buffered_writer.writer().writeStruct(Header{}); | |
| 31 | try buffered_writer.writeStruct(Header{}); | |
| 30 | 32 | } |
| 31 | 33 | |
| 32 | 34 | pub fn deinit_thread() void { |
| ... | ... | @@ -39,19 +41,19 @@ pub fn deinit_thread() void { |
| 39 | 41 | pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: anytype) void { |
| 40 | 42 | const fmt = "{s}:{d}:{d} ({s})" ++ ifmt; |
| 41 | 43 | const args = .{ ctx.src.file, ctx.src.line, ctx.src.column, ctx.src.fn_name }; |
| 42 | buffered_writer.writer().writeStruct(BeginEvent{ | |
| 44 | buffered_writer.writeStruct(BeginEvent{ | |
| 43 | 45 | .pid = @intCast(pid), |
| 44 | 46 | .tid = @intCast(tid), |
| 45 | 47 | .time = @floatFromInt(std.time.microTimestamp()), |
| 46 | 48 | .name_len = @truncate(std.fmt.count(fmt, args ++ iargs)), |
| 47 | 49 | .args_len = 0, |
| 48 | 50 | }) catch return; |
| 49 | buffered_writer.writer().print(fmt, args ++ iargs) catch return; | |
| 51 | buffered_writer.print(fmt, args ++ iargs) catch return; | |
| 50 | 52 | } |
| 51 | 53 | |
| 52 | 54 | pub inline fn trace_end(ctx: tracer.Ctx) void { |
| 53 | 55 | _ = ctx; |
| 54 | buffered_writer.writer().writeStruct(EndEvent{ | |
| 56 | buffered_writer.writeStruct(EndEvent{ | |
| 55 | 57 | .pid = @intCast(pid), |
| 56 | 58 | .tid = @intCast(tid), |
| 57 | 59 | .time = @floatFromInt(std.time.microTimestamp()), |
zigmod.yml+5| ... | ... | @@ -6,3 +6,8 @@ description: Generic tracing library for Zig, supports multiple backends. |
| 6 | 6 | dependencies: |
| 7 | 7 | - src: git https://github.com/nektro/zig-extras |
| 8 | 8 | - src: git https://github.com/nektro/zig-sys-linux |
| 9 | - src: git https://github.com/nektro/zig-nfs | |
| 10 | - src: git https://github.com/nektro/zig-nio | |
| 11 | ||
| 12 | root_dependencies: | |
| 13 | - src: git https://github.com/nektro/zig-nfs |