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