1#![deny(warnings)]
2#![recursion_limit = "512"]
3
4use serde::{Deserialize, Serialize};
5use std::str::FromStr;
6use strum::EnumProperty;
7use strum_macros::{AsRefStr, EnumProperty, EnumString};
8
9mod argtypes;
10mod build_rs;
11mod cache;
12mod cargo;
13mod deps;
14mod error;
15mod gen;
16mod hashing;
17pub mod proc_macros;
18mod serde_helpers;
19mod spec;
20mod syn_helpers;
21#[cfg(test)]
22mod testdata;
23
24pub use build_rs::{build, tracers_build};
26pub use error::*;
27
28#[derive(Debug, AsRefStr, Serialize, Deserialize, PartialEq, EnumString)]
32pub(crate) enum TracingType {
33 #[strum(serialize = "disabled")]
34 Disabled,
35 #[strum(serialize = "static")]
36 Static,
37 #[strum(serialize = "dynamic")]
38 Dynamic,
39}
40
41impl TracingType {
42 pub fn is_enabled(&self) -> bool {
43 *self != TracingType::Disabled
44 }
45}
46
47#[derive(Debug, AsRefStr, Serialize, Deserialize, PartialEq, EnumString)]
49pub(crate) enum TracingTarget {
50 #[strum(serialize = "disabled")]
51 Disabled,
52 #[strum(serialize = "stap")]
53 Stap,
54 #[strum(serialize = "lttng")]
55 Lttng,
56 #[strum(serialize = "noop")]
57 NoOp,
58}
59
60impl TracingTarget {
61 pub fn is_enabled(&self) -> bool {
62 *self != TracingTarget::Disabled && *self != TracingTarget::NoOp
63 }
64
65 pub fn has_native_enabled_func(&self) -> bool {
66 *self == TracingTarget::Lttng
69 }
70}
71
72#[derive(Clone, Debug, AsRefStr, Serialize, Deserialize, EnumProperty, PartialEq)]
75pub(crate) enum TracingImplementation {
76 #[strum(serialize = "disabled", props(type = "disabled", target = "disabled"))]
77 Disabled,
78
79 #[strum(serialize = "static_stap", props(type = "static", target = "stap"))]
80 StaticStap,
81
82 #[strum(serialize = "static_lttng", props(type = "static", target = "lttng"))]
83 StaticLttng,
84
85 #[strum(serialize = "static_noop", props(type = "static", target = "noop"))]
86 StaticNoOp,
87
88 #[strum(serialize = "dyn_stap", props(type = "dynamic", target = "stap"))]
89 DynamicStap,
90
91 #[strum(serialize = "dyn_noop", props(type = "dynamic", target = "noop"))]
92 DynamicNoOp,
93}
94
95impl TracingImplementation {
96 pub fn tracing_type(&self) -> TracingType {
97 TracingType::from_str(&*self.get_str("type").unwrap()).unwrap()
98 }
99
100 pub fn tracing_target(&self) -> TracingTarget {
101 TracingTarget::from_str(&*self.get_str("target").unwrap()).unwrap()
102 }
103
104 pub fn is_enabled(&self) -> bool {
105 self.tracing_type().is_enabled()
106 }
107
108 pub fn is_dynamic(&self) -> bool {
109 self.tracing_type() == TracingType::Dynamic
110 }
111
112 pub fn is_static(&self) -> bool {
113 self.tracing_type() == TracingType::Static
114 }
115}