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