MetricsProvider

Trait MetricsProvider 

Source
pub trait MetricsProvider<'a> {
    // Required methods
    fn description(&self) -> String;
    fn profiling_mode(&self) -> ProfilingMode;
    fn percentiles(&self) -> Vec<u8> ;
    fn metric_data(&self) -> HashMap<String, Vec<MetricType>>;
    fn entry_counts(&self) -> (usize, usize);
    fn new(
        stats: &'a HashMap<&'static str, FunctionStats>,
        total_elapsed: Duration,
        percentiles: Vec<u8>,
        caller_name: &'static str,
        limit: usize,
    ) -> Self
       where Self: Sized;
    fn total_elapsed(&self) -> u64;
    fn caller_name(&self) -> &str;

    // Provided methods
    fn headers(&self) -> Vec<String> { ... }
    fn sort_key(&self, metrics: &[MetricType]) -> f64 { ... }
    fn has_unsupported_async(&self) -> bool { ... }
}
Expand description

Trait for accessing profiling metrics data from custom reporters.

This trait provides a standardized interface for reporters to access profiling metrics, regardless of the underlying profiling mode (time or allocation tracking). Implement Reporter to use this interface for custom output.

§Examples

use hotpath::{Reporter, MetricsProvider};
use std::error::Error;

struct CustomReporter;

impl Reporter for CustomReporter {
    fn report(&self, metrics: &dyn MetricsProvider<'_>) -> Result<(), Box<dyn Error>> {
        println!("=== {} ===", metrics.description());

        for (func_name, metric_values) in metrics.metric_data() {
            println!("{}: {} values", func_name, metric_values.len());
        }

        Ok(())
    }
}

§See Also

Required Methods§

Source

fn description(&self) -> String

Source

fn profiling_mode(&self) -> ProfilingMode

Source

fn percentiles(&self) -> Vec<u8>

Source

fn metric_data(&self) -> HashMap<String, Vec<MetricType>>

Source

fn entry_counts(&self) -> (usize, usize)

Source

fn new( stats: &'a HashMap<&'static str, FunctionStats>, total_elapsed: Duration, percentiles: Vec<u8>, caller_name: &'static str, limit: usize, ) -> Self
where Self: Sized,

Source

fn total_elapsed(&self) -> u64

Source

fn caller_name(&self) -> &str

Provided Methods§

Source

fn headers(&self) -> Vec<String>

Source

fn sort_key(&self, metrics: &[MetricType]) -> f64

Source

fn has_unsupported_async(&self) -> bool

Trait Implementations§

Source§

impl From<&dyn MetricsProvider<'_>> for FunctionsJson

Source§

fn from(metrics: &dyn MetricsProvider<'_>) -> Self

Converts to this type from the input type.

Implementors§