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
Reporter- Trait for implementing custom reportersMetricType- Metric value types
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,
) -> Selfwhere
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
Trait Implementations§
Source§impl From<&dyn MetricsProvider<'_>> for FunctionsJson
impl From<&dyn MetricsProvider<'_>> for FunctionsJson
Source§fn from(metrics: &dyn MetricsProvider<'_>) -> Self
fn from(metrics: &dyn MetricsProvider<'_>) -> Self
Converts to this type from the input type.