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