Debian Codegraph @

debian/rust-vendor/codspeed/instrument-hooks/src/instruments/fifo_instrument.zig

raw
1 const std = @import("std");
2 const runner_fifo = @import("../runner_fifo.zig");
3 const shared = @import("../shared.zig");
4
5 /// Creates a complete FIFO-based instrument struct that validates a specific integration mode
6 pub fn FifoInstrument(comptime mode: shared.IntegrationMode, comptime error_type: anytype) type {
7 return struct {
8 fifo: runner_fifo.RunnerFifo,
9
10 const Self = @This();
11
12 pub fn init(allocator: std.mem.Allocator) !Self {
13 var fifo = try runner_fifo.RunnerFifo.init(allocator);
14
15 // Ensure both the runner and integration FIFO are compatible
16 try fifo.validate_protocol_version();
17
18 // Get the instrumentation mode from the runner
19 const detected_mode = fifo.get_integration_mode() catch |err| {
20 fifo.deinit();
21 return err;
22 };
23
24 // Only accept if the runner is in the correct mode
25 if (detected_mode != mode) {
26 fifo.deinit();
27 return error_type.ModeError;
28 }
29
30 return Self{ .fifo = fifo };
31 }
32
33 pub fn deinit(self: *Self) void {
34 self.fifo.deinit();
35 }
36
37 pub fn send_version(self: *Self, protocol_version: u64) !void {
38 try self.fifo.send_version(protocol_version);
39 }
40
41 pub fn start_benchmark(self: *Self) !void {
42 try self.fifo.start_benchmark();
43 }
44
45 pub fn stop_benchmark(self: *Self) !void {
46 try self.fifo.stop_benchmark();
47 }
48
49 pub fn set_executed_benchmark(self: *Self, pid: i32, uri: [*c]const u8) !void {
50 try self.fifo.set_executed_benchmark(pid, uri);
51 }
52
53 pub fn set_integration(self: *Self, name: [*c]const u8, version: [*c]const u8) !void {
54 try self.fifo.set_integration(name, version);
55 }
56
57 pub fn add_marker(self: *Self, pid: i32, marker: shared.MarkerType) !void {
58 try self.fifo.add_marker(pid, marker);
59 }
60 };
61 }