11const std = @import ("std" );
2- const builtin = @import ("builtin" );
32const perf = @import ("perf.zig" );
3+ const analysis = @import ("analysis.zig" );
44const valgrind = @import ("valgrind.zig" );
55const shared = @import ("../shared.zig" );
66const ValgrindInstrument = valgrind .ValgrindInstrument ;
7+ const PerfInstrument = perf .PerfInstrument ;
8+ const AnalysisInstrument = analysis .AnalysisInstrument ;
79
810pub const InstrumentHooks = union (enum ) {
911 valgrind : ValgrindInstrument ,
10- perf : perf.PerfInstrument ,
12+ perf : PerfInstrument ,
13+ analysis : AnalysisInstrument ,
1114 none : void ,
1215
1316 const Self = @This ();
1417
1518 pub fn init (allocator : std.mem.Allocator ) ! Self {
16- if (ValgrindInstrument .is_instrumented ()) {
17- return Self { .valgrind = ValgrindInstrument . init ( allocator ) };
18- }
19+ if (ValgrindInstrument .init ( allocator )) | valgrind_inst | {
20+ return Self { .valgrind = valgrind_inst };
21+ } else | _ | {}
1922
20- var perf_inst = perf .PerfInstrument .init (allocator ) catch {
21- return Self { .none = {} };
22- };
23- if (perf_inst .is_instrumented ()) {
23+ if (AnalysisInstrument .init (allocator )) | analysis_inst | {
24+ return Self { .analysis = analysis_inst };
25+ } else | _ | {}
26+
27+ if (PerfInstrument .init (allocator )) | perf_inst | {
2428 return Self { .perf = perf_inst };
25- }
29+ } else | _ | {}
2630
2731 return Self { .none = {} };
2832 }
@@ -31,17 +35,16 @@ pub const InstrumentHooks = union(enum) {
3135 switch (self .* ) {
3236 .valgrind = > {},
3337 .perf = > self .perf .deinit (),
38+ .analysis = > self .analysis .deinit (),
3439 .none = > {},
3540 }
3641 }
3742
3843 pub inline fn is_instrumented (self : * Self ) bool {
3944 return switch (self .* ) {
4045 .valgrind = > ValgrindInstrument .is_instrumented (),
41- .perf = > | perf_inst | {
42- var mutable_perf = perf_inst ;
43- return mutable_perf .is_instrumented ();
44- },
46+ .perf = > true ,
47+ .analysis = > true ,
4548 .none = > false ,
4649 };
4750 }
@@ -51,6 +54,8 @@ pub const InstrumentHooks = union(enum) {
5154 return self .perf .start_benchmark ();
5255 } else if (self .* == .valgrind ) {
5356 return ValgrindInstrument .start_benchmark ();
57+ } else if (self .* == .analysis ) {
58+ return self .analysis .start_benchmark ();
5459 }
5560 }
5661
@@ -59,13 +64,16 @@ pub const InstrumentHooks = union(enum) {
5964 return ValgrindInstrument .stop_benchmark ();
6065 } else if (self .* == .perf ) {
6166 return self .perf .stop_benchmark ();
67+ } else if (self .* == .analysis ) {
68+ return self .analysis .stop_benchmark ();
6269 }
6370 }
6471
6572 pub inline fn set_executed_benchmark (self : * Self , pid : u32 , uri : [* c ]const u8 ) ! void {
6673 switch (self .* ) {
6774 .valgrind = > ValgrindInstrument .set_executed_benchmark (pid , uri ),
6875 .perf = > try self .perf .set_executed_benchmark (pid , uri ),
76+ .analysis = > try self .analysis .set_executed_benchmark (pid , uri ),
6977 .none = > {},
7078 }
7179 }
@@ -74,13 +82,16 @@ pub const InstrumentHooks = union(enum) {
7482 switch (self .* ) {
7583 .valgrind = > try self .valgrind .set_integration (name , version ),
7684 .perf = > try self .perf .set_integration (name , version ),
85+ .analysis = > try self .analysis .set_integration (name , version ),
7786 .none = > {},
7887 }
7988 }
8089
8190 pub inline fn add_marker (self : * Self , pid : u32 , marker : shared.MarkerType ) ! void {
8291 if (self .* == .perf ) {
8392 return self .perf .add_marker (pid , marker );
93+ } else if (self .* == .analysis ) {
94+ return self .analysis .add_marker (pid , marker );
8495 }
8596 }
8697};
0 commit comments