1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#![deny(warnings)]
#![recursion_limit = "512"]

use serde::{Deserialize, Serialize};
use std::str::FromStr;
use strum::EnumProperty;
use strum_macros::{AsRefStr, EnumProperty, EnumString};

mod argtypes;
mod build_rs;
mod cache;
mod cargo;
mod deps;
mod error;
mod gen;
mod hashing;
pub mod proc_macros;
mod serde_helpers;
mod spec;
mod syn_helpers;
#[cfg(test)]
mod testdata;

//Export some of the internal types from their (private) modules
pub use build_rs::{build, tracers_build};
pub use error::*;

/// The categories of tracing implementations.  Within `Static` and `Dynamic` there are various
/// platform-specific implementations, however the behavior of all implementations within a
/// category is broadly identical
#[derive(Debug, AsRefStr, Serialize, Deserialize, PartialEq, EnumString)]
pub(crate) enum TracingType {
    #[strum(serialize = "disabled")]
    Disabled,
    #[strum(serialize = "static")]
    Static,
    #[strum(serialize = "dynamic")]
    Dynamic,
}

impl TracingType {
    pub fn is_enabled(&self) -> bool {
        *self != TracingType::Disabled
    }
}

/// The possible platform-specific implementations of tracing, regardless of which type they are
#[derive(Debug, AsRefStr, Serialize, Deserialize, PartialEq, EnumString)]
pub(crate) enum TracingTarget {
    #[strum(serialize = "disabled")]
    Disabled,
    #[strum(serialize = "stap")]
    Stap,
    #[strum(serialize = "lttng")]
    Lttng,
    #[strum(serialize = "noop")]
    NoOp,
}

impl TracingTarget {
    pub fn is_enabled(&self) -> bool {
        *self != TracingTarget::Disabled && *self != TracingTarget::NoOp
    }

    pub fn has_native_enabled_func(&self) -> bool {
        //Thus far only LTTng provides a native version of a function to call to test for
        //enablement.  All others use a semaphore variable that can be queried directly
        *self == TracingTarget::Lttng
    }
}

/// All possible tracing implementations.  Every supported linear combination of `TracingType` and
/// `TracingTarget`
#[derive(Clone, Debug, AsRefStr, Serialize, Deserialize, EnumProperty, PartialEq)]
pub(crate) enum TracingImplementation {
    #[strum(serialize = "disabled", props(type = "disabled", target = "disabled"))]
    Disabled,

    #[strum(serialize = "static_stap", props(type = "static", target = "stap"))]
    StaticStap,

    #[strum(serialize = "static_lttng", props(type = "static", target = "lttng"))]
    StaticLttng,

    #[strum(serialize = "static_noop", props(type = "static", target = "noop"))]
    StaticNoOp,

    #[strum(serialize = "dyn_stap", props(type = "dynamic", target = "stap"))]
    DynamicStap,

    #[strum(serialize = "dyn_noop", props(type = "dynamic", target = "noop"))]
    DynamicNoOp,
}

impl TracingImplementation {
    pub fn tracing_type(&self) -> TracingType {
        TracingType::from_str(&*self.get_str("type").unwrap()).unwrap()
    }

    pub fn tracing_target(&self) -> TracingTarget {
        TracingTarget::from_str(&*self.get_str("target").unwrap()).unwrap()
    }

    pub fn is_enabled(&self) -> bool {
        self.tracing_type().is_enabled()
    }

    pub fn is_dynamic(&self) -> bool {
        self.tracing_type() == TracingType::Dynamic
    }

    pub fn is_static(&self) -> bool {
        self.tracing_type() == TracingType::Static
    }
}