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
use serde::Deserialize;
use thiserror::Error;
#[cfg(any(
all(not(target_os = "linux"), not(target_os = "macos")),
feature = "des",
feature = "no-linker"
))]
pub mod record;
#[cfg_attr(any(target_os = "linux", not(feature = "asm")), allow(dead_code))]
mod common;
#[cfg_attr(target_os = "linux", path = "empty.rs")]
#[cfg_attr(all(target_os = "macos", feature = "no-linker"), path = "no-linker.rs")]
#[cfg_attr(
all(target_os = "macos", not(feature = "no-linker")),
path = "linker.rs"
)]
#[cfg_attr(
all(not(target_os = "linux"), not(target_os = "macos")),
path = "no-linker.rs"
)]
mod internal;
pub fn register_probes() -> Result<(), Error> {
crate::internal::register_probes()
}
#[derive(Error, Debug)]
pub enum Error {
#[error(transparent)]
ParseError(#[from] dtrace_parser::DTraceError),
#[error(transparent)]
IO(#[from] std::io::Error),
#[error(transparent)]
Env(#[from] std::env::VarError),
#[error("The file is not a valid object file")]
InvalidFile,
#[error("Failed to call DTrace subprocess")]
DTraceError,
}
#[derive(Default, Debug, Deserialize)]
pub struct CompileProvidersConfig {
pub format: Option<String>,
}
fn format_probe(
format: &Option<String>,
provider_name: &str,
probe_name: &str,
) -> proc_macro2::Ident {
if let Some(fmt) = format {
quote::format_ident!(
"{}",
fmt.replace("{provider}", provider_name)
.replace("{probe}", probe_name)
)
} else {
quote::format_ident!("{}_{}", provider_name, probe_name)
}
}
pub fn compile_providers(
source: &str,
config: &CompileProvidersConfig,
) -> Result<proc_macro2::TokenStream, Error> {
crate::internal::compile_providers(source, config)
}