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