Skip to main content

main

Attribute Macro main 

Source
#[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.

For programmatic control over the same options, see HotpathGuardBuilder.

§Parameters

  • percentiles - Array of percentile values (0-100) to compute. Default: [95]
  • format - Output format: "table" (default), "json", "json-pretty", or "none"
  • limit - Maximum number of functions in the report (0 = unlimited). Default: 15
  • output_path - File path for the report. Defaults to stdout. Overridden by HOTPATH_META_OUTPUT_PATH env var.
  • report - Comma-separated sections to include: "functions-timing", "functions-alloc", "channels", "streams", "futures", "threads", or "all". Overridden by HOTPATH_META_REPORT env var.

§Examples

Basic usage with default settings (P95 percentile, table format):

#[hotpath_meta::main]
fn main() {
    // Your code here
}

Custom percentiles:

#[tokio::main]
#[hotpath_meta::main(percentiles = [50, 90, 95, 99])]
async fn main() {
    // Your code here
}

JSON output to file:

#[hotpath_meta::main(format = "json-pretty", output_path = "report.json")]
fn main() {
    // Your code here
}

Select report sections:

#[hotpath_meta::main(report = "functions-timing,channels")]
fn main() {
    // Your code here
}

§Usage with Tokio

When using with tokio, place #[tokio::main] before #[hotpath_meta::main]:

#[tokio::main]
#[hotpath_meta::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 HotpathGuardBuilder) will cause a panic.

§See Also