#[cfg(feature = "perf_counters")]
use core::cell::Cell;
#[derive(Debug, Copy, Clone)]
pub struct PerfCounterFields {
pub variant_lookup_count : usize,
pub variant_load_count : usize,
pub key_group_ref_count : usize,
pub max_variant_entry_refs : usize,
pub key_group_load_count : usize,
pub keys_found_count : usize,
pub distance_function_invocation_count : usize,
pub records_found_count : usize,
}
impl PerfCounterFields {
pub fn new() -> Self {
Self {
variant_lookup_count : 0,
variant_load_count : 0,
key_group_ref_count : 0,
max_variant_entry_refs : 0,
key_group_load_count : 0,
keys_found_count : 0,
distance_function_invocation_count : 0,
records_found_count : 0,
}
}
}
#[cfg(feature = "perf_counters")]
pub struct PerfCounters(Cell<PerfCounterFields>);
#[cfg(feature = "perf_counters")]
impl PerfCounters {
pub fn new() -> Self {
Self(Cell::new(PerfCounterFields::new()))
}
pub fn reset(&self) {
self.set(PerfCounterFields::new())
}
pub fn update<F : Fn(&mut PerfCounterFields)>(&self, func : F) {
let mut fields = self.get();
func(&mut fields);
self.set(fields);
}
pub fn get(&self) -> PerfCounterFields {
self.0.get()
}
pub fn set(&self, fields : PerfCounterFields) {
self.0.set(fields);
}
}
#[cfg(not(feature = "perf_counters"))]
pub struct PerfCounters();
#[cfg(not(feature = "perf_counters"))]
impl PerfCounters {
pub fn new() -> Self {
Self()
}
pub fn reset(&self) {
}
pub fn get(&self) -> PerfCounterFields {
PerfCounterFields::new()
}
}