Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add benchmark for user_events enabled check #133

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
7 changes: 6 additions & 1 deletion opentelemetry-user-events-logs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ opentelemetry-appender-tracing = { workspace = true }
tracing = { version = "0.1", default-features = false, features = ["std"] }
tracing-core = "0.1.31"
tracing-subscriber = { version = "0.3.0", default-features = false, features = ["registry", "std"] }
microbench = "0.5"
criterion = "0.4" # Add the Criterion crate for benchmarking

[features]
spec_unstable_logs_enabled = ["opentelemetry/spec_unstable_logs_enabled", "opentelemetry_sdk/spec_unstable_logs_enabled", "opentelemetry-appender-tracing/spec_unstable_logs_enabled"]
default = ["spec_unstable_logs_enabled"]

[[bench]]
name = "benchmark"
harness = false

34 changes: 34 additions & 0 deletions opentelemetry-user-events-logs/benches/benchmark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Run as root user as access to `tracefs` is required, or ensure the current user has the necessary permissions.
// To run benchmarks with root privileges, execute:
// sudo -E /home/<username>/.cargo/bin/cargo bench
// Replace <username> with your actual username.
//
// System Information:
// Processor: AMD EPYC 7763 64-Core Processor
// CPU Cores: 8
// Logical Processors: 16
// Memory: 64 GB
// time: [4.1429 ns 4.1514 ns 4.1621 ns]
cijothomas marked this conversation as resolved.
Show resolved Hide resolved

use criterion::{criterion_group, criterion_main, Criterion};
use eventheader_dynamic::{Provider, ProviderOptions};

fn benchmark_find_set(c: &mut Criterion) {
// Setup the Provider
let mut options = ProviderOptions::new();
options = *options.group_name("testprovider");
let mut provider = Provider::new("testprovider", &options);

// Register some dummy events with specific levels and keywords
let keyword = 0x01; // Example keyword
let mut level = 4; // Example level (Informational)
provider.register_set(eventheader::Level::Informational, keyword);
level = level.into();

Check failure on line 26 in opentelemetry-user-events-logs/benches/benchmark.rs

View workflow job for this annotation

GitHub Actions / lint

useless conversion to the same type: `u8`
// Benchmark the `find_set` method
c.bench_function("provider_find_set", |b| {
b.iter(|| provider.find_set(level.into(), keyword));
});
}

criterion_group!(benches, benchmark_find_set);
criterion_main!(benches);
Loading