receiving-code-review
OBobra/superpowers298k近 7 天新增 2,631 个 star
Configure hotpath profiling in a Rust project. Adds the hotpath dependency with feature-gated setup, instruments main with hotpath::main, functions with measure/measure_all, and wraps channels, mutexes, rw_locks, streams, futures, reqwest clients, axum routers and byte-level I/O with hotpath macros. Use when the user wants to add or set up hotpath profiling in a crate.
Set up hotpath profiling in the current Rust project. The setup is fully feature-gated: zero compile-time and runtime overhead unless the hotpath feature is explicitly enabled. All macros are noops when the feature is off, so no cfg_attr wrapping is needed.
The hotpath docs are the reference for every macro, cargo feature, parameter and caveat; this skill only holds the procedure. Every page of https://hotpath.rs is served as markdown when requested with an Accept: text/markdown header:
curl -sL -H 'Accept: text/markdown' https://hotpath.rs/functions
Before each step, fetch the pages it names and follow them instead of relying on memory. Keep -L (some pages redirect) and the header (there are no .md URLs). A #fragment is not sent to the server: fetch the whole page and find the heading. Fetch a page only when the project uses what it covers.
The site documents the latest hotpath release, which can be newer than the version the project uses. Never change the project's hotpath version because the docs show a newer one. If the docs describe something that version does not have, tell the user it needs a newer hotpath instead of working around it.
| Page | Covers |
|---|---|
| https://hotpath.rs/ | basic setup, example report |
| https://hotpath.rs/profiling_modes | #[hotpath::main] vs HotpathGuardBuilder, report options, TUI, optional vs non-optional dependency |
| https://hotpath.rs/functions | main, measure, measure_all, skip, measure_block!, allocation profiling, custom allocators |
| https://hotpath.rs/data_flow | channel!, stream!, future!: supported libraries and their cargo features, hotpath::wrap:: types, call-site aggregation, capacity |
| https://hotpath.rs/locks | mutex!, rw_lock!: supported libraries and their cargo features, wrapped types |
| https://hotpath.rs/io_tracing | io!, io_unwrap, measured layers, compression encoders |
| https://hotpath.rs/sql_tracing | sqlx, Diesel and Toasty query profiling |
| https://hotpath.rs/http_tracing | reqwest and ureq client profiling |
| https://hotpath.rs/axum_tracing | axum router profiling, route scoping of SQL and HTTP |
| https://hotpath.rs/tokio_runtime | tokio_runtime!() metrics |
| https://hotpath.rs/configuration | every environment variable |
| https://hotpath.rs/regression_policy | the policy file of step 7 |
main function. If there is no main you control (e.g. a library or a test harness), use the HotpathGuardBuilder API instead of #[hotpath::main] (see step 3).tokio, smol, none) and which instrumentable primitives the code uses: channels, Mutex and RwLock, futures streams, SQL (sqlx, diesel, toasty), HTTP clients (reqwest, ureq; note the major version), axum routers (find where the Router is finished and passed to axum::serve), byte-level I/O values implementing std::io::Read/Write or tokio::io::AsyncRead/AsyncWrite (files, sockets, compression codecs).In the target crate's Cargo.toml:
[dependencies]
hotpath = "0.28"
[features]
hotpath = ["hotpath/hotpath"]
hotpath-alloc = ["hotpath/hotpath-alloc"]
hotpath-prometheus = ["hotpath/hotpath-prometheus"]
hotpath-cloud = ["hotpath/hotpath-cloud"]
Enable the extra hotpath cargo features on the dependency (tokio, a channel or lock library, an SQL or HTTP integration, ...) that the pages fetched in step 1 name for the primitives the project uses. Pick the HTTP and axum features matching the project's major versions. For example: hotpath = { version = "0.28", features = ["tokio"] }.
Use this version, not the one the docs snippets show. If the project already depends on hotpath, keep its version.
If the crate already has a [features] section, merge the entries.
Docs: https://hotpath.rs/functions, https://hotpath.rs/profiling_modes.
#[hotpath::main] on main. With tokio, #[tokio::main] must come FIRST (above it). Defaults are fine for a first setup; don't add parameters unless asked.HotpathGuardBuilder. The builder does not install the allocation-tracking allocator, so also declare hotpath::CountingAllocator as the #[global_allocator] ("Allocation tracking with HotpathGuardBuilder").allocator = ... parameter with the macro, CountingAllocator::with(...) with the builder. Never leave two #[global_allocator] statics active under hotpath-alloc.Docs: https://hotpath.rs/functions.
#[hotpath::measure_all] on inline modules and impl blocks. Exclude noisy or trivial functions with #[hotpath::skip].#[hotpath::measure] on individual functions, both sync and async, and hotpath::measure_block! for ad-hoc code blocks.hotpath::measure_all annotations and up to 30 hotpath::measure. Goal of the initial setup is not to measure all functions, but to get the initial working instrumentation in place.Docs: https://hotpath.rs/data_flow, https://hotpath.rs/locks, https://hotpath.rs/io_tracing.
Wrap channels, streams, futures, locks and I/O values at their creation site with the macro the docs give, with a label.
channel!, stream! and io!, and it is safe for unbounded instance churn. Use iter = true only where one row per instance is wanted and the number of instances is bounded.io!, wrap the side where the work happens ("Measured layers", "Compression encoders"), or the reported rate is meaningless.hotpath::wrap; update type signatures where needed. Explain to the user that these types are no-op unless the hotpath feature is enabled. If that requires changes across many function boundaries, note it to the user rather than rewriting half the codebase silently.log = true only if Debug is already implemented.Fetch the page before adding one of these:
hotpath::wrap:: types. When both reqwest majors are enabled, 0.12 clients and errors use the versioned hotpath::wrap::reqwest_012 path. If the app already uses reqwest-middleware, attach the hotpath middleware to its stack instead of the macro.mkdir -p hotpath
curl -fsSL https://hotpath.rs/api/v1/policy/default | jq -j .source > hotpath/policy.toml
Run it from the repository root. It writes the default regression policy, with comments, to hotpath/policy.toml (no token needed; with wget, use wget -qO- https://hotpath.rs/api/v1/policy/default). Never overwrite an existing policy file. Do not change the defaults unless the user asks; https://hotpath.rs/regression_policy documents every key.
cargo check # feature off: must still compile, zero overhead
cargo check --features hotpath # feature on
cargo run --features hotpath # prints report on exit
Optionally verify alloc mode: cargo run --features 'hotpath,hotpath-alloc'.
Report what was instrumented and mention next steps, with their docs links: the live TUI and report options (https://hotpath.rs/profiling_modes) and the environment variables (https://hotpath.rs/configuration). Report sections need no configuration, so mention HOTPATH_REPORT only if the user wants to restrict output.
Also explain to the user that hotpath is safe to keep as a regular (non-optional) dependency ("Optional vs non-optional" in https://hotpath.rs/profiling_modes).
hotpath feature by default (default = []); profiling must stay opt-in.OBobra/superpowers298k近 7 天新增 2,631 个 star
OBobra/superpowers298k近 7 天新增 2,631 个 star
OBobra/superpowers298k近 7 天新增 2,631 个 star
MAmattpocock/skills288k近 7 天新增 10,178 个 star
MAmattpocock/skills288k近 7 天新增 10,178 个 star
MAmattpocock/skills288k近 7 天新增 10,178 个 star