dipstick/src/lib.rs

140 lines
3.2 KiB
Rust
Raw Normal View History

2018-01-26 20:40:15 +00:00
//! A quick, modular metrics toolkit for Rust applications.
2017-09-01 07:31:25 +00:00
#![cfg_attr(feature = "bench", feature(test))]
2019-04-09 11:55:15 +00:00
#![warn(
missing_docs,
trivial_casts,
trivial_numeric_casts,
unused_extern_crates,
unused_qualifications
)]
#![recursion_limit = "32"]
#[cfg(feature = "bench")]
extern crate test;
#[macro_use]
2017-10-10 20:44:27 +00:00
extern crate log;
2018-01-08 05:32:32 +00:00
#[macro_use]
extern crate lazy_static;
2018-06-11 18:56:40 +00:00
#[macro_use]
2018-09-14 10:47:31 +00:00
mod macros;
pub use crate::macros::*;
2018-09-14 10:47:31 +00:00
2019-04-09 11:55:15 +00:00
#[cfg(not(feature = "parking_lot"))]
macro_rules! write_lock {
2019-04-09 11:55:15 +00:00
($WUT:expr) => {
$WUT.write().unwrap()
};
}
2019-04-09 11:55:15 +00:00
#[cfg(feature = "parking_lot")]
macro_rules! write_lock {
2019-04-09 11:55:15 +00:00
($WUT:expr) => {
$WUT.write()
};
}
2019-04-09 11:55:15 +00:00
#[cfg(not(feature = "parking_lot"))]
macro_rules! read_lock {
2019-04-09 11:55:15 +00:00
($WUT:expr) => {
$WUT.read().unwrap()
};
}
2019-04-09 11:55:15 +00:00
#[cfg(feature = "parking_lot")]
macro_rules! read_lock {
2019-04-09 11:55:15 +00:00
($WUT:expr) => {
$WUT.read()
};
}
2020-05-15 04:28:40 +00:00
mod attributes;
mod clock;
mod input;
mod label;
mod metrics;
mod name;
mod pcg32;
mod proxy;
mod scheduler;
mod atomic;
mod stats;
mod cache;
mod lru_cache;
mod multi;
mod queue;
pub use crate::attributes::{
Attributes, Buffered, Buffering, MetricId, Observe, ObserveWhen, OnFlush, OnFlushCancel,
Prefixed, Sampled, Sampling, WithAttributes,
};
2020-05-15 04:28:40 +00:00
pub use crate::clock::TimeHandle;
pub use crate::input::{
2019-04-09 11:55:15 +00:00
Counter, Gauge, Input, InputDyn, InputKind, InputMetric, InputScope, Level, Marker, Timer,
};
2020-05-15 04:28:40 +00:00
pub use crate::label::{AppLabel, Labels, ThreadLabel};
pub use crate::name::{MetricName, NameParts};
2020-05-23 03:47:18 +00:00
pub use crate::output::void::Void;
2020-05-25 13:12:24 +00:00
pub use crate::scheduler::{Cancel, CancelGuard, CancelHandle, ScheduleFlush};
#[cfg(test)]
2020-05-15 04:28:40 +00:00
pub use crate::clock::{mock_clock_advance, mock_clock_reset};
2020-05-15 04:28:40 +00:00
pub use crate::proxy::Proxy;
2018-09-14 10:47:31 +00:00
mod output;
pub use crate::output::format::{
Formatting, LabelOp, LineFormat, LineOp, LineTemplate, SimpleFormat,
};
pub use crate::output::graphite::{Graphite, GraphiteMetric, GraphiteScope};
pub use crate::output::log::{Log, LogScope};
pub use crate::output::map::StatsMapScope;
pub use crate::output::statsd::{Statsd, StatsdMetric, StatsdScope};
pub use crate::output::stream::{Stream, TextScope};
2018-09-14 10:47:31 +00:00
//#[cfg(feature="prometheus")]
pub use crate::output::prometheus::{Prometheus, PrometheusScope};
2020-05-15 04:28:40 +00:00
pub use crate::atomic::AtomicBucket;
pub use crate::cache::CachedInput;
pub use crate::multi::{MultiInput, MultiInputScope};
pub use crate::queue::{InputQueue, InputQueueScope, QueuedInput};
pub use crate::stats::{stats_all, stats_average, stats_summary, ScoreType};
2018-09-14 10:47:31 +00:00
2020-05-23 03:47:18 +00:00
use std::io;
2020-05-15 04:28:40 +00:00
/// Base type for recorded metric values.
pub type MetricValue = isize;
2018-09-14 10:47:31 +00:00
2020-05-15 04:28:40 +00:00
/// Both InputScope and OutputScope share the ability to flush the recorded data.
pub trait Flush {
/// Flush does nothing by default.
2020-05-23 03:47:18 +00:00
fn flush(&self) -> io::Result<()>;
2020-05-15 04:28:40 +00:00
}
2018-09-14 10:47:31 +00:00
2020-05-15 04:28:40 +00:00
#[cfg(feature = "bench")]
pub mod bench {
use super::clock::*;
use super::input::*;
use crate::AtomicBucket;
#[bench]
fn get_instant(b: &mut test::Bencher) {
b.iter(|| test::black_box(TimeHandle::now()));
}
#[bench]
fn time_bench_direct_dispatch_event(b: &mut test::Bencher) {
let metrics = AtomicBucket::new();
let marker = metrics.marker("aaa");
b.iter(|| test::black_box(marker.mark()));
}
}