Expand description
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. It can provide actionable insights into time, memory, and data flow with minimal setup.
§Setup & Usage
For a complete setup guide, examples, and advanced configuration, visit hotpath.rs.
Re-exports§
pub use json::Route;
Modules§
- channels
- Channel instrumentation module - tracks message flow and channel state.
- cpu_
baseline - debug
- Debug subsystem - value logging, debug logging, and gauges.
- functions
- Function profiling module - measures execution time and memory allocations per function.
- futures
- Futures instrumentation module - tracks async Future lifecycle and poll statistics.
- hotpath_
guard - http
- HTTP request instrumentation module - tracks request durations per endpoint.
- io
- Byte-level I/O instrumentation - tracks read/write/flush/shutdown operations
performed through wrapped
Read/Write/AsyncRead/AsyncWritevalues. - json
- JSON serializable types for TUI and CLI consumers.
- mutexes
- Mutex instrumentation module - tracks lock acquisitions and hold durations.
- rw_
locks - RwLock instrumentation module - tracks read/write lock acquisitions and hold durations.
- sql
- SQL query instrumentation module - tracks query execution durations.
- streams
- Stream instrumentation module - tracks items yielded and stream lifecycle.
- threads
- This module provides real-time thread monitoring capabilities, collecting CPU usage statistics for all threads in the current process.
- wrap
- Mirror of
stdpaths so instrumented types can be used as drop-in replacements by prefixing imports withhotpath::wrap::(e.g.hotpath::wrap::std::sync::RwLock).
Macros§
- channel
- Instrument a channel creation for profiling.
- dbg
- Debug macro that tracks debug output in the profiler.
- future
- Instrument a future to inspect future’s lifecycle events.
- gauge
- Gauge macro for tracking numeric values with set/inc/dec operations.
- http
- Wrap a
reqwest::Clientso every request it sends is timed and reported in thehttpsection, keyed by normalized endpoint. - io
- Instrument a value implementing
std::io::Read,std::io::Write,tokio::io::AsyncRead, ortokio::io::AsyncWritefor byte-level I/O profiling (tokiotraits require thetokiofeature). - measure_
block - Measures the execution time or memory allocations of a code block.
- mutex
- Instrument an
std::sync::Mutex, [parking_lot::Mutex],tokio::sync::Mutex, orasync_lock::Mutexfor lock wait & acquire profiling. - rw_lock
- Instrument an
std::sync::RwLock, [parking_lot::RwLock],async_lock::RwLock, ortokio::sync::RwLockfor read/write profiling. - stream
- Instrument a stream to track its item yields.
- tokio_
runtime - Initialize Tokio runtime metrics monitoring.
- val
- Value tracking macro that logs key-value pairs to the profiler.
Structs§
- Counting
Allocator - Shared global allocator that dispatches to enabled allocation tracking features
- Hotpath
Guard - RAII guard that owns the profiler lifetime.
- Hotpath
Guard Builder - Builder for
HotpathGuard- a programmatic alternative to the#[hotpath::main]macro for configuring and initializing the profiler. - Measurement
Guard Async - Measurement
Guard Sync - Reqwest
Http Middleware - Middleware that reports per-request timing to the hotpath HTTP worker.
Enums§
- Format
- Output format for profiling reports.
- Output
Destination - Destination for profiling report output.
- Profiling
Mode - Profiling mode indicating what type of measurements were collected.
- Section
Statics§
Traits§
- Instrument
Http Client - Wraps an HTTP client so every request it sends is timed and reported.
Implemented for
reqwest::Client(per enabled reqwest generation); the concrete client type routes to the matchingreqwest-middlewarewrapper. - IntoF64
Functions§
- ceil_
char_ boundary - floor_
char_ boundary - format_
bytes - Formats a byte count into a human-readable string (e.g., “1.5 MB”).
- format_
count - Formats an allocation count as a string.
- format_
debug_ truncated - format_
duration - Formats a duration in nanoseconds into a human-readable string with appropriate units.
- format_
percentile_ header - Formats a percentile value for display as a column header (e.g.,
"P95","P99.9"). - format_
percentile_ key - Formats a percentile value for use as a map key (e.g.,
"p95","p99.9"). - format_
rate - Formats an optional per-second rate to one decimal place, or
-when absent. - format_
throughput - Formats an optional bytes-per-second rate (e.g.
12.4 MB/s), or-when absent. Sub-KB rates keep one decimal place so slow but nonzero traffic doesn’t round down to0 B/s. - io_
unwrap - Consumes an
io!wrapper, returning the wrapped value. The escape hatch for calling consuming methods of the wrapped type (e.g. a codec’sfinish(self)); borrowing methods are reachable directly throughDeref/DerefMutinstead. - parse_
bytes - Parses a human-readable byte string back to a byte count.
Inverse of
format_bytes. - parse_
count - Parses a count string back to a u64.
Inverse of
format_count. - parse_
duration - Parses a human-readable duration string back to nanoseconds.
Inverse of
format_duration. - shorten_
function_ name
Attribute Macros§
- future_
fn - Instruments an async function to track its lifecycle as a Future.
- main
- Initializes the hotpath profiling system and generates a performance report on program exit.
- measure
- Instruments a function to measure execution time or memory allocations.
- measure_
all - Instruments all functions in a module or impl block with the
measureprofiling macro. - skip
- Marks a function to be excluded from profiling when used with
measure_all.