Debian Codegraph @

debian/rust-vendor/codspeed/instrument-hooks/src/features.zig

raw
1 const std = @import("std");
2
3 pub const Feature = enum(u64) {
4 // When enabled, we will not call the CALLGRIND_START_INSTRUMENTATION and CALLGRIND_STOP_INSTRUMENTATION markers.
5 // This is useful when you notice additional overhead from this library in microbenchmarks, but means you
6 // have to manually call them in your code.
7 disable_callgrind_markers = 0,
8 };
9
10 var features = std.StaticBitSet(64).initEmpty();
11
12 pub fn set_feature(feature: Feature, enabled: bool) void {
13 if (enabled) {
14 features.set(@intFromEnum(feature));
15 } else {
16 features.unset(@intFromEnum(feature));
17 }
18 }
19
20 pub fn is_feature_enabled(feature: Feature) bool {
21 return features.isSet(@intFromEnum(feature));
22 }
23
24 test "set_feature and is_feature_enabled" {
25 set_feature(Feature.disable_callgrind_markers, false);
26 try std.testing.expect(!is_feature_enabled(Feature.disable_callgrind_markers));
27 set_feature(Feature.disable_callgrind_markers, true);
28 try std.testing.expect(is_feature_enabled(Feature.disable_callgrind_markers));
29 }