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