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:...@@ -3,6 +3,12 @@ MIT:
3- This3- This
4- git https://github.com/nektro/zig-extras4- git https://github.com/nektro/zig-extras
5- git https://github.com/nektro/zig-sys-linux5- 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
7Unspecified:13Unspecified:
8- system_lib c14- 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");
3const alloc = std.heap.c_allocator;3const alloc = std.heap.c_allocator;
4const log = std.log.scoped(.tracer);4const log = std.log.scoped(.tracer);
5const root = @import("root");5const root = @import("root");
6const nfs = @import("nfs");
7const nio = @import("nio");
6const linux = @import("sys-linux");8const linux = @import("sys-linux");
79
8var pid: linux.pid_t = undefined;10var pid: linux.pid_t = undefined;
9threadlocal var tid: linux.pid_t = undefined;11threadlocal var tid: linux.pid_t = undefined;
10threadlocal var path: []const u8 = undefined;12threadlocal var path: [:0]const u8 = undefined;
11threadlocal var file: std.fs.File = undefined;13threadlocal var file: nfs.File = undefined;
12threadlocal var buffered_writer: std.io.BufferedWriter(4096, std.fs.File.Writer) = undefined;14threadlocal var buffered_writer: nio.BufferedWriter(4096, nfs.File) = undefined;
1315
14pub fn init() !void {16pub 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}
2123
22pub fn init_thread(dir: std.fs.Dir) !void {24pub fn init_thread(dir: nfs.Dir) !void {
23 tid = linux.gettid();25 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 });
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);
2830
29 try buffered_writer.writer().writeAll("[\n");31 try buffered_writer.writeAll("[\n");
30}32}
3133
32pub fn deinit_thread() void {34pub fn deinit_thread() void {
33 defer alloc.free(path);35 defer alloc.free(path);
34 defer file.close();36 defer file.close();
3537
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}
3941
40pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: anytype) void {42pub 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
5961
60pub inline fn trace_end(ctx: tracer.Ctx) void {62pub 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 @@
1const std = @import("std");1const std = @import("std");
2const tracer = @import("./mod.zig");2const tracer = @import("./mod.zig");
3const log = std.log.scoped(.tracer);3const log = std.log.scoped(.tracer);
4const nfs = @import("nfs");
45
5pub fn init() !void {}6pub fn init() !void {}
67
7pub fn deinit() void {}8pub fn deinit() void {}
89
9pub fn init_thread(dir: std.fs.Dir) !void {10pub fn init_thread(dir: nfs.Dir) !void {
10 _ = dir;11 _ = dir;
11}12}
1213
src/main.zig+3-1
...@@ -1,5 +1,7 @@...@@ -1,5 +1,7 @@
1const std = @import("std");1const std = @import("std");
2const tracer = @import("tracer");2const tracer = @import("tracer");
3const nfs = @import("nfs");
4
3pub const build_options = @import("build_options");5pub const build_options = @import("build_options");
46
5pub const tracer_impl = switch (build_options.backend) {7pub 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();
2325
24 handler();26 handler();
src/mod.zig+3-2
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const std = @import("std");1const std = @import("std");
2const root = @import("root");2const root = @import("root");
3const extras = @import("extras");3const extras = @import("extras");
4const nfs = @import("nfs");
4const impl = extras.globalOption("tracer_impl", type) orelse none;5const impl = extras.globalOption("tracer_impl", type) orelse none;
56
6threadlocal var started = false;7threadlocal 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}
2021
21pub fn init_thread(dir: ?std.fs.Dir) !void {22pub 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}
2526
src/none.zig+2-1
...@@ -1,12 +1,13 @@...@@ -1,12 +1,13 @@
1const std = @import("std");1const std = @import("std");
2const tracer = @import("./mod.zig");2const tracer = @import("./mod.zig");
3const log = std.log.scoped(.tracer);3const log = std.log.scoped(.tracer);
4const nfs = @import("nfs");
45
5pub fn init() !void {}6pub fn init() !void {}
67
7pub fn deinit() void {}8pub fn deinit() void {}
89
9pub fn init_thread(dir: std.fs.Dir) !void {10pub fn init_thread(dir: nfs.Dir) !void {
10 _ = dir;11 _ = dir;
11}12}
1213
src/spall.zig+12-10
...@@ -3,13 +3,15 @@ const tracer = @import("./mod.zig");...@@ -3,13 +3,15 @@ const tracer = @import("./mod.zig");
3const alloc = std.heap.c_allocator;3const alloc = std.heap.c_allocator;
4const log = std.log.scoped(.tracer);4const log = std.log.scoped(.tracer);
5const root = @import("root");5const root = @import("root");
6const nfs = @import("nfs");
7const nio = @import("nio");
6const linux = @import("sys-linux");8const linux = @import("sys-linux");
79
8var pid: linux.pid_t = undefined;10var pid: linux.pid_t = undefined;
9threadlocal var tid: linux.pid_t = undefined;11threadlocal var tid: linux.pid_t = undefined;
10threadlocal var path: []const u8 = undefined;12threadlocal var path: [:0]const u8 = undefined;
11threadlocal var file: std.fs.File = undefined;13threadlocal var file: nfs.File = undefined;
12threadlocal var buffered_writer: std.io.BufferedWriter(4096, std.fs.File.Writer) = undefined;14threadlocal var buffered_writer: nio.BufferedWriter(4096, nfs.File) = undefined;
1315
14pub fn init() !void {16pub 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}
2123
22pub fn init_thread(dir: std.fs.Dir) !void {24pub fn init_thread(dir: nfs.Dir) !void {
23 tid = linux.gettid();25 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 });
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);
2830
29 try buffered_writer.writer().writeStruct(Header{});31 try buffered_writer.writeStruct(Header{});
30}32}
3133
32pub fn deinit_thread() void {34pub fn deinit_thread() void {
...@@ -39,19 +41,19 @@ pub fn deinit_thread() void {...@@ -39,19 +41,19 @@ pub fn deinit_thread() void {
39pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: anytype) void {41pub 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}
5153
52pub inline fn trace_end(ctx: tracer.Ctx) void {54pub 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.
6dependencies:6dependencies:
7 - src: git https://github.com/nektro/zig-extras7 - src: git https://github.com/nektro/zig-extras
8 - src: git https://github.com/nektro/zig-sys-linux8 - 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