#![allow(dead_code)]
use std::collections::HashMap;
use metrics::Counter;
use reth_metrics::Metrics;
use tracing::trace;
use self::types::DynamicContractMetricEvent;
pub mod types;
#[derive(Debug, Default, Clone)]
pub struct DynamicContractMetrics {
contracts: ContractMetrics,
functions: HashMap<String, ContractFunctionMetrics>,
}
impl DynamicContractMetrics {
pub(crate) fn get_contract_metrics(&mut self, _address: String) -> &mut ContractMetrics {
&mut self.contracts
}
pub(crate) fn get_function_metrics(
&mut self,
function_name: String,
) -> &mut ContractFunctionMetrics {
self.functions
.entry(function_name.clone())
.or_insert_with(|| {
ContractFunctionMetrics::new_with_labels(&[("functions", function_name)])
})
}
pub(crate) fn handle_event(&mut self, event: DynamicContractMetricEvent) {
trace!(target: "tracing::metrics", ?event, "Metric event received");
match event {
DynamicContractMetricEvent::ContractMetricRecieved(_) => panic!("NOT IMPLEMENTED YET"),
}
}
}
#[derive(Metrics, Clone)]
#[metrics(scope = "contracts")]
pub(crate) struct ContractMetrics {
pub(crate) times_called: Counter,
}
#[derive(Metrics, Clone)]
#[metrics(scope = "contract_functions")]
pub(crate) struct ContractFunctionMetrics {
pub(crate) times_called: Counter,
}