Skip to content

Commit

Permalink
cleanup old macros (#251)
Browse files Browse the repository at this point in the history
Remove old macros since we now use the attribute macros everywhere.
  • Loading branch information
brayniac authored May 3, 2024
1 parent 23b1eb8 commit d092ddf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 133 deletions.
132 changes: 0 additions & 132 deletions src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,138 +49,6 @@ impl Counter {
}
}

#[macro_export]
#[rustfmt::skip]
/// A convenience macro for constructing a lazily initialized
/// `metriken::Counter` given an identifier, name, and optional description.
macro_rules! counter {
($ident:ident, $name:tt) => {
#[metriken::metric(
name = $name,
crate = metriken
)]
pub static $ident: Lazy<metriken::Counter> = metriken::Lazy::new(|| {
metriken::Counter::new()
});
};
($ident:ident, $name:tt, $description:tt) => {
#[metriken::metric(
name = $name,
crate = metriken
)]
pub static $ident: Lazy<metriken::Counter> = metriken::Lazy::new(|| {
metriken::Counter::new()
});
};
}

#[macro_export]
#[rustfmt::skip]
/// A convenience macro for constructing a lazily initialized
/// `metriken::Gauge` given an identifier, name, and optional description.
macro_rules! gauge {
($ident:ident, $name:tt) => {
#[metriken::metric(
name = $name,
crate = metriken
)]
pub static $ident: Lazy<metriken::Gauge> = metriken::Lazy::new(|| {
metriken::Gauge::new()
});
};
($ident:ident, $name:tt, $description:tt) => {
#[metriken::metric(
name = $name,
crate = metriken
)]
pub static $ident: Lazy<metriken::Gauge> = metriken::Lazy::new(|| {
metriken::Gauge::new()
});
};
}

#[macro_export]
#[rustfmt::skip]
/// A convenience macro for constructing a lazily initialized
/// `metriken::AtomicHistogram` given an identifier, name, and optional
/// description.
///
/// The histogram configuration used here can record counts for all 64bit
/// integer values with a maximum error of 0.78%.
macro_rules! histogram {
($ident:ident, $name:tt) => {
#[metriken::metric(
name = $name,
crate = metriken
)]
pub static $ident: metriken::AtomicHistogram = metriken::AtomicHistogram::new($crate::common::HISTOGRAM_GROUPING_POWER, 64);
};
($ident:ident, $name:tt, $description:tt) => {
#[metriken::metric(
name = $name,
description = $description,
crate = metriken
)]
pub static $ident: metriken::AtomicHistogram = metriken::AtomicHistogram::new($crate::common::HISTOGRAM_GROUPING_POWER, 64);
};
}

#[macro_export]
#[rustfmt::skip]
/// A convenience macro for constructing a lazily initialized
/// `metriken::RwLockHistogram` given an identifier, name, and optional
/// description.
///
/// The histogram configuration used here can record counts for all 64bit
/// integer values with a maximum error of 0.78%.
macro_rules! bpfhistogram {
($ident:ident, $name:tt) => {
#[metriken::metric(
name = $name,
crate = metriken
)]
pub static $ident: metriken::RwLockHistogram = metriken::RwLockHistogram::new($crate::common::HISTOGRAM_GROUPING_POWER, 64);
};
($ident:ident, $name:tt, $description:tt) => {
#[metriken::metric(
name = $name,
description = $description,
crate = metriken
)]
pub static $ident: metriken::RwLockHistogram = metriken::RwLockHistogram::new($crate::common::HISTOGRAM_GROUPING_POWER, 64);
};
}

#[macro_export]
#[rustfmt::skip]
/// A convenience macro for constructing a lazily initialized counter with a
/// histogram which will track secondly rates for the same counter.
macro_rules! counter_with_histogram {
($counter:ident, $histogram:ident, $name:tt) => {
self::counter!($counter, $name);
self::histogram!($histogram, $name);
};
($counter:ident, $histogram:ident, $name:tt, $description:tt) => {
self::counter!($counter, $name, $description);
self::histogram!($histogram, $name, $description);
}
}

#[macro_export]
#[rustfmt::skip]
/// A convenience macro for constructing a lazily initialized gauge with a
/// histogram which will track instantaneous readings for the same gauge.
macro_rules! gauge_with_histogram {
($gauge:ident, $histogram:ident, $name:tt) => {
self::gauge!($gauge, $name);
self::histogram!($histogram, $name);
};
($gauge:ident, $histogram:ident, $name:tt, $description:tt) => {
self::gauge!($gauge, $name, $description);
self::histogram!($histogram, $name, $description);
}
}

#[macro_export]
#[rustfmt::skip]
/// A convenience macro for defining a top-level sampler which will contain
Expand Down
9 changes: 8 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use crate::common::Counter;
use backtrace::Backtrace;
use clap::{Arg, Command};
use linkme::distributed_slice;
use metriken::metric;
use metriken::Lazy;
use metriken::LazyCounter;
use metriken_exposition::Histogram;
use ringlog::*;
use std::collections::HashMap;
Expand Down Expand Up @@ -92,7 +95,11 @@ pub static PERCENTILES: &[(&str, f64)] = &[
#[distributed_slice]
pub static SAMPLERS: [fn(config: &Config) -> Box<dyn Sampler>] = [..];

counter!(RUNTIME_SAMPLE_LOOP, "runtime/sample/loop");
#[metric(
name = "runtime/sample/loop",
description = "The total number sampler loops executed"
)]
pub static RUNTIME_SAMPLE_LOOP: LazyCounter = LazyCounter::new(metriken::Counter::default);

fn main() {
// custom panic hook to terminate whole process after unwinding
Expand Down

0 comments on commit d092ddf

Please sign in to comment.