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