1#![cfg_attr(feature = "bench", feature(test))]
4#![warn(
5 missing_docs,
6 trivial_casts,
7 trivial_numeric_casts,
8 unused_extern_crates,
9 unused_qualifications
10)]
11#![recursion_limit = "32"]
12
13#[cfg(doctest)]
14#[macro_use]
15extern crate doc_comment;
16#[cfg(doctest)]
17doctest!("../README.md");
18#[cfg(doctest)]
19doctest!("../HANDBOOK.md");
20
21#[cfg(feature = "bench")]
22extern crate test;
23
24#[macro_use]
25extern crate log;
26
27#[macro_use]
28extern crate lazy_static;
29
30#[macro_use]
31mod macros;
32pub use crate::macros::*;
33
34#[cfg(not(feature = "parking_lot"))]
35macro_rules! write_lock {
36 ($WUT:expr) => {
37 $WUT.write().unwrap()
38 };
39}
40
41#[cfg(feature = "parking_lot")]
42macro_rules! write_lock {
43 ($WUT:expr) => {
44 $WUT.write()
45 };
46}
47
48#[cfg(not(feature = "parking_lot"))]
49macro_rules! read_lock {
50 ($WUT:expr) => {
51 $WUT.read().unwrap()
52 };
53}
54
55#[cfg(feature = "parking_lot")]
56macro_rules! read_lock {
57 ($WUT:expr) => {
58 $WUT.read()
59 };
60}
61
62mod attributes;
63mod clock;
64mod input;
65mod label;
66mod metrics;
67mod name;
68mod pcg32;
69mod proxy;
70mod scheduler;
71
72mod atomic;
73mod stats;
74
75mod cache;
76mod lru_cache;
77
78mod multi;
79mod queue;
80
81pub use crate::attributes::{
82 Attributes, Buffered, Buffering, MetricId, Observe, ObserveWhen, OnFlush, OnFlushCancel,
83 Prefixed, Sampled, Sampling, WithAttributes,
84};
85pub use crate::clock::TimeHandle;
86pub use crate::input::{
87 Counter, Gauge, Input, InputDyn, InputKind, InputMetric, InputScope, Level, Marker, Timer,
88};
89pub use crate::label::{AppLabel, Labels, ThreadLabel};
90pub use crate::name::{MetricName, NameParts};
91pub use crate::output::void::Void;
92pub use crate::scheduler::{Cancel, CancelGuard, CancelHandle, ScheduleFlush};
93
94#[cfg(test)]
95pub use crate::clock::{mock_clock_advance, mock_clock_reset};
96
97pub use crate::proxy::Proxy;
98
99mod output;
100pub use crate::output::format::{
101 Formatting, LabelOp, LineFormat, LineOp, LineTemplate, SimpleFormat,
102};
103pub use crate::output::graphite::{Graphite, GraphiteMetric, GraphiteScope};
104pub use crate::output::graphite_udp::{GraphiteUdp, GraphiteUdpMetric, GraphiteUdpScope};
105pub use crate::output::log::{Log, LogScope};
106pub use crate::output::map::StatsMapScope;
107pub use crate::output::statsd::{Statsd, StatsdMetric, StatsdScope};
108pub use crate::output::stream::{Stream, TextScope};
109
110pub use crate::output::prometheus::{Prometheus, PrometheusScope};
112
113pub use crate::atomic::AtomicBucket;
114pub use crate::cache::CachedInput;
115pub use crate::multi::{MultiInput, MultiInputScope};
116pub use crate::queue::{InputQueue, InputQueueScope, QueuedInput};
117pub use crate::stats::{ScoreType, stats_all, stats_average, stats_summary};
118
119use std::io;
120
121pub type MetricValue = isize;
123
124pub trait Flush {
126 fn flush(&self) -> io::Result<()>;
128}
129
130#[cfg(feature = "bench")]
132pub mod bench {
133
134 use super::clock::*;
135 use super::input::*;
136 use crate::AtomicBucket;
137
138 #[bench]
139 fn get_instant(b: &mut test::Bencher) {
140 b.iter(|| test::black_box(TimeHandle::now()));
141 }
142
143 #[bench]
144 fn time_bench_direct_dispatch_event(b: &mut test::Bencher) {
145 let metrics = AtomicBucket::new();
146 let marker = metrics.marker("aaa");
147 b.iter(|| test::black_box(marker.mark()));
148 }
149}