#[main]Expand description
Initializes the hotpath profiling system and generates a performance report on program exit.
This attribute macro should be applied to your program’s main (or other entry point) function to enable profiling. It creates a guard that initializes the background measurement processing thread and automatically displays a performance summary when the program exits. Additionally it creates a measurement guard that will be used to measure the wrapper function itself.
§Parameters
percentiles- Array of percentile values (0-100) to display in the report. Default:[95]format- Output format as a string:"table"(default),"json", or"json-pretty"limit- Maximum number of functions to display in the report (0 = show all). Default:15
§Examples
Basic usage with default settings (P95 percentile, table format):
#[cfg_attr(feature = "hotpath", hotpath::main)]
fn main() {
// Your code here
}Custom percentiles:
#[tokio::main]
#[cfg_attr(feature = "hotpath", hotpath::main(percentiles = [50, 90, 95, 99]))]
async fn main() {
// Your code here
}JSON output format:
#[cfg_attr(feature = "hotpath", hotpath::main(format = "json-pretty"))]
fn main() {
// Your code here
}Combined parameters:
#[cfg_attr(feature = "hotpath", hotpath::main(percentiles = [50, 99], format = "json"))]
fn main() {
// Your code here
}Custom limit (show top 20 functions):
#[cfg_attr(feature = "hotpath", hotpath::main(limit = 20))]
fn main() {
// Your code here
}§Usage with Tokio
When using with tokio, place #[tokio::main] before #[hotpath::main]:
#[tokio::main]
#[cfg_attr(feature = "hotpath", hotpath::main)]
async fn main() {
// Your code here
}§Limitations
Only one hotpath guard can be active at a time. Creating a second guard (either via this
macro or via GuardBuilder) will cause a panic.
§See Also
measure- Attribute macro for instrumenting functionsmeasure_block!- Macro for measuring code blocksGuardBuilder- Manual control over profiling lifecycle