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    // Profiling disabled: every form (`label`, `log`, `iter`, any order)
76    // returns the original stream unchanged.
77    ($expr:expr $(, $($rest:tt)*)?) => {
78        $expr
79    };
80}
81
82#[macro_export]
83macro_rules! tokio_runtime {
84    ($($handle:expr)?) => {};
85}
86
87#[macro_export]
88macro_rules! future {
89    ($fut:expr) => {
90        $fut
91    };
92    ($fut:expr, label = $label:expr) => {
93        $fut
94    };
95    ($fut:expr, log = true) => {
96        $fut
97    };
98    ($fut:expr, label = $label:expr, log = true) => {
99        $fut
100    };
101    ($fut:expr, log = true, label = $label:expr) => {
102        $fut
103    };
104}
105
106pub use crate::Format;
107pub use crate::Section;
108
109pub struct MeasurementGuard {}
110
111impl MeasurementGuard {
112    pub fn new(_name: &'static str, _wrapper: bool) -> Self {
113        Self {}
114    }
115
116    pub fn build(_name: &'static str, _wrapper: bool) -> Self {
117        Self {}
118    }
119}
120
121#[inline]
122pub fn measure_sync<T, F: FnOnce() -> T>(_measurement_loc: &'static str, f: F) -> T {
123    f()
124}
125
126#[inline]
127pub fn measure_sync_log<T: std::fmt::Debug, F: FnOnce() -> T>(
128    _measurement_loc: &'static str,
129    f: F,
130) -> T {
131    f()
132}
133
134pub async fn measure_async<T, Fut>(_measurement_loc: &'static str, fut: Fut) -> T
135where
136    Fut: std::future::Future<Output = T>,
137{
138    fut.await
139}
140
141pub async fn measure_async_log<T: std::fmt::Debug, Fut>(
142    _measurement_loc: &'static str,
143    fut: Fut,
144) -> T
145where
146    Fut: std::future::Future<Output = T>,
147{
148    fut.await
149}
150
151pub async fn measure_async_future<T, Fut>(_measurement_loc: &'static str, fut: Fut) -> T
152where
153    Fut: std::future::Future<Output = T>,
154{
155    fut.await
156}
157
158pub async fn measure_async_future_log<T: std::fmt::Debug, Fut>(
159    _measurement_loc: &'static str,
160    fut: Fut,
161) -> T
162where
163    Fut: std::future::Future<Output = T>,
164{
165    fut.await
166}
167
168pub struct HotpathGuard;
169
170impl Default for HotpathGuard {
171    fn default() -> Self {
172        Self::new()
173    }
174}
175
176impl HotpathGuard {
177    pub(crate) fn new() -> Self {
178        Self {}
179    }
180}
181
182pub struct HotpathGuardBuilder {}
183
184impl HotpathGuardBuilder {
185    pub fn new(_caller_name: &'static str) -> Self {
186        Self {}
187    }
188
189    pub fn percentiles(self, _percentiles: &[f64]) -> Self {
190        self
191    }
192
193    pub fn format(self, _format: Format) -> Self {
194        self
195    }
196
197    pub fn functions_limit(self, _limit: usize) -> Self {
198        self
199    }
200
201    pub fn channels_limit(self, _limit: usize) -> Self {
202        self
203    }
204
205    pub fn streams_limit(self, _limit: usize) -> Self {
206        self
207    }
208
209    pub fn futures_limit(self, _limit: usize) -> Self {
210        self
211    }
212
213    pub fn threads_limit(self, _limit: usize) -> Self {
214        self
215    }
216
217    pub fn rw_locks_limit(self, _limit: usize) -> Self {
218        self
219    }
220
221    pub fn mutexes_limit(self, _limit: usize) -> Self {
222        self
223    }
224
225    pub fn sql_limit(self, _limit: usize) -> Self {
226        self
227    }
228
229    pub fn http_limit(self, _limit: usize) -> Self {
230        self
231    }
232
233    pub fn io_limit(self, _limit: usize) -> Self {
234        self
235    }
236
237    pub fn limit(self, _limit: usize) -> Self {
238        self
239    }
240
241    pub fn time_sampling_rate(self, _rate: f64) -> Self {
242        self
243    }
244
245    pub fn functions_time_sampling_rate(self, _rate: f64) -> Self {
246        self
247    }
248
249    pub fn mutexes_time_sampling_rate(self, _rate: f64) -> Self {
250        self
251    }
252
253    pub fn rw_locks_time_sampling_rate(self, _rate: f64) -> Self {
254        self
255    }
256
257    pub fn futures_time_sampling_rate(self, _rate: f64) -> Self {
258        self
259    }
260
261    pub fn channels_time_sampling_rate(self, _rate: f64) -> Self {
262        self
263    }
264
265    pub fn io_time_sampling_rate(self, _rate: f64) -> Self {
266        self
267    }
268
269    pub fn output_path(self, _path: impl AsRef<std::path::Path>) -> Self {
270        self
271    }
272
273    pub fn sections(self, _sections: Vec<Section>) -> Self {
274        self
275    }
276
277    pub fn sections_exclude(self, _sections: Vec<Section>) -> Self {
278        self
279    }
280
281    pub fn report(self, _spec: &str) -> Self {
282        self
283    }
284
285    pub fn before_shutdown(self, _f: impl FnOnce() + Send + 'static) -> Self {
286        self
287    }
288
289    pub fn build(self) -> HotpathGuard {
290        HotpathGuard
291    }
292
293    pub fn build_with_shutdown(self, _duration: std::time::Duration) {}
294}
295
296pub mod channels {
297    #[derive(Debug, Clone, Copy, PartialEq, Eq)]
298    pub enum ChannelType {
299        Bounded(usize),
300        Unbounded,
301        Oneshot,
302        Pending,
303    }
304}
305
306pub mod streams {}
307
308pub mod threads {}
309
310pub mod futures {}
311
312pub mod rw_locks {
313    pub use std::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard};
314}
315
316pub mod mutexes {
317    pub use std::sync::{Mutex, MutexGuard};
318}
319
320#[macro_export]
321macro_rules! rw_lock {
322    ($expr:expr) => {
323        $expr
324    };
325    ($expr:expr, label = $label:expr) => {
326        $expr
327    };
328}
329
330#[macro_export]
331macro_rules! mutex {
332    ($expr:expr) => {
333        $expr
334    };
335    ($expr:expr, label = $label:expr) => {
336        $expr
337    };
338}
339
340/// No-op counterpart of the enabled-mode `io_unwrap`. `io!` returns its
341/// argument unchanged when profiling is disabled, so unwrapping is the
342/// identity and call sites compile identically in both modes.
343pub fn io_unwrap<T>(io: T) -> T {
344    io
345}
346
347#[macro_export]
348macro_rules! io {
349    ($expr:expr) => {
350        $expr
351    };
352    ($expr:expr, label = $label:expr) => {
353        $expr
354    };
355    ($expr:expr, iter = true) => {
356        $expr
357    };
358    ($expr:expr, label = $label:expr, iter = true) => {
359        $expr
360    };
361    ($expr:expr, iter = true, label = $label:expr) => {
362        $expr
363    };
364}