hotpath README

项目的 README,来自 github.com/hotpath-rs/hotpath。合并为一个 markdown 文件:README.md。

hotpath-rs logo hotpath-rs - Rust Profiler for Easy Performance Debugging

Latest Version Downloads hotpath-cloud Sponsor

A simple Rust profiler that shows exactly why your code is slow.

Performance profiling for developers and coding agents. Profile CPU, memory allocations, async tasks, SQL queries, I/O, and lock contention in one place. Explore performance metrics in a live TUI, or export to Prometheus and Grafana when you need production monitoring.

Already using Criterion.rs? Criterion tells you how fast your code runs. hotpath-rs explains why. Add detailed CPU and memory profiling to your existing Criterion benchmarks with minimal changes. Explore Criterion integration →

Find bottlenecks locally, then use hotpath-cloud to track performance changes across pull requests.

Try the TUI demo via SSH - no installation required:

ssh demo.hotpath.rs

Or let your AI coding agent set up profiling, paste into Claude Code, Codex, OpenCode or Cursor:

Set up hotpath-rs profiling in this Rust project using the instructions at https://hotpath.rs/agent/setup

hotpath-rs is an easy-to-configure Rust performance profiling toolkit that shows exactly where your code spends time, burns CPU, and allocates memory.

It helps you distinguish between functions that are slow because they wait on I/O and those that are CPU-intensive. Instrument functions, channels, futures, streams, SQL queries, HTTP calls, and byte-level I/O to find bottlenecks and focus optimizations where they matter most.

Explore the full documentation at hotpath.rs. See CONTRIBUTING.md for development setup and guidelines.

You can use it to produce one-off performance (timing, memory or CPU) reports:

hotpath alloc report

correlate all performance signals in Grafana with minimal profiling overhead:

Grafana dashboard built on hotpath-rs Prometheus metrics showing slowest SQL queries, per-function allocations and requests by route

catch performance regressions on every pull request with a simple CI integration:

hotpath-cloud pull request comment showing wall time, allocation and RSS changes against the main branch

inspect throughput and latency of network, file or compression I/O streams:

hotpath-rs I/O profiling report showing per-stream read counts, bytes, transfer rate, average and P95 latency

analyze SQL/HTTP calls performance with automatic source function attribution:

hotpath-rs SQL query profiling report showing per-query call counts, source function attribution, average and P95 execution time

monitor throughput, performance and max queue depth of instrumented channels:

hotpath-rs channel profiling report showing throughput, send-to-receive latency and max queue depth per channel

or use the live TUI dashboard to monitor real-time performance and async data flow metrics with debug info:

https://github.com/user-attachments/assets/2e890417-2b43-4b1b-8657-a5ef3b458153

Features

Getting Started

The quickest way to set up hotpath is to let your own AI coding agent do it. Paste this prompt into Claude Code, Codex, OpenCode, Cursor or any other coding agent, inside your project repo:

Set up hotpath-rs profiling in this Rust project using the instructions at https://hotpath.rs/agent/setup

The agent inspects your project, including workspaces and any existing hotpath setup, adds the feature-gated dependency, instruments main and a small starting set of hot functions, channels and locks, and verifies that everything compiles with profiling enabled and disabled. When the project has a workload that exits, it runs it and shows you the first report; it does not start long-running servers just to get one. It then explains how to run profiling and the live TUI. It finally asks once whether to optionally set up hotpath-cloud to benchmark pull requests in CI.

The prompt is a one-time project setup. The hotpath-rs agent skill is what stays: reusable hotpath knowledge your agent loads in every later session. To install it, for example in a repo that already uses hotpath, run:

npx skills add hotpath-rs/hotpath --skill hotpath-rs

The skill maps every hotpath task, from instrumenting a crate to fixing a regression flagged in CI, to the documentation page that covers it, so your agent fetches the current docs instead of relying on its memory. Your agent remains in control: you review and approve edits through its regular permission prompts.

Manual installation

Add to your Cargo.toml:

[dependencies]
hotpath = "0.33"

