Skip to main content

hotpath_meta/
lib.rs

1//! hotpath-rs is a simple async Rust profiler. It instruments functions, channels, futures, and streams to quickly find bottlenecks and focus optimizations where they matter most.
2//! It can provide actionable insights into time, memory, and data flow with minimal setup.
3//! ## Setup & Usage
4//! For a complete setup guide, examples, and advanced configuration, visit
5//! [hotpath.rs](https://hotpath.rs).
6
7// Meta crate mirrors the main crate; some code is conditionally dead
8// depending on feature combinations (e.g. alloc code without global_allocator).
9#![allow(dead_code)]
10
11#[cfg(all(
12    feature = "hotpath-cpu-meta",
13    not(any(target_os = "macos", target_os = "linux"))
14))]
15compile_error!("the `hotpath-cpu-meta` feature is only supported on macOS and Linux");
16
17#[cfg(all(feature = "hotpath-alloc-meta", not(feature = "hotpath-meta")))]
18compile_error!("the `hotpath-alloc-meta` feature requires the `hotpath-meta` feature");
19
20#[cfg(all(feature = "hotpath-cpu-meta", not(feature = "hotpath-meta")))]
21compile_error!("the `hotpath-cpu-meta` feature requires the `hotpath-meta` feature");
22
23#[cfg(all(feature = "hotpath-prometheus-meta", not(feature = "hotpath-meta")))]
24compile_error!("the `hotpath-prometheus-meta` feature requires the `hotpath-meta` feature");
25
26#[cfg(all(feature = "hotpath-cloud-meta", not(feature = "hotpath-meta")))]
27compile_error!("the `hotpath-cloud-meta` feature requires the `hotpath-meta` feature");
28
29#[cfg(feature = "hotpath-meta")]
30#[doc(inline)]
31pub use lib_on::*;
32#[cfg(feature = "hotpath-meta")]
33mod lib_on;
34
35#[cfg(all(feature = "hotpath-meta", feature = "tokio"))]
36pub use lib_on::tokio_runtime;
37
38#[cfg(feature = "json")]
39pub(crate) mod output;
40#[cfg(feature = "json")]
41pub use output::{
42    ceil_char_boundary, floor_char_boundary, format_bytes, format_count, format_duration,
43    format_percentile_header, format_percentile_key, format_rate, parse_bytes, parse_count,
44    parse_duration, shorten_function_name, ProfilingMode, MAX_LOG_LEN,
45};
46#[cfg(feature = "hotpath-meta")]
47pub use output_on::format_debug_truncated;
48
49#[cfg(feature = "hotpath-meta")]
50pub(crate) mod output_on;
51
52#[cfg(feature = "hotpath-meta")]
53#[doc(hidden)]
54pub mod table;
55
56#[cfg(feature = "hotpath-meta")]
57pub(crate) mod auth;
58
59#[cfg(feature = "hotpath-meta")]
60pub(crate) mod metrics_server;
61
62#[cfg(feature = "hotpath-prometheus-meta")]
63pub(crate) mod prometheus_server;
64
65#[cfg(feature = "hotpath-mcp-meta")]
66pub(crate) mod mcp_server;
67
68#[allow(dead_code)]
69#[cfg(feature = "json")]
70pub mod json;
71#[cfg(feature = "json")]
72pub use json::Route;
73
74#[cfg(feature = "hotpath-meta")]
75#[doc(hidden)]
76pub mod instant;
77#[cfg(feature = "hotpath-meta")]
78pub(crate) mod tid;
79
80#[cfg(not(feature = "hotpath-meta"))]
81#[doc(inline)]
82pub use lib_off::*;
83#[cfg(not(feature = "hotpath-meta"))]
84mod lib_off;
85
86/// Mirror of `std` paths so instrumented types can be used as drop-in
87/// replacements by prefixing imports with `hotpath_meta::wrap::` (e.g.
88/// `hotpath_meta::wrap::std::sync::RwLock`).
89pub mod wrap {
90    pub mod std {
91        pub mod sync {
92            #[cfg(feature = "hotpath-meta")]
93            pub use crate::lib_on::{
94                mutexes::wrapper::std::{Mutex, MutexGuard},
95                rw_locks::wrapper::std::{RwLock, RwLockReadGuard, RwLockWriteGuard},
96            };
97            #[cfg(not(feature = "hotpath-meta"))]
98            pub use std::sync::{Mutex, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard};
99
100            /// Instrumented `std::sync::mpsc` channel endpoints for
101            /// `channel!`. With `hotpath-meta` enabled these are the
102            /// instrumented wrappers; otherwise `channel!` is a no-op and the endpoints
103            /// are the raw std types, so the alias resolves the same way regardless of
104            /// feature configuration.
105            pub mod mpsc {
106                #[cfg(feature = "hotpath-meta")]
107                pub use crate::lib_on::channels::wrapper::std_wrap::{
108                    Receiver, Sender, SyncSender,
109                };
110                #[cfg(not(feature = "hotpath-meta"))]
111                pub use std::sync::mpsc::{Receiver, Sender, SyncSender};
112            }
113        }
114    }
115
116    /// Instrumented `tokio::sync::mpsc` channel endpoints for
117    /// `channel!`. With `hotpath-meta` enabled these are the
118    /// instrumented wrappers; otherwise `channel!` is a no-op and the endpoints
119    /// are the raw tokio types, so the alias resolves the same way regardless of
120    /// feature configuration.
121    #[cfg(feature = "tokio")]
122    pub mod tokio {
123        pub mod sync {
124            pub mod mpsc {
125                #[cfg(feature = "hotpath-meta")]
126                pub use crate::lib_on::channels::wrapper::tokio_wrap::{
127                    Receiver, Sender, UnboundedReceiver, UnboundedSender, WeakSender,
128                    WeakUnboundedSender,
129                };
130                #[cfg(not(feature = "hotpath-meta"))]
131                pub use tokio::sync::mpsc::{
132                    Receiver, Sender, UnboundedReceiver, UnboundedSender, WeakSender,
133                    WeakUnboundedSender,
134                };
135            }
136
137            /// Instrumented `tokio::sync::oneshot` channel endpoints for the default
138            /// `channel!` mode. With `hotpath-meta` enabled these are the instrumented
139            /// wrappers; otherwise `channel!` is a no-op and the endpoints are the raw
140            /// tokio types, so the alias resolves the same way regardless of feature
141            /// configuration.
142            pub mod oneshot {
143                #[cfg(feature = "hotpath-meta")]
144                pub use crate::lib_on::channels::wrapper::tokio_oneshot_wrap::{Receiver, Sender};
145                #[cfg(not(feature = "hotpath-meta"))]
146                pub use tokio::sync::oneshot::{Receiver, Sender};
147            }
148        }
149    }
150
151    /// Instrumented crossbeam channel endpoints for `channel!`.
152    /// With `hotpath-meta` enabled these are the instrumented wrappers; otherwise
153    /// `channel!` is a no-op and the endpoints are the raw crossbeam types, so the
154    /// alias resolves the same way regardless of feature configuration.
155    #[cfg(feature = "crossbeam")]
156    pub mod crossbeam {
157        #[cfg(feature = "hotpath-meta")]
158        pub use crate::lib_on::channels::wrapper::crossbeam_wrap::{Receiver, Sender};
159        #[cfg(not(feature = "hotpath-meta"))]
160        pub use crossbeam_channel::{Receiver, Sender};
161    }
162
163    /// Instrumented flume channel endpoints for `channel!`.
164    /// With `hotpath-meta` enabled these are the instrumented wrappers; otherwise
165    /// `channel!` is a no-op and the endpoints are the raw flume types, so the
166    /// alias resolves the same way regardless of feature configuration.
167    #[cfg(feature = "flume")]
168    pub mod flume {
169        #[cfg(feature = "hotpath-meta")]
170        pub use crate::lib_on::channels::wrapper::flume_wrap::{Receiver, Sender};
171        #[cfg(not(feature = "hotpath-meta"))]
172        pub use flume::{Receiver, Sender};
173    }
174
175    /// Instrumented async-channel endpoints for `channel!`.
176    /// With `hotpath-meta` enabled these are the instrumented wrappers; otherwise
177    /// `channel!` is a no-op and the endpoints are the raw async-channel types, so the
178    /// alias resolves the same way regardless of feature configuration.
179    #[cfg(feature = "async-channel")]
180    pub mod async_channel {
181        #[cfg(feature = "hotpath-meta")]
182        pub use crate::lib_on::channels::wrapper::asc_wrap::{Receiver, Sender};
183        #[cfg(not(feature = "hotpath-meta"))]
184        pub use async_channel::{Receiver, Sender};
185    }
186
187    /// Instrumented `futures_channel` endpoints for the default `channel!` mode.
188    /// With `hotpath-meta` enabled these are the instrumented wrappers; otherwise
189    /// `channel!` is a no-op and the endpoints are the raw futures types, so the
190    /// alias resolves the same way regardless of feature configuration.
191    #[cfg(feature = "futures")]
192    pub mod futures_channel {
193        pub mod mpsc {
194            #[cfg(feature = "hotpath-meta")]
195            pub use crate::lib_on::channels::wrapper::ftc_wrap::{
196                Receiver, Sender, TrySendError, UnboundedReceiver, UnboundedSender,
197            };
198            #[cfg(not(feature = "hotpath-meta"))]
199            pub use futures_channel::mpsc::{
200                Receiver, Sender, TrySendError, UnboundedReceiver, UnboundedSender,
201            };
202        }
203
204        pub mod oneshot {
205            #[cfg(feature = "hotpath-meta")]
206            pub use crate::lib_on::channels::wrapper::ftc_oneshot_wrap::{Receiver, Sender};
207            #[cfg(not(feature = "hotpath-meta"))]
208            pub use futures_channel::oneshot::{Receiver, Sender};
209        }
210    }
211}
212
213mod shared;
214pub use shared::{env_flag, Format, IntoF64, Section};
215
216#[doc(hidden)]
217pub mod dev_logging;