hotpath 0.1.0

Minmal performance profiler for Rust applications
Documentation

HotPath

A lightweight Rust performance measurement library with async background processing.

Features

  • Zero-overhead function measurement with #[measure] attribute
  • Async background processing via MPSC channels
  • Full module path tracking (e.g., my_app::services::db::connect)
  • High-performance with RwLock for concurrent access
  • Graceful shutdown with proper resource cleanup

Quick Start

Add to your Cargo.toml:

[dependencies]
hotpath = "0.1"
tokio = { version = "1.0", features = ["full"] }

Usage

use hotpath::{measure, HotPath};
use std::time::Duration;

#[measure]
fn sync_function() {
    std::thread::sleep(Duration::from_millis(100));
}

#[measure]
async fn async_function() {
    tokio::time::sleep(Duration::from_millis(150)).await;
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize the background measurement processor
    HotPath::init().await?;

    // Your measured functions will automatically send metrics
    sync_function();
    async_function().await;

    // Graceful shutdown - processes remaining measurements
    HotPath::finalize().await?;

    Ok(())
}

Output:

[HotPath] my_app::sync_function took 105.0ms
[HotPath] my_app::async_function took 152.1ms
[HotPath] Background task shutting down

How It Works

  1. #[measure] - Proc-macro that wraps functions with timing code
  2. Background MPSC - Measurements are sent to a background task via unbounded channel
  3. Non-blocking - Function execution continues immediately after sending measurement
  4. Async processing - Background task prints measurements without blocking your code

API

HotPath::init()

Starts the background measurement processing task. Call once at application startup.

HotPath::finalize()

Gracefully shuts down the background task, processing any remaining measurements. Call before application exit.

#[measure]

Attribute macro that instruments functions to send timing measurements to the background processor.