-
Notifications
You must be signed in to change notification settings - Fork 734
/
reload.rs
65 lines (61 loc) · 2.22 KB
/
reload.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#![cfg(feature = "env-filter")]
use criterion::{criterion_group, criterion_main, Criterion};
use tracing_subscriber::{
filter::LevelFilter,
fmt::{
format::{DefaultFields, Format, Full},
Collector, CollectorBuilder,
},
EnvFilter,
};
mod support;
use support::NoWriter;
/// Prepare a real-world-inspired collector and use it to measure the performance impact of
/// reloadable collectors.
fn mk_builder() -> CollectorBuilder<DefaultFields, Format<Full>, EnvFilter, fn() -> NoWriter> {
let filter = EnvFilter::default()
.add_directive("this=off".parse().unwrap())
.add_directive("also=off".parse().unwrap())
.add_directive("this_too=off".parse().unwrap())
.add_directive("stuff=warn".parse().unwrap())
.add_directive("moar=warn".parse().unwrap())
.add_directive(LevelFilter::INFO.into());
Collector::builder()
.with_env_filter(filter)
.with_writer(NoWriter::new as _)
.with_ansi(true)
.with_target(true)
.with_level(true)
.with_thread_names(true)
}
fn bench_reload(c: &mut Criterion) {
let mut group = c.benchmark_group("reload");
group.bench_function("complex-collector", |b| {
let builder = mk_builder();
let collector = builder.finish();
tracing::collect::with_default(collector, || {
b.iter(|| {
tracing::info!(target: "this", "hi");
tracing::debug!(target: "enabled", "hi");
tracing::warn!(target: "hepp", "hi");
tracing::trace!(target: "stuff", "hi");
})
});
});
group.bench_function("complex-collector-reloadable", |b| {
let builder = mk_builder().with_filter_reloading();
let _handle = builder.reload_handle();
let collector = builder.finish();
tracing::collect::with_default(collector, || {
b.iter(|| {
tracing::info!(target: "this", "hi");
tracing::debug!(target: "enabled", "hi");
tracing::warn!(target: "hepp", "hi");
tracing::trace!(target: "stuff", "hi");
})
});
});
group.finish();
}
criterion_group!(benches, bench_reload);
criterion_main!(benches);