forked from open-telemetry/opentelemetry-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog_enabled.rs
88 lines (78 loc) · 2.69 KB
/
log_enabled.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
The benchmark results:
criterion = "0.5.1"
Hardware: Apple M4 Pro
Total Number of Cores: 14 (10 performance and 4 efficiency)
| Test | Average time|
|---------------------------------------------|-------------|
| exporter_disabled_concurrent_processor | 2.5 ns |
| exporter_disabled_simple_processor | 5.3 ns |
*/
// cargo bench --bench log_enabled --features="spec_unstable_logs_enabled,experimental_logs_concurrent_log_processor"
use criterion::{criterion_group, criterion_main, Criterion};
use opentelemetry::logs::{Logger, LoggerProvider};
use opentelemetry_sdk::error::OTelSdkResult;
use opentelemetry_sdk::logs::concurrent_log_processor::SimpleConcurrentLogProcessor;
use opentelemetry_sdk::logs::{
LogBatch, LogExporter, LogProcessor, SdkLoggerProvider, SimpleLogProcessor,
};
use opentelemetry_sdk::Resource;
#[cfg(not(target_os = "windows"))]
use pprof::criterion::{Output, PProfProfiler};
#[derive(Debug)]
struct NoopExporter;
impl LogExporter for NoopExporter {
async fn export(&self, _: LogBatch<'_>) -> OTelSdkResult {
Ok(())
}
fn shutdown(&self) -> OTelSdkResult {
Ok(())
}
#[inline]
fn event_enabled(
&self,
_level: opentelemetry::logs::Severity,
_target: &str,
_name: Option<&str>,
) -> bool {
false
}
fn set_resource(&mut self, _: &Resource) {}
}
fn benchmark_exporter_enabled_false<T>(c: &mut Criterion, name: &str, processor: T)
where
T: LogProcessor + Send + Sync + 'static,
{
let provider = SdkLoggerProvider::builder()
.with_log_processor(processor)
.build();
let logger = provider.logger("test_logger");
c.bench_function(name, |b| {
b.iter(|| {
criterion::black_box(logger.event_enabled(
opentelemetry::logs::Severity::Debug,
"target",
Some("name"),
));
});
});
}
fn criterion_benchmark(c: &mut Criterion) {
let processor = SimpleConcurrentLogProcessor::new(NoopExporter);
benchmark_exporter_enabled_false(c, "exporter_disabled_concurrent_processor", processor);
let simple = SimpleLogProcessor::new(NoopExporter);
benchmark_exporter_enabled_false(c, "exporter_disabled_simple_processor", simple);
}
#[cfg(not(target_os = "windows"))]
criterion_group! {
name = benches;
config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
targets = criterion_benchmark
}
#[cfg(target_os = "windows")]
criterion_group! {
name = benches;
config = Criterion::default();
targets = criterion_benchmark
}
criterion_main!(benches);