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    // Profiling disabled: every form (`wrap`, `label`, `log`, `capacity`, any order)
67    // returns the original channel unchanged.
68    ($expr:expr $(, $($rest:tt)*)?) => {
69        $expr
70    };
71}
72
73#[macro_export]
74macro_rules! stream {
75    ($expr:expr) => {
76        $expr
77    };
78    ($expr: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}
91
92#[macro_export]
93macro_rules! tokio_runtime {
94    ($($handle:expr)?) => {};
95}
96
97#[macro_export]
98macro_rules! future {
99    ($fut:expr) => {
100        $fut
101    };
102    ($fut:expr, label = $label:expr) => {
103        $fut
104    };
105    ($fut:expr, log = true) => {
106        $fut
107    };
108    ($fut:expr, label = $label:expr, log = true) => {
109        $fut
110    };
111    ($fut:expr, log = true, label = $label:expr) => {
112        $fut
113    };
114}
115
116pub use crate::Format;
117pub use crate::Section;
118
119pub struct MeasurementGuard {}
120
121impl MeasurementGuard {
122    pub fn new(_name: &'static str, _wrapper: bool) -> Self {
123        Self {}
124    }
125
126    pub fn build(_name: &'static str, _wrapper: bool) -> Self {
127        Self {}
128    }
129}
130
131#[inline]
132pub fn measure_sync<T, F: FnOnce() -> T>(_measurement_loc: &'static str, f: F) -> T {
133    f()
134}
135
136#[inline]
137pub fn measure_sync_log<T: std::fmt::Debug, F: FnOnce() -> T>(
138    _measurement_loc: &'static str,
139    f: F,
140) -> T {
141    f()
142}
143
144pub async fn measure_async<T, Fut>(_measurement_loc: &'static str, fut: Fut) -> T
145where
146    Fut: std::future::Future<Output = T>,
147{
148    fut.await
149}
150
151pub async fn measure_async_log<T: std::fmt::Debug, Fut>(
152    _measurement_loc: &'static str,
153    fut: Fut,
154) -> T
155where
156    Fut: std::future::Future<Output = T>,
157{
158    fut.await
159}
160
161pub async fn measure_async_future<T, Fut>(_measurement_loc: &'static str, fut: Fut) -> T
162where
163    Fut: std::future::Future<Output = T>,
164{
165    fut.await
166}
167
168pub async fn measure_async_future_log<T: std::fmt::Debug, Fut>(
169    _measurement_loc: &'static str,
170    fut: Fut,
171) -> T
172where
173    Fut: std::future::Future<Output = T>,
174{
175    fut.await
176}
177
178pub struct HotpathGuard;
179
180impl Default for HotpathGuard {
181    fn default() -> Self {
182        Self::new()
183    }
184}
185
186impl HotpathGuard {
187    pub(crate) fn new() -> Self {
188        Self {}
189    }
190}
191
192pub struct HotpathGuardBuilder {}
193
194impl HotpathGuardBuilder {
195    pub fn new(_caller_name: &'static str) -> Self {
196        Self {}
197    }
198
199    pub fn percentiles(self, _percentiles: &[f64]) -> Self {
200        self
201    }
202
203    pub fn format(self, _format: Format) -> Self {
204        self
205    }
206
207    pub fn functions_limit(self, _limit: usize) -> Self {
208        self
209    }
210
211    pub fn channels_limit(self, _limit: usize) -> Self {
212        self
213    }
214
215    pub fn streams_limit(self, _limit: usize) -> Self {
216        self
217    }
218
219    pub fn futures_limit(self, _limit: usize) -> Self {
220        self
221    }
222
223    pub fn threads_limit(self, _limit: usize) -> Self {
224        self
225    }
226
227    pub fn rw_locks_limit(self, _limit: usize) -> Self {
228        self
229    }
230
231    pub fn mutexes_limit(self, _limit: usize) -> Self {
232        self
233    }
234
235    pub fn sql_limit(self, _limit: usize) -> Self {
236        self
237    }
238
239    pub fn limit(self, _limit: usize) -> Self {
240        self
241    }
242
243    pub fn output_path(self, _path: impl AsRef<std::path::Path>) -> Self {
244        self
245    }
246
247    pub fn sections(self, _sections: Vec<Section>) -> Self {
248        self
249    }
250
251    pub fn before_shutdown(self, _f: impl FnOnce() + Send + 'static) -> Self {
252        self
253    }
254
255    pub fn build(self) -> HotpathGuard {
256        HotpathGuard
257    }
258
259    pub fn build_with_shutdown(self, _duration: std::time::Duration) {}
260}
261
262pub mod channels {
263    #[derive(Debug, Clone, Copy, PartialEq, Eq)]
264    pub enum ChannelType {
265        Bounded(usize),
266        Unbounded,
267        Oneshot,
268    }
269}
270
271pub mod streams {}
272
273pub mod threads {}
274
275pub mod futures {}
276
277pub mod rw_locks {
278    pub use std::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard};
279}
280
281pub mod mutexes {
282    pub use std::sync::{Mutex, MutexGuard};
283}
284
285#[macro_export]
286macro_rules! rw_lock {
287    ($expr:expr) => {
288        $expr
289    };
290    ($expr:expr, label = $label:expr) => {
291        $expr
292    };
293}
294
295#[macro_export]
296macro_rules! mutex {
297    ($expr:expr) => {
298        $expr
299    };
300    ($expr:expr, label = $label:expr) => {
301        $expr
302    };
303}