#[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:15timeout- Optional timeout in milliseconds. If specified, the program will print the report and exit after the timeout.
§Examples
Basic usage with default settings (P95 percentile, table format):
#[hotpath::main]
fn main() {
// Your code here
}Custom percentiles:
#[tokio::main]
#[hotpath::main(percentiles = [50, 90, 95, 99])]
async fn main() {
// Your code here
}JSON output format:
#[hotpath::main(format = "json-pretty")]
fn main() {
// Your code here
}Combined parameters:
#[hotpath::main(percentiles = [50, 99], format = "json")]
fn main() {
// Your code here
}Custom limit (show top 20 functions):
#[hotpath::main(limit = 20)]
fn main() {
// Your code here
}§Usage with Tokio
When using with tokio, place #[tokio::main] before #[hotpath::main]:
#[tokio::main]
#[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 FunctionsGuardBuilder) will cause a panic.
§See Also
measure- Attribute macro for instrumenting functionsmeasure_block!- Macro for measuring code blocksFunctionsGuardBuilder- Manual control over profiling lifecycle