use super::{ExecutionPlanMetricsSet, MetricBuilder, MetricType, ScopedTimerGuard, Time};
#[derive(Debug, Clone)]
pub struct ExpressionEvaluatorMetrics {
expression_times: Vec<Time>,
}
impl ExpressionEvaluatorMetrics {
pub fn new<T>(
metrics: &ExecutionPlanMetricsSet,
partition: usize,
expression_labels: impl IntoIterator<Item = T>,
) -> Self
where
T: Into<String>,
{
let expression_times = expression_labels
.into_iter()
.enumerate()
.map(|(idx, label)| {
MetricBuilder::new(metrics)
.with_new_label("expr", label.into())
.with_type(MetricType::DEV)
.subset_time(format!("expr_{idx}_eval_time"), partition)
})
.collect();
Self { expression_times }
}
#[inline]
pub fn scoped_timer(&self, index: usize) -> Option<ScopedTimerGuard<'_>> {
self.expression_times.get(index).map(Time::timer)
}
pub fn len(&self) -> usize {
self.expression_times.len()
}
pub fn is_empty(&self) -> bool {
self.expression_times.is_empty()
}
}