[features]
hotpath = ["hotpath/hotpath"]
hotpath-cpu = ["hotpath", "hotpath/hotpath-cpu"]
hotpath-callgrind = ["hotpath", "hotpath/hotpath-callgrind"]
hotpath-alloc = ["hotpath", "hotpath/hotpath-alloc"]
hotpath-prometheus = ["hotpath", "hotpath/hotpath-prometheus"]

This config ensures that the lib has no compile time or runtime overhead unless explicitly enabled via one of the hotpath features. Every profiling feature also enables hotpath, so a single flag like --features=hotpath-alloc is enough. All the lib dependencies are optional (i.e. not compiled) and all macros are noop unless profiling is enabled.

Basic setup

You'll need only #[hotpath::main] and #[hotpath::measure] macros to get started:

#[hotpath::measure]
fn sync_function(sleep: u64) {
    std::thread::sleep(Duration::from_nanos(sleep));
    let vec1 = vec![1, 2, 3];
    std::hint::black_box(&vec1); // force mem allocation
}

#[hotpath::measure]
async fn async_function(sleep: u64) {
    tokio::time::sleep(Duration::from_nanos(sleep)).await;
}

// When using with tokio, place the #[tokio::main] first
#[tokio::main]
#[hotpath::main]
async fn main() {
    for i in 0..1000 {
        sync_function(i);
        async_function(i * 2).await;

        hotpath::measure_block!("custom_block", {
            std::thread::sleep(Duration::from_nanos(i * 3))
        });
    }
}

Now, run your program with hotpath (and optionally hotpath-alloc features):

cargo run --features='hotpath-alloc'

On exit it will print a report with timings, memory allocations and thread usage metrics:

[hotpath] 1.20s | timing, alloc, threads

timing - Function execution time metrics.
+------------------------------+-------+----------+----------+----------+---------+
| Function                     | Calls | Avg      | P95      | Total    | % Total |
+------------------------------+-------+----------+----------+----------+---------+
| docs_example::main           | 1     | 1.20 s   | 1.20 s   | 1.20 s   | 100.00% |
+------------------------------+-------+----------+----------+----------+---------+
| docs_example::async_function | 1,000 | 1.16 ms  | 1.24 ms  | 1.16 s   | 96.84%  |
+------------------------------+-------+----------+----------+----------+---------+
| custom_block                 | 1,000 | 16.86 µs | 29.50 µs | 16.86 ms | 1.41%   |
+------------------------------+-------+----------+----------+----------+---------+
| docs_example::sync_function  | 1,000 | 12.16 µs | 23.84 µs | 12.17 ms | 1.02%   |
+------------------------------+-------+----------+----------+----------+---------+

alloc-bytes - Exclusive allocation bytes by each function (excluding nested calls).
Total: 100.1 KB
+------------------------------+-------+---------+---------+---------+---------+
| Function                     | Calls | Avg     | P95     | Total   | % Total |
+------------------------------+-------+---------+---------+---------+---------+
| docs_example::main           | 1     | 88.4 KB | 88.4 KB | 88.4 KB | 88.29%  |
+------------------------------+-------+---------+---------+---------+---------+
| docs_example::sync_function  | 1,000 | 12 B    | 12 B    | 11.7 KB | 11.71%  |
+------------------------------+-------+---------+---------+---------+---------+
| custom_block                 | 1,000 | 0 B     | 0 B     | 0 B     | 0.00%   |
+------------------------------+-------+---------+---------+---------+---------+
| docs_example::async_function | 1,000 | 0 B     | 0 B     | 0 B     | 0.00%   |
+------------------------------+-------+---------+---------+---------+---------+

