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::{ArgValue, AsTraceStrRef, Scope, duration, instant};
31 use fuchsia_trace::{TraceCategoryContext, trace_site_t};
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 let Some(context) = $crate::__inner::category_context() {
54 use $crate::__inner::AsTraceStrRef as _;
55
56 args = [$($crate::__inner::ArgValue::of_registered(
57 $key.as_trace_str_ref(&context),
58 $val,
59 )),*];
60
61 Some($crate::__inner::duration($crate::CATEGORY, $name, &args))
62 } else {
63 None
64 }
65 };
66 }
67 }
68
69 #[macro_export]
73 macro_rules! trace_instant {
74 ($name:expr $(, $key:expr => $val:expr)* $(,)?) => {
75 if let Some(context) = $crate::__inner::category_context() {
76 use $crate::__inner::AsTraceStrRef as _;
77
78 let args = [$($crate::__inner::ArgValue::of_registered(
79 $key.as_trace_str_ref(&context),
80 $val,
81 )),*];
82
83 $crate::__inner::instant(
84 &context,
85 $name,
86 $crate::__inner::Scope::Thread,
87 &args
88 );
89 }
90 }
91 }
92}
93
94#[cfg(not(target_os = "fuchsia"))]
96#[allow(missing_docs)]
97pub mod __inner {
98 #[macro_export]
99 macro_rules! trace_duration {
100 ($name:expr $(, $key:expr => $val:expr)* $(,)?) => {
101 $(
102 let _ = $key;
103 let _ = $val;
104 )*
105 }
106 }
107
108 #[macro_export]
109 macro_rules! trace_instant {
110 ($name:expr $(, $key:expr => $val:expr)* $(,)?) => {
111 $(
112 let _ = $key;
113 let _ = $val;
114 )*
115 }
116 }
117}
118
119pub use id::TraceResourceId;