netstack3_trace/
lib.rs
1#![no_std]
12#![warn(missing_docs, unreachable_patterns, clippy::useless_conversion, clippy::redundant_clone)]
13
14mod id;
15
16pub const CATEGORY: &'static core::ffi::CStr = c"net";
18
19#[cfg(target_os = "fuchsia")]
21pub mod __inner {
22 use super::CATEGORY;
23
24 pub use fuchsia_trace::{duration, instant, ArgValue, Scope};
25 use fuchsia_trace::{trace_site_t, TraceCategoryContext};
26
27 static CACHE: trace_site_t = trace_site_t::new(0);
32
33 #[inline]
35 pub fn category_context() -> Option<TraceCategoryContext> {
36 TraceCategoryContext::acquire_cached(CATEGORY, &CACHE)
37 }
38
39 #[macro_export]
43 macro_rules! trace_duration {
44 ($name:expr $(, $key:expr => $val:expr)* $(,)?) => {
45 let mut args;
46 let _scope = {
47 if $crate::__inner::category_context().is_some() {
48 args = [$($crate::__inner::ArgValue::of($key, $val)),*];
49 Some($crate::__inner::duration($crate::CATEGORY, $name, &args))
50 } else {
51 None
52 }
53 };
54 }
55 }
56
57 #[macro_export]
61 macro_rules! trace_instant {
62 ($name:expr $(, $key:expr => $val:expr)* $(,)?) => {
63 if let Some(context) = $crate::__inner::category_context() {
64 let args = [$($crate::__inner::ArgValue::of($key, $val)),*];
65 $crate::__inner::instant(
66 &context,
67 $name,
68 $crate::__inner::Scope::Thread,
69 &args
70 );
71 }
72 }
73 }
74}
75
76#[cfg(not(target_os = "fuchsia"))]
78#[allow(missing_docs)]
79pub mod __inner {
80 #[macro_export]
81 macro_rules! trace_duration {
82 ($name:expr $(, $key:expr => $val:expr)* $(,)?) => {
83 $(
84 let _ = $key;
85 let _ = $val;
86 )*
87 }
88 }
89
90 #[macro_export]
91 macro_rules! trace_instant {
92 ($name:expr $(, $key:expr => $val:expr)* $(,)?) => {
93 $(
94 let _ = $key;
95 let _ = $val;
96 )*
97 }
98 }
99}
100
101pub use id::TraceResourceId;