Skip to main content

hotpath_meta/
lib_off.rs

1pub use hotpath_macros_meta::{future_fn, main, measure, measure_all, skip};
2
3#[macro_export]
4macro_rules! measure_block {
5    ($label:expr, $expr:expr) => {{
6        $expr
7    }};
8}
9
10#[macro_export]
11macro_rules! dbg {
12    ($val:expr $(,)?) => {
13        match $val {
14            tmp => tmp
15        }
16    };
17    ($($val:expr),+ $(,)?) => {
18        ($($crate::dbg!($val)),+,)
19    };
20}
21
22#[macro_export]
23macro_rules! val {
24    ($key:expr) => {{
25        $crate::ValHandle
26    }};
27}
28
29pub struct ValHandle;
30
31impl ValHandle {
32    #[inline]
33    pub fn set<T: std::fmt::Debug>(&self, _value: &T) {}
34}
35
36pub use crate::shared::IntoF64;
37
38#[macro_export]
39macro_rules! gauge {
40    ($key:expr) => {{
41        $crate::GaugeHandle
42    }};
43}
44
45pub struct GaugeHandle;
46
47impl GaugeHandle {
48    #[inline]
49    pub fn set(&self, _value: impl IntoF64) -> &Self {
50        self
51    }
52
53    #[inline]
54    pub fn inc(&self, _delta: impl IntoF64) -> &Self {
55        self
56    }
57
58    #[inline]
59    pub fn dec(&self, _delta: impl IntoF64) -> &Self {
60        self
61    }
62}
63
64#[macro_export]
65macro_rules! channel {
66    ($expr:expr) => {
67        $expr
68    };
69    ($expr:expr, label = $label:expr) => {
70        $expr
71    };
72    ($expr:expr, capacity = $capacity:expr) => {
73        $expr
74    };
75    ($expr:expr, label = $label:expr, capacity = $capacity:expr) => {
76        $expr
77    };
78    ($expr:expr, capacity = $capacity:expr, label = $label:expr) => {
79        $expr
80    };
81    ($expr:expr, log = true) => {
82        $expr
83    };
84    ($expr:expr, label = $label:expr, log = true) => {
85        $expr
86    };
87    ($expr:expr, log = true, label = $label:expr) => {
88        $expr
89    };
90    ($expr:expr, capacity = $capacity:expr, log = true) => {
91        $expr
92    };
93    ($expr:expr, log = true, capacity = $capacity:expr) => {
94        $expr
95    };
96    ($expr:expr, label = $label:expr, capacity = $capacity:expr, log = true) => {
97        $expr
98    };
99    ($expr:expr, label = $label:expr, log = true, capacity = $capacity:expr) => {
100        $expr
101    };
102    ($expr:expr, capacity = $capacity:expr, label = $label:expr, log = true) => {
103        $expr
104    };
105    ($expr:expr, capacity = $capacity:expr, log = true, label = $label:expr) => {
106        $expr
107    };
108    ($expr:expr, log = true, label = $label:expr, capacity = $capacity:expr) => {
109        $expr
110    };
111    ($expr:expr, log = true, capacity = $capacity:expr, label = $label:expr) => {
112        $expr
113    };
114}
115
116#[macro_export]
117macro_rules! stream {
118    ($expr:expr) => {
119        $expr
120    };
121    ($expr:expr, label = $label:expr) => {
122        $expr
123    };
124    ($expr:expr, log = true) => {
125        $expr
126    };
127    ($expr:expr, label = $label:expr, log = true) => {
128        $expr
129    };
130    ($expr:expr, log = true, label = $label:expr) => {
131        $expr
132    };
133}
134
135#[macro_export]
136macro_rules! tokio_runtime {
137    () => {};
138    ($handle:expr) => {};
139}
140
141#[macro_export]
142macro_rules! future {
143    ($fut:expr) => {
144        $fut
145    };
146    ($fut:expr, label = $label:expr) => {
147        $fut
148    };
149    ($fut:expr, log = true) => {
150        $fut
151    };
152    ($fut:expr, label = $label:expr, log = true) => {
153        $fut
154    };
155    ($fut:expr, log = true, label = $label:expr) => {
156        $fut
157    };
158}
159
160pub use crate::Format;
161pub use crate::Section;
162
163pub struct MeasurementGuard {}
164
165impl MeasurementGuard {
166    pub fn new(_name: &'static str, _wrapper: bool) -> Self {
167        Self {}
168    }
169
170    pub fn build(_name: &'static str, _wrapper: bool) -> Self {
171        Self {}
172    }
173}
174
175#[inline]
176pub fn measure_sync<T, F: FnOnce() -> T>(_measurement_loc: &'static str, f: F) -> T {
177    f()
178}
179
180#[inline]
181pub fn measure_sync_log<T: std::fmt::Debug, F: FnOnce() -> T>(
182    _measurement_loc: &'static str,
183    f: F,
184) -> T {
185    f()
186}
187
188pub async fn measure_async<T, Fut>(_measurement_loc: &'static str, fut: Fut) -> T
189where
190    Fut: std::future::Future<Output = T>,
191{
192    fut.await
193}
194
195pub async fn measure_async_log<T: std::fmt::Debug, Fut>(
196    _measurement_loc: &'static str,
197    fut: Fut,
198) -> T
199where
200    Fut: std::future::Future<Output = T>,
201{
202    fut.await
203}
204
205pub async fn measure_async_future<T, Fut>(_measurement_loc: &'static str, fut: Fut) -> T
206where
207    Fut: std::future::Future<Output = T>,
208{
209    fut.await
210}
211
212pub async fn measure_async_future_log<T: std::fmt::Debug, Fut>(
213    _measurement_loc: &'static str,
214    fut: Fut,
215) -> T
216where
217    Fut: std::future::Future<Output = T>,
218{
219    fut.await
220}
221
222pub struct HotpathGuard;
223
224impl Default for HotpathGuard {
225    fn default() -> Self {
226        Self::new()
227    }
228}
229
230impl HotpathGuard {
231    pub(crate) fn new() -> Self {
232        Self {}
233    }
234}
235
236pub struct HotpathGuardBuilder {}
237
238impl HotpathGuardBuilder {
239    pub fn new(_caller_name: &'static str) -> Self {
240        Self {}
241    }
242
243    pub fn percentiles(self, _percentiles: &[u8]) -> Self {
244        self
245    }
246
247    pub fn format(self, _format: Format) -> Self {
248        self
249    }
250
251    pub fn with_functions_limit(self, _limit: usize) -> Self {
252        self
253    }
254
255    pub fn with_channels_limit(self, _limit: usize) -> Self {
256        self
257    }
258
259    pub fn with_streams_limit(self, _limit: usize) -> Self {
260        self
261    }
262
263    pub fn with_futures_limit(self, _limit: usize) -> Self {
264        self
265    }
266
267    pub fn with_threads_limit(self, _limit: usize) -> Self {
268        self
269    }
270
271    pub fn output_path(self, _path: impl AsRef<std::path::Path>) -> Self {
272        self
273    }
274
275    pub fn with_sections(self, _sections: Vec<Section>) -> Self {
276        self
277    }
278
279    pub fn before_shutdown(self, _f: impl FnOnce() + Send + 'static) -> Self {
280        self
281    }
282
283    pub fn build(self) -> HotpathGuard {
284        HotpathGuard
285    }
286
287    pub fn build_with_shutdown(self, _duration: std::time::Duration) {}
288}
289
290pub mod channels {
291    #[derive(Debug, Clone, Copy, PartialEq, Eq)]
292    pub enum ChannelType {
293        Bounded(usize),
294        Unbounded,
295        Oneshot,
296    }
297}
298
299pub mod streams {}
300
301pub mod threads {}
302
303pub mod futures {}