use std::sync::Arc;
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum KevyMetric {
Replay {
commands: u64,
bytes: u64,
elapsed_ms: u64,
},
Rewrite {
keys: u64,
before_bytes: u64,
after_bytes: u64,
elapsed_ms: u64,
},
}
#[derive(Clone)]
pub(crate) struct MetricSink(Arc<dyn Fn(KevyMetric) + Send + Sync>);
impl MetricSink {
pub(crate) fn new(f: impl Fn(KevyMetric) + Send + Sync + 'static) -> Self {
MetricSink(Arc::new(f))
}
pub(crate) fn emit(&self, m: KevyMetric) {
(self.0)(m);
}
}
impl std::fmt::Debug for MetricSink {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("MetricSink(<fn>)")
}
}