authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-04-25 21:15:16 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-04-25 21:15:16 -07:00
logaf18634753b3671d998ad6064e1f6c3ad9bbc6eb
treed7490a3a2a81efb36ac6957c29c0cf37461ac288
parent75d814d188bc5969d066ab3b5e19aa55f5aa2434
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

further migration to zig-sys


8 files changed, 45 insertions(+), 25 deletions(-)

licenses.txt+6
......@@ -3,6 +3,12 @@ MIT:
33- This
44- git https://github.com/nektro/zig-extras
55- git https://github.com/nektro/zig-sys-linux
6- git https://github.com/nektro/zig-time
7
8MPL-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
612
713Unspecified:
814- system_lib c
src/chrome.zig+12-10
......@@ -3,13 +3,15 @@ const tracer = @import("./mod.zig");
33const alloc = std.heap.c_allocator;
44const log = std.log.scoped(.tracer);
55const root = @import("root");
6const nfs = @import("nfs");
7const nio = @import("nio");
68const linux = @import("sys-linux");
79
810var pid: linux.pid_t = undefined;
911threadlocal var tid: linux.pid_t = undefined;
10threadlocal var path: []const u8 = undefined;
11threadlocal var file: std.fs.File = undefined;
12threadlocal var buffered_writer: std.io.BufferedWriter(4096, std.fs.File.Writer) = undefined;
12threadlocal var path: [:0]const u8 = undefined;
13threadlocal var file: nfs.File = undefined;
14threadlocal var buffered_writer: nio.BufferedWriter(4096, nfs.File) = undefined;
1315
1416pub fn init() !void {
1517 pid = linux.getpid();
......@@ -19,26 +21,26 @@ pub fn deinit() void {
1921 //
2022}
2123
22pub fn init_thread(dir: std.fs.Dir) !void {
24pub fn init_thread(dir: nfs.Dir) !void {
2325 tid = linux.gettid();
2426
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 });
2628 file = try dir.createFile(path, .{});
27 buffered_writer = std.io.bufferedWriter(file.writer());
29 buffered_writer = .init(file);
2830
29 try buffered_writer.writer().writeAll("[\n");
31 try buffered_writer.writeAll("[\n");
3032}
3133
3234pub fn deinit_thread() void {
3335 defer alloc.free(path);
3436 defer file.close();
3537
36 buffered_writer.writer().writeAll("]\n") catch {};
38 buffered_writer.writeAll("]\n") catch {};
3739 buffered_writer.flush() catch {};
3840}
3941
4042pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: anytype) void {
41 buffered_writer.writer().print(
43 buffered_writer.print(
4244 \\{{"cat":"function", "name":"{s}:{d}:{d} ({s})
4345 ++ ifmt ++
4446 \\", "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
5961
6062pub inline fn trace_end(ctx: tracer.Ctx) void {
6163 _ = ctx;
62 buffered_writer.writer().print(
64 buffered_writer.print(
6365 \\{{"cat":"function", "ph": "E", "pid": {d}, "tid": {d}, "ts": {d}}},
6466 \\
6567 ,
src/log.zig+2-1
......@@ -1,12 +1,13 @@
11const std = @import("std");
22const tracer = @import("./mod.zig");
33const log = std.log.scoped(.tracer);
4const nfs = @import("nfs");
45
56pub fn init() !void {}
67
78pub fn deinit() void {}
89
9pub fn init_thread(dir: std.fs.Dir) !void {
10pub fn init_thread(dir: nfs.Dir) !void {
1011 _ = dir;
1112}
1213
src/main.zig+3-1
......@@ -1,5 +1,7 @@
11const std = @import("std");
22const tracer = @import("tracer");
3const nfs = @import("nfs");
4
35pub const build_options = @import("build_options");
46
57pub const tracer_impl = switch (build_options.backend) {
......@@ -18,7 +20,7 @@ pub fn main() !void {
1820 var go = false;
1921 _ = &go;
2022 while (go) {
21 try tracer.init_thread(std.fs.cwd());
23 try tracer.init_thread(nfs.cwd());
2224 defer tracer.deinit_thread();
2325
2426 handler();
src/mod.zig+3-2
......@@ -1,6 +1,7 @@
11const std = @import("std");
22const root = @import("root");
33const extras = @import("extras");
4const nfs = @import("nfs");
45const impl = extras.globalOption("tracer_impl", type) orelse none;
56
67threadlocal var started = false;
......@@ -18,8 +19,8 @@ pub fn deinit() void {
1819 impl.deinit();
1920}
2021
21pub fn init_thread(dir: ?std.fs.Dir) !void {
22 try impl.init_thread(dir orelse std.fs.cwd());
22pub fn init_thread(dir: ?nfs.Dir) !void {
23 try impl.init_thread(dir orelse nfs.cwd());
2324 started = true;
2425}
2526
src/none.zig+2-1
......@@ -1,12 +1,13 @@
11const std = @import("std");
22const tracer = @import("./mod.zig");
33const log = std.log.scoped(.tracer);
4const nfs = @import("nfs");
45
56pub fn init() !void {}
67
78pub fn deinit() void {}
89
9pub fn init_thread(dir: std.fs.Dir) !void {
10pub fn init_thread(dir: nfs.Dir) !void {
1011 _ = dir;
1112}
1213
src/spall.zig+12-10
......@@ -3,13 +3,15 @@ const tracer = @import("./mod.zig");
33const alloc = std.heap.c_allocator;
44const log = std.log.scoped(.tracer);
55const root = @import("root");
6const nfs = @import("nfs");
7const nio = @import("nio");
68const linux = @import("sys-linux");
79
810var pid: linux.pid_t = undefined;
911threadlocal var tid: linux.pid_t = undefined;
10threadlocal var path: []const u8 = undefined;
11threadlocal var file: std.fs.File = undefined;
12threadlocal var buffered_writer: std.io.BufferedWriter(4096, std.fs.File.Writer) = undefined;
12threadlocal var path: [:0]const u8 = undefined;
13threadlocal var file: nfs.File = undefined;
14threadlocal var buffered_writer: nio.BufferedWriter(4096, nfs.File) = undefined;
1315
1416pub fn init() !void {
1517 pid = linux.getpid();
......@@ -19,14 +21,14 @@ pub fn deinit() void {
1921 //
2022}
2123
22pub fn init_thread(dir: std.fs.Dir) !void {
24pub fn init_thread(dir: nfs.Dir) !void {
2325 tid = linux.gettid();
2426
25 path = try std.fmt.allocPrint(alloc, "{d}.{d}.spall", .{ pid, tid });
27 path = try std.fmt.allocPrintZ(alloc, "{d}.{d}.spall", .{ pid, tid });
2628 file = try dir.createFile(path, .{});
27 buffered_writer = std.io.bufferedWriter(file.writer());
29 buffered_writer = .init(file);
2830
29 try buffered_writer.writer().writeStruct(Header{});
31 try buffered_writer.writeStruct(Header{});
3032}
3133
3234pub fn deinit_thread() void {
......@@ -39,19 +41,19 @@ pub fn deinit_thread() void {
3941pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: anytype) void {
4042 const fmt = "{s}:{d}:{d} ({s})" ++ ifmt;
4143 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{
4345 .pid = @intCast(pid),
4446 .tid = @intCast(tid),
4547 .time = @floatFromInt(std.time.microTimestamp()),
4648 .name_len = @truncate(std.fmt.count(fmt, args ++ iargs)),
4749 .args_len = 0,
4850 }) catch return;
49 buffered_writer.writer().print(fmt, args ++ iargs) catch return;
51 buffered_writer.print(fmt, args ++ iargs) catch return;
5052}
5153
5254pub inline fn trace_end(ctx: tracer.Ctx) void {
5355 _ = ctx;
54 buffered_writer.writer().writeStruct(EndEvent{
56 buffered_writer.writeStruct(EndEvent{
5557 .pid = @intCast(pid),
5658 .tid = @intCast(tid),
5759 .time = @floatFromInt(std.time.microTimestamp()),
zigmod.yml+5
......@@ -6,3 +6,8 @@ description: Generic tracing library for Zig, supports multiple backends.
66dependencies:
77 - src: git https://github.com/nektro/zig-extras
88 - 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
12root_dependencies:
13 - src: git https://github.com/nektro/zig-nfs