-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add support for analysis mode #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
not-matthias
merged 5 commits into
main
from
cod-1710-instrument-hooks-support-new-analysis-mode
Nov 27, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bcc85db
feat: add new FIFO cmds
not-matthias 790d752
fix: use runner-shared for deserialization tests
not-matthias 8a3043f
feat: add shared runner fifo struct
not-matthias f22b1f4
feat: add analysis instrument
not-matthias 075ad83
chore: release new core.c
not-matthias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| const shared = @import("../shared.zig"); | ||
| const fifo_instrument = @import("fifo_instrument.zig"); | ||
|
|
||
| const AnalysisError = error{ModeError}; | ||
|
|
||
| pub const AnalysisInstrument = fifo_instrument.FifoInstrument(.Analysis, AnalysisError); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| const std = @import("std"); | ||
| const runner_fifo = @import("../runner_fifo.zig"); | ||
| const shared = @import("../shared.zig"); | ||
|
|
||
| /// Creates a complete FIFO-based instrument struct that validates a specific integration mode | ||
| pub fn FifoInstrument(comptime mode: shared.IntegrationMode, comptime error_type: anytype) type { | ||
not-matthias marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return struct { | ||
| fifo: runner_fifo.RunnerFifo, | ||
|
|
||
| const Self = @This(); | ||
|
|
||
| pub fn init(allocator: std.mem.Allocator) !Self { | ||
| var fifo = try runner_fifo.RunnerFifo.init(allocator); | ||
|
|
||
| // Get the instrumentation mode from the runner | ||
| const detected_mode = fifo.get_integration_mode() catch |err| { | ||
| fifo.deinit(); | ||
| return err; | ||
| }; | ||
not-matthias marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Only accept if the runner is in the correct mode | ||
| if (detected_mode != mode) { | ||
| fifo.deinit(); | ||
| return error_type.ModeError; | ||
| } | ||
|
|
||
| return Self{ .fifo = fifo }; | ||
| } | ||
|
|
||
| pub fn deinit(self: *Self) void { | ||
| self.fifo.deinit(); | ||
| } | ||
|
|
||
| pub fn send_version(self: *Self, protocol_version: u64) !void { | ||
| try self.fifo.send_version(protocol_version); | ||
| } | ||
|
|
||
| pub fn start_benchmark(self: *Self) !void { | ||
| try self.fifo.start_benchmark(); | ||
| } | ||
|
|
||
| pub fn stop_benchmark(self: *Self) !void { | ||
| try self.fifo.stop_benchmark(); | ||
| } | ||
|
|
||
| pub fn set_executed_benchmark(self: *Self, pid: u32, uri: [*c]const u8) !void { | ||
| try self.fifo.set_executed_benchmark(pid, uri); | ||
| } | ||
|
|
||
| pub fn set_integration(self: *Self, name: [*c]const u8, version: [*c]const u8) !void { | ||
| try self.fifo.set_integration(name, version); | ||
| } | ||
|
|
||
| pub fn add_marker(self: *Self, pid: u32, marker: shared.MarkerType) !void { | ||
| try self.fifo.add_marker(pid, marker); | ||
| } | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,158 +1,6 @@ | ||
| const std = @import("std"); | ||
| const fifo = @import("../fifo.zig"); | ||
| const shared = @import("../shared.zig"); | ||
| const fifo_instrument = @import("fifo_instrument.zig"); | ||
|
|
||
| pub const PerfInstrument = struct { | ||
| allocator: std.mem.Allocator, | ||
| writer: fifo.UnixPipe.Writer, | ||
| reader: fifo.UnixPipe.Reader, | ||
| const PerfError = error{ModeError}; | ||
|
|
||
| const Self = @This(); | ||
|
|
||
| pub fn init(allocator: std.mem.Allocator) !Self { | ||
| return .{ | ||
| .allocator = allocator, | ||
| .writer = try fifo.UnixPipe.openWrite(allocator, shared.RUNNER_CTL_FIFO), | ||
| .reader = try fifo.UnixPipe.openRead(allocator, shared.RUNNER_ACK_FIFO), | ||
| }; | ||
| } | ||
|
|
||
| pub fn deinit(self: *Self) void { | ||
| self.writer.deinit(); | ||
| self.reader.deinit(); | ||
| } | ||
|
|
||
| pub fn send_cmd(self: *Self, cmd: fifo.Command) !void { | ||
| try self.writer.sendCmd(cmd); | ||
| try self.reader.waitForAck(null); | ||
| } | ||
|
|
||
| pub fn is_instrumented(self: *Self) bool { | ||
| self.send_cmd(fifo.Command.PingPerf) catch { | ||
| return false; | ||
| }; | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| pub noinline fn start_benchmark(self: *Self) !void { | ||
| @branchHint(.cold); // Prevent inline | ||
|
|
||
| try self.writer.sendCmd(fifo.Command.StartBenchmark); | ||
| try self.reader.waitForAck(null); | ||
| } | ||
|
|
||
| pub noinline fn stop_benchmark(self: *Self) !void { | ||
| @branchHint(.cold); // Prevent inline | ||
|
|
||
| try self.writer.sendCmd(fifo.Command.StopBenchmark); | ||
| try self.reader.waitForAck(null); | ||
| } | ||
|
|
||
| pub fn set_executed_benchmark(self: *Self, pid: u32, uri: [*c]const u8) !void { | ||
| try self.writer.sendCmd(fifo.Command{ .ExecutedBenchmark = .{ | ||
| .pid = pid, | ||
| .uri = std.mem.span(uri), | ||
| } }); | ||
| try self.reader.waitForAck(null); | ||
| } | ||
|
|
||
| pub fn set_integration(self: *Self, name: [*c]const u8, version: [*c]const u8) !void { | ||
| try self.writer.sendCmd(fifo.Command{ .SetIntegration = .{ | ||
| .name = std.mem.span(name), | ||
| .version = std.mem.span(version), | ||
| } }); | ||
| try self.reader.waitForAck(null); | ||
| } | ||
|
|
||
| pub fn add_marker(self: *Self, pid: u32, marker: shared.MarkerType) !void { | ||
| try self.writer.sendCmd(fifo.Command{ .AddMarker = .{ | ||
| .pid = pid, | ||
| .marker = marker, | ||
| } }); | ||
| try self.reader.waitForAck(null); | ||
| } | ||
|
|
||
| pub fn send_version(self: *Self, protocol_version: u64) !void { | ||
| try self.writer.sendCmd(fifo.Command{ .SetVersion = protocol_version }); | ||
| try self.reader.waitForAck(null); | ||
| } | ||
| }; | ||
|
|
||
| test "perf integration" { | ||
| const allocator = std.testing.allocator; | ||
|
|
||
| try fifo.UnixPipe.create(shared.RUNNER_ACK_FIFO); | ||
| try fifo.UnixPipe.create(shared.RUNNER_CTL_FIFO); | ||
|
|
||
| var ctl_fifo = try fifo.UnixPipe.openRead(allocator, shared.RUNNER_CTL_FIFO); | ||
| defer ctl_fifo.deinit(); | ||
|
|
||
| var ack_fifo = try fifo.UnixPipe.openWrite(allocator, shared.RUNNER_ACK_FIFO); | ||
| defer ack_fifo.deinit(); | ||
|
|
||
| const FifoTester = struct { | ||
| allocator: std.mem.Allocator, | ||
| ctl_pipe: *fifo.UnixPipe.Reader, | ||
| ack_pipe: *fifo.UnixPipe.Writer, | ||
|
|
||
| received_cmd: ?fifo.Command = null, | ||
| error_occurred: bool = false, | ||
|
|
||
| pub fn func(ctx: *@This()) void { | ||
| const received_cmd = ctx.ctl_pipe.recvCmd() catch |err| { | ||
| std.debug.print("Failed to receive command: {}\n", .{err}); | ||
| ctx.error_occurred = true; | ||
| return; | ||
| }; | ||
| ctx.received_cmd = received_cmd; | ||
|
|
||
| ctx.ack_pipe.sendCmd(fifo.Command.Ack) catch |err| { | ||
| std.debug.print("Failed to send ACK: {}\n", .{err}); | ||
| ctx.error_occurred = true; | ||
| }; | ||
| } | ||
|
|
||
| pub fn send(self: *@This(), comptime f: anytype, args: anytype) !fifo.Command { | ||
| // 1. Create the thread which handles the command | ||
| // 2. Execute the callback | ||
| // 3. Wait for the thread to finish | ||
| // | ||
| const receiver_thread = try std.Thread.spawn(.{}, @This().func, .{self}); | ||
| try @call(.auto, f, args); | ||
| receiver_thread.join(); | ||
|
|
||
| if (self.error_occurred) { | ||
| return error.IntegrationError; | ||
| } | ||
| self.error_occurred = false; | ||
|
|
||
| return self.received_cmd.?; | ||
| } | ||
| }; | ||
|
|
||
| var tester = FifoTester{ | ||
| .allocator = allocator, | ||
| .ctl_pipe = &ctl_fifo, | ||
| .ack_pipe = &ack_fifo, | ||
| }; | ||
|
|
||
| var perf = try PerfInstrument.init(allocator); | ||
| defer perf.deinit(); | ||
|
|
||
| const si_result = try tester.send(PerfInstrument.set_integration, .{ &perf, "zig", "0.10.0" }); | ||
| try std.testing.expect(si_result.equal(fifo.Command{ .SetIntegration = .{ .name = "zig", .version = "0.10.0" } })); | ||
| si_result.deinit(allocator); | ||
|
|
||
| const cb_result = try tester.send(PerfInstrument.set_executed_benchmark, .{ &perf, 42, "foo" }); | ||
| try std.testing.expect(cb_result.equal(fifo.Command{ .ExecutedBenchmark = .{ .pid = 42, .uri = "foo" } })); | ||
| cb_result.deinit(allocator); | ||
|
|
||
| const start_result = try tester.send(PerfInstrument.start_benchmark, .{&perf}); | ||
| try std.testing.expect(start_result.equal(fifo.Command.StartBenchmark)); | ||
| start_result.deinit(allocator); | ||
|
|
||
| const stop_result = try tester.send(PerfInstrument.stop_benchmark, .{&perf}); | ||
| try std.testing.expect(stop_result.equal(fifo.Command.StopBenchmark)); | ||
| stop_result.deinit(allocator); | ||
| } | ||
| pub const PerfInstrument = fifo_instrument.FifoInstrument(.Perf, PerfError); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.