threads - Thread CPU and memory statistics. (Max RSS: 8.6 MB, Alloc: 108.5 KB, Dealloc: 123.8 KB, Diff: -15.3 KB)
+-----------------+------+------+----------+---------+----------+
| Thread          | Max% | Avg% | Alloc    | Dealloc | Diff     |
+-----------------+------+------+----------+---------+----------+
| main            | 4.5% | 3.8% | 100.1 KB | 46.0 KB | 54.0 KB  |
+-----------------+------+------+----------+---------+----------+
| tokio-rt-worker | 0.0% | 0.0% | 79 B     | 70.1 KB | -70.0 KB |
+-----------------+------+------+----------+---------+----------+
| tokio-rt-worker | 0.0% | 0.0% | 4.2 KB   | 471 B   | 3.8 KB   |
+-----------------+------+------+----------+---------+----------+
| tokio-rt-worker | 0.0% | 0.0% | 3.3 KB   | 407 B   | 2.9 KB   |
+-----------------+------+------+----------+---------+----------+

Full documentation

See the full docs and advanced config tutorials at hotpath.rs.

Read the complete guide to profiling Rust applications - a comprehensive overview of debugging performance issues in Rust.

hotpath-cloud

hotpath-cloud turns profiling data into automated performance reviews for Rust pull requests.

Detect performance regressions before they ship by comparing CPU instruction counts, memory allocations, execution times, and SQL queries across PRs. Define performance budgets, get actionable feedback directly in GitHub, and investigate regressions using AI coding agents.

hotpath (hotpath-rs/hotpath)

正在搜索数据库…

这是什么?hotpath-rs 是一个 Rust 性能分析器,精确显示你的代码在哪里耗时、消耗 CPU 和分配内存,涵盖异步执行、SQL/HTTP 调用、I/O 流和锁竞争。
这是我要添加到项目里的 Rust 库,还是一个独立工具?它主要是一个库:你将它作为受 feature 开关控制的 Cargo 依赖添加,并用 #[hotpath::main] 和 #[hotpath::measure] 宏标注函数。它还附带用于设置的配套 hotpath CLI 和实时 TUI 仪表盘,以及面向 AI 智能体的 MCP 服务器。
我怎么在我的项目里让它跑起来?推荐的方式是安装 hotpath CLI 并在你的仓库中运行“hotpath init”,它会启动你的 AI 编程智能体(Claude Code、Codex 或 OpenCode)来自动添加依赖并为代码插桩。另一种方式是手动把 hotpath crate 添加到 Cargo.toml,并自己应用 #[hotpath::main]/#[hotpath::measure] 宏。
使用自动化设置需要 AI 编程智能体吗?只有推荐的 AI 辅助设置才需要,该方式要求安装 curl,且 PATH 中有 claude、codex 或 opencode 之一的 CLI。手动安装只需要修改 Cargo.toml 并应用性能分析宏,无需任何智能体。
如果我把它编译进去,性能分析会增加开销吗?不会——所有依赖都是可选的,除非明确启用 hotpath 的 feature 开关,宏都会变成空操作,因此禁用时编译期和运行时开销为零。注意该项目仍在积极开发中,JSON 报告格式和 TUI/MCP 细节等内部实现可能在版本之间发生变化。
这是为谁打造的?它面向需要诊断慢函数、内存泄漏、异步瓶颈或缓慢 SQL/HTTP 调用的 Rust 开发者(以及他们的编程智能体),而非普通应用用户。
不安装任何东西也能试用 hotpath 吗?可以,README 提供了一个可通过 SSH 访问的 TUI 演示,无需安装。
内置的 MCP 服务器是做什么的?它提供一个 MCP(Model Context Protocol,模型上下文协议)服务器,让 AI 智能体可以直接查询实时分析数据,例如耗时、内存使用和异步指标。
它能分析哪些 SQL 和 HTTP 库?它可以分析 sqlx 和 Diesel 的 SQL 查询、reqwest 和 ureq 的 HTTP 客户端调用,以及 axum 的 HTTP 服务器路由,并提供每个端点的延迟和错误指标。
它能与我现有的监控体系集成吗?可以,hotpath 将性能分析指标导出到 Prometheus,并让你构建 Grafana 仪表盘,在同一个地方关联所有性能信号。
有哪些类似的项目?openobserve, siglake, pgbot, scalene, kividb, memray, grafana, claude-code
大小
50.4 MB
星标
1.9K
时长
1年
提交 · 90 天