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