fast_telemetry/metric/dynamic/
mod.rs1mod counter;
14mod distribution;
15mod gauge;
16mod gauge_i64;
17mod histogram;
18
19pub use counter::{DynamicCounter, DynamicCounterSeries};
20pub use distribution::{DynamicDistribution, DynamicDistributionSeries};
21pub use gauge::{DynamicGauge, DynamicGaugeSeries};
22pub use gauge_i64::{DynamicGaugeI64, DynamicGaugeI64Series};
23pub use histogram::{DynamicHistogram, DynamicHistogramSeries, DynamicHistogramSeriesView};
24
25use std::collections::BTreeMap;
26use std::sync::atomic::AtomicUsize;
27#[cfg(feature = "eviction")]
28use std::sync::atomic::{AtomicU32, Ordering};
29
30pub(crate) use crate::thread_id::thread_id;
31
32#[cfg(feature = "eviction")]
33static EVICTION_CYCLE: AtomicU32 = AtomicU32::new(0);
34
35#[cfg(feature = "eviction")]
37#[inline]
38pub fn current_cycle() -> u32 {
39 EVICTION_CYCLE.load(Ordering::Relaxed)
40}
41
42#[cfg(feature = "eviction")]
46#[inline]
47pub fn advance_cycle() -> u32 {
48 EVICTION_CYCLE.fetch_add(1, Ordering::Relaxed) + 1
49}
50
51#[derive(Clone, Debug, Eq, PartialEq, Hash)]
56pub struct DynamicLabelSet {
57 labels: Vec<(String, String)>,
58}
59
60impl DynamicLabelSet {
61 pub fn from_pairs(labels: &[(&str, &str)]) -> Self {
63 let mut map = BTreeMap::new();
64 for (k, v) in labels {
65 map.insert((*k).to_string(), (*v).to_string());
66 }
67 Self {
68 labels: map.into_iter().collect(),
69 }
70 }
71
72 #[doc(hidden)]
76 pub fn from_canonical_pairs(labels: &[(String, String)]) -> Self {
77 Self {
78 labels: labels.to_vec(),
79 }
80 }
81
82 pub fn pairs(&self) -> &[(String, String)] {
84 &self.labels
85 }
86}
87
88pub(crate) static COUNTER_IDS: AtomicUsize = AtomicUsize::new(1);
90pub(crate) static GAUGE_IDS: AtomicUsize = AtomicUsize::new(1);
91pub(crate) static HISTOGRAM_IDS: AtomicUsize = AtomicUsize::new(1);
92pub(crate) static DISTRIBUTION_IDS: AtomicUsize = AtomicUsize::new(1);