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(any(feature = "hotpath-meta", feature = "tui"))]
39pub(crate) mod output;
40#[cfg(feature = "hotpath-meta")]
41pub use output::format_debug_truncated;
42#[cfg(any(feature = "hotpath-meta", feature = "tui"))]
43pub use output::{
44    ceil_char_boundary, floor_char_boundary, format_bytes, format_count, format_duration,
45    format_percentile_header, format_percentile_key, format_rate, parse_bytes, parse_count,
46    parse_duration, shorten_function_name, ProfilingMode, MAX_LOG_LEN,
47};
48
49#[cfg(feature = "hotpath-meta")]
50pub(crate) mod output_on;
51
52#[cfg(feature = "hotpath-meta")]
53pub(crate) mod auth;
54
55#[cfg(feature = "hotpath-meta")]
56pub(crate) mod metrics_server;
57
58#[cfg(feature = "hotpath-prometheus-meta")]
59pub(crate) mod prometheus_server;
60
61#[cfg(feature = "hotpath-mcp-meta")]
62pub(crate) mod mcp_server;
63
64#[allow(dead_code)]
65#[cfg(any(feature = "hotpath-meta", feature = "tui"))]
66pub mod json;
67#[cfg(any(feature = "hotpath-meta", feature = "tui"))]
68pub use json::Route;
69
70#[cfg(feature = "hotpath-meta")]
71#[doc(hidden)]
72pub mod instant;
73#[cfg(feature = "hotpath-meta")]
74pub(crate) mod tid;
75
76#[cfg(not(feature = "hotpath-meta"))]
77#[doc(inline)]
78pub use lib_off::*;
79#[cfg(not(feature = "hotpath-meta"))]
80mod lib_off;
81
82/// Mirror of `std` paths so instrumented types can be used as drop-in
83/// replacements by prefixing imports with `hotpath_meta::wrap::` (e.g.
84/// `hotpath_meta::wrap::std::sync::RwLock`).
85pub mod wrap {
86    pub mod std {
87        pub mod sync {
88            #[cfg(feature = "hotpath-meta")]
89            pub use crate::lib_on::{
90                mutexes::wrapper::std::{Mutex, MutexGuard},
91                rw_locks::wrapper::std::{RwLock, RwLockReadGuard, RwLockWriteGuard},
92            };
93            #[cfg(not(feature = "hotpath-meta"))]
94            pub use std::sync::{Mutex, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard};
95
96            /// Instrumented `std::sync::mpsc` channel endpoints for
97            /// `channel!(..., wrap = true)`. With `hotpath-meta` enabled these are the
98            /// instrumented wrappers; otherwise `channel!` is a no-op and the endpoints
99            /// are the raw std types, so the alias resolves the same way regardless of
100            /// feature configuration.
101            pub mod mpsc {
102                #[cfg(feature = "hotpath-meta")]
103                pub use crate::lib_on::channels::wrapper::std_wrap::{
104                    Receiver, Sender, SyncSender,
105                };
106                #[cfg(not(feature = "hotpath-meta"))]
107                pub use std::sync::mpsc::{Receiver, Sender, SyncSender};
108            }
109        }
110    }
111
112    /// Instrumented `tokio::sync::mpsc` channel endpoints for
113    /// `channel!(..., wrap = true)`. With `hotpath-meta` enabled these are the
114    /// instrumented wrappers; otherwise `channel!` is a no-op and the endpoints
115    /// are the raw tokio types, so the alias resolves the same way regardless of
116    /// feature configuration.
117    #[cfg(feature = "tokio")]
118    pub mod tokio {
119        pub mod sync {
120            pub mod mpsc {
121                #[cfg(feature = "hotpath-meta")]
122                pub use crate::lib_on::channels::wrapper::tokio_wrap::{
123                    Receiver, Sender, UnboundedReceiver, UnboundedSender, WeakSender,
124                    WeakUnboundedSender,
125                };
126                #[cfg(not(feature = "hotpath-meta"))]
127                pub use tokio::sync::mpsc::{
128                    Receiver, Sender, UnboundedReceiver, UnboundedSender, WeakSender,
129                    WeakUnboundedSender,
130                };
131            }
132        }
133    }
134
135    /// Instrumented crossbeam channel endpoints for `channel!(..., wrap = true)`.
136    /// With `hotpath-meta` enabled these are the instrumented wrappers; otherwise
137    /// `channel!` is a no-op and the endpoints are the raw crossbeam types, so the
138    /// alias resolves the same way regardless of feature configuration.
139    #[cfg(feature = "crossbeam")]
140    pub mod crossbeam {
141        #[cfg(feature = "hotpath-meta")]
142        pub use crate::lib_on::channels::wrapper::crossbeam_wrap::{Receiver, Sender};
143        #[cfg(not(feature = "hotpath-meta"))]
144        pub use crossbeam_channel::{Receiver, Sender};
145    }
146
147    /// Instrumented flume channel endpoints for `channel!(..., wrap = true)`.
148    /// With `hotpath-meta` enabled these are the instrumented wrappers; otherwise
149    /// `channel!` is a no-op and the endpoints are the raw flume types, so the
150    /// alias resolves the same way regardless of feature configuration.
151    #[cfg(feature = "flume")]
152    pub mod flume {
153        #[cfg(feature = "hotpath-meta")]
154        pub use crate::lib_on::channels::wrapper::flume_wrap::{Receiver, Sender};
155        #[cfg(not(feature = "hotpath-meta"))]
156        pub use flume::{Receiver, Sender};
157    }
158
159    /// Instrumented async-channel endpoints for `channel!(..., wrap = true)`.
160    /// With `hotpath-meta` enabled these are the instrumented wrappers; otherwise
161    /// `channel!` is a no-op and the endpoints are the raw async-channel types, so the
162    /// alias resolves the same way regardless of feature configuration.
163    #[cfg(feature = "async-channel")]
164    pub mod async_channel {
165        #[cfg(feature = "hotpath-meta")]
166        pub use crate::lib_on::channels::wrapper::asc_wrap::{Receiver, Sender};
167        #[cfg(not(feature = "hotpath-meta"))]
168        pub use async_channel::{Receiver, Sender};
169    }
170}
171
172mod shared;
173pub use shared::{env_flag, Format, IntoF64, Section};
174
175#[doc(hidden)]
176pub mod dev_logging;