mod cache;
mod counter;
mod distribution;
mod gauge;
mod gauge_i64;
mod histogram;
pub use counter::{DynamicCounter, DynamicCounterSeries};
pub use distribution::{DynamicDistribution, DynamicDistributionSeries};
pub use gauge::{DynamicGauge, DynamicGaugeSeries};
pub use gauge_i64::{DynamicGaugeI64, DynamicGaugeI64Series};
pub use histogram::{DynamicHistogram, DynamicHistogramSeries, DynamicHistogramSeriesView};
use std::collections::BTreeMap;
use std::sync::atomic::AtomicUsize;
#[cfg(feature = "eviction")]
use std::sync::atomic::{AtomicU32, Ordering};
pub(crate) use crate::thread_id::thread_id;
#[cfg(feature = "eviction")]
static EVICTION_CYCLE: AtomicU32 = AtomicU32::new(0);
#[cfg(feature = "eviction")]
#[inline]
pub fn current_cycle() -> u32 {
EVICTION_CYCLE.load(Ordering::Relaxed)
}
#[cfg(feature = "eviction")]
#[inline]
pub fn advance_cycle() -> u32 {
EVICTION_CYCLE.fetch_add(1, Ordering::Relaxed) + 1
}
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct DynamicLabelSet {
labels: Vec<(String, String)>,
}
impl DynamicLabelSet {
pub fn from_pairs(labels: &[(&str, &str)]) -> Self {
let mut map = BTreeMap::new();
for (k, v) in labels {
map.insert((*k).to_string(), (*v).to_string());
}
Self {
labels: map.into_iter().collect(),
}
}
#[doc(hidden)]
pub fn from_canonical_pairs(labels: &[(String, String)]) -> Self {
Self {
labels: labels.to_vec(),
}
}
pub fn pairs(&self) -> &[(String, String)] {
&self.labels
}
}
pub(crate) static COUNTER_IDS: AtomicUsize = AtomicUsize::new(1);
pub(crate) static GAUGE_IDS: AtomicUsize = AtomicUsize::new(1);
pub(crate) static HISTOGRAM_IDS: AtomicUsize = AtomicUsize::new(1);
pub(crate) static DISTRIBUTION_IDS: AtomicUsize = AtomicUsize::new(1);