authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-04-26 19:15:51 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-04-27 20:59:51 -07:00
logc42ff8d7185789845d5986af43aa66f9fdd90c5a
tree2f495ef22f096092ac6cccf6bee0c9f3925495d6
parentccbff4bf3ad50eaba9a89f8dffbd37fd8b5099ad
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

make the init and init_thread params configurable


7 files changed, 31 insertions(+), 20 deletions(-)

README.md+3-2
...@@ -15,17 +15,18 @@ in your program:...@@ -15,17 +15,18 @@ in your program:
15```zig15```zig
16const std = @import("std");16const std = @import("std");
17const tracer = @import("tracer");17const tracer = @import("tracer");
18const nfs = @import("nfs");
18pub const build_options = @import("build_options");19pub const build_options = @import("build_options");
1920
20pub const tracer_impl = tracer.spall; // see 'Backends' section below21pub const tracer_impl = tracer.spall; // see 'Backends' section below
2122
22pub fn main() !void {23pub fn main() !void {
23 try tracer.init();24 try tracer.init(.{});
24 defer tracer.deinit();25 defer tracer.deinit();
2526
26 // main loop27 // main loop
27 while (true) {28 while (true) {
28 try tracer.init_thread();29 try tracer.init_thread(.{nfs.cwd()});
29 defer tracer.deinit_thread();30 defer tracer.deinit_thread();
3031
31 handler();32 handler();
src/chrome.zig+4-2
...@@ -14,7 +14,8 @@ threadlocal var path: [:0]const u8 = undefined;...@@ -14,7 +14,8 @@ threadlocal var path: [:0]const u8 = undefined;
14threadlocal var file: nfs.File = undefined;14threadlocal var file: nfs.File = undefined;
15threadlocal var buffered_writer: nio.BufferedWriter(4096, nfs.File) = undefined;15threadlocal var buffered_writer: nio.BufferedWriter(4096, nfs.File) = undefined;
1616
17pub fn init() !void {17pub fn init(args: struct {}) !void {
18 _ = args;
18 pid = linux.getpid();19 pid = linux.getpid();
19}20}
2021
...@@ -22,7 +23,8 @@ pub fn deinit() void {...@@ -22,7 +23,8 @@ pub fn deinit() void {
22 //23 //
23}24}
2425
25pub fn init_thread(dir: nfs.Dir) !void {26pub fn init_thread(args: struct { nfs.Dir }) !void {
27 const dir = args[0];
26 tid = linux.gettid();28 tid = linux.gettid();
2729
28 path = try std.fmt.allocPrintZ(alloc, "trace.{d}.{d}.chrome.json", .{ pid, tid });30 path = try std.fmt.allocPrintZ(alloc, "trace.{d}.{d}.chrome.json", .{ pid, tid });
src/log.zig+5-4
...@@ -1,14 +1,15 @@...@@ -1,14 +1,15 @@
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");
54
6pub fn init() !void {}5pub fn init(args: struct {}) !void {
6 _ = args;
7}
78
8pub fn deinit() void {}9pub fn deinit() void {}
910
10pub fn init_thread(dir: nfs.Dir) !void {11pub fn init_thread(args: struct {}) !void {
11 _ = dir;12 _ = args;
12}13}
1314
14pub fn deinit_thread() void {}15pub fn deinit_thread() void {}
src/main.zig+6-2
...@@ -13,14 +13,18 @@ pub const tracer_impl = switch (build_options.backend) {...@@ -13,14 +13,18 @@ pub const tracer_impl = switch (build_options.backend) {
13};13};
1414
15pub fn main() !void {15pub fn main() !void {
16 try tracer.init();16 try tracer.init(.{});
17 defer tracer.deinit();17 defer tracer.deinit();
1818
19 // main loop19 // main loop
20 var go = false;20 var go = false;
21 _ = &go;21 _ = &go;
22 while (go) {22 while (go) {
23 try tracer.init_thread(nfs.cwd());23 try tracer.init_thread(switch (build_options.backend) {
24 0, 1 => .{},
25 2, 3 => .{nfs.cwd()},
26 else => comptime unreachable,
27 });
24 defer tracer.deinit_thread();28 defer tracer.deinit_thread();
2529
26 handler();30 handler();
src/mod.zig+4-4
...@@ -11,16 +11,16 @@ pub const log = @import("./log.zig");...@@ -11,16 +11,16 @@ pub const log = @import("./log.zig");
11pub const chrome = @import("./chrome.zig");11pub const chrome = @import("./chrome.zig");
12pub const spall = @import("./spall.zig");12pub const spall = @import("./spall.zig");
1313
14pub fn init() !void {14pub fn init(args: @typeInfo(@TypeOf(impl.init)).@"fn".params[0].type.?) !void {
15 try impl.init();15 try impl.init(args);
16}16}
1717
18pub fn deinit() void {18pub fn deinit() void {
19 impl.deinit();19 impl.deinit();
20}20}
2121
22pub fn init_thread(dir: ?nfs.Dir) !void {22pub fn init_thread(args: @typeInfo(@TypeOf(impl.init_thread)).@"fn".params[0].type.?) !void {
23 try impl.init_thread(dir orelse nfs.cwd());23 try impl.init_thread(args);
24 started = true;24 started = true;
25}25}
2626
src/none.zig+5-4
...@@ -1,14 +1,15 @@...@@ -1,14 +1,15 @@
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");
54
6pub fn init() !void {}5pub fn init(args: struct {}) !void {
6 _ = args;
7}
78
8pub fn deinit() void {}9pub fn deinit() void {}
910
10pub fn init_thread(dir: nfs.Dir) !void {11pub fn init_thread(args: struct {}) !void {
11 _ = dir;12 _ = args;
12}13}
1314
14pub fn deinit_thread() void {}15pub fn deinit_thread() void {}
src/spall.zig+4-2
...@@ -14,7 +14,8 @@ threadlocal var path: [:0]const u8 = undefined;...@@ -14,7 +14,8 @@ threadlocal var path: [:0]const u8 = undefined;
14threadlocal var file: nfs.File = undefined;14threadlocal var file: nfs.File = undefined;
15threadlocal var buffered_writer: nio.BufferedWriter(4096, nfs.File) = undefined;15threadlocal var buffered_writer: nio.BufferedWriter(4096, nfs.File) = undefined;
1616
17pub fn init() !void {17pub fn init(args: struct {}) !void {
18 _ = args;
18 pid = linux.getpid();19 pid = linux.getpid();
19}20}
2021
...@@ -22,7 +23,8 @@ pub fn deinit() void {...@@ -22,7 +23,8 @@ pub fn deinit() void {
22 //23 //
23}24}
2425
25pub fn init_thread(dir: nfs.Dir) !void {26pub fn init_thread(args: struct { nfs.Dir }) !void {
27 const dir = args[0];
26 tid = linux.gettid();28 tid = linux.gettid();
2729
28 path = try std.fmt.allocPrintZ(alloc, "{d}.{d}.spall", .{ pid, tid });30 path = try std.fmt.allocPrintZ(alloc, "{d}.{d}.spall", .{ pid, tid });