-
Notifications
You must be signed in to change notification settings - Fork 41
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
lalitb
wants to merge
7
commits into
open-telemetry:main
Choose a base branch
from
lalitb:user-events-logs-provider-benchmark
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9e3b47f
add benchmark
lalitb 56cd4ef
Merge branch 'main' into user-events-logs-provider-benchmark
lalitb 6f6d08e
add benchmark for concurrent check
lalitb f972a4c
fix benchmark
lalitb 22f6dc4
Merge branch 'main' into user-events-logs-provider-benchmark
lalitb ffb659b
Merge branch 'main' into user-events-logs-provider-benchmark
lalitb ac193e0
Merge branch 'main' into user-events-logs-provider-benchmark
lalitb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// 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 | ||
|
||
// provider_find_set_single time: [3.9862 ns 3.9898 ns 3.9937 ns] | ||
// provider_find_set_concurrent_0threads time: [3.9937 ns 3.9978 ns 4.0024 ns] | ||
// provider_find_set_concurrent_2threads: time: time: [111.52 ns 114.61 ns 117.38 ns] | ||
// provider_find_set_concurrent_4threads: time: time: [199.18 ns 203.92 ns 208.43 ns] | ||
// provider_find_set_concurrent_8threads time: time: [199.18 ns 203.92 ns 208.43 ns] | ||
|
||
use criterion::black_box; | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use eventheader_dynamic::{Provider, ProviderOptions}; | ||
use std::sync::{ | ||
atomic::{AtomicBool, Ordering}, | ||
Arc, | ||
}; | ||
use std::thread; | ||
|
||
/// Benchmark `find_set` with no concurrent threads | ||
fn benchmark_find_set_single(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 level = 4; // Example level (Informational) | ||
provider.register_set(eventheader::Level::Informational, keyword); | ||
|
||
// Benchmark the `find_set` method with `enabled` check | ||
c.bench_function("provider_find_set_single", |b| { | ||
b.iter(|| { | ||
if let Some(event_set) = provider.find_set(level.into(), keyword) { | ||
black_box(event_set.enabled()); // Check if the tracepoint is being listened to | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
/// Benchmark `find_set` with a parameterized number of concurrent threads | ||
fn benchmark_find_set_concurrent(c: &mut Criterion) { | ||
let thread_counts = [0, 2, 4, 8]; // Test with 2, 4, and 8 threads | ||
|
||
for &thread_count in &thread_counts { | ||
// 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 level = 4; // Example level (Informational) | ||
provider.register_set(eventheader::Level::Informational, keyword); | ||
|
||
// Shared Provider and stop flag | ||
let provider = Arc::new(provider); | ||
let stop_flag = Arc::new(AtomicBool::new(false)); | ||
|
||
// Spawn worker threads | ||
let mut worker_handles = Vec::new(); | ||
for _ in 0..thread_count { | ||
let provider_clone = Arc::clone(&provider); | ||
let stop_flag_clone = Arc::clone(&stop_flag); | ||
worker_handles.push(thread::spawn(move || { | ||
while !stop_flag_clone.load(Ordering::Relaxed) { | ||
if let Some(event_set) = provider_clone.find_set(level.into(), keyword) { | ||
black_box(event_set.enabled()); // Check if tracepoint is being listened to | ||
} | ||
} | ||
})); | ||
} | ||
|
||
// Dereference the `Arc` once before the benchmark to reduce overhead | ||
let provider_ref: &Provider = &provider; | ||
|
||
// Benchmark the `find_set` method with `enabled` check | ||
let benchmark_name = format!("provider_find_set_concurrent_{}threads", thread_count); | ||
c.bench_function(&benchmark_name, |b| { | ||
b.iter(|| { | ||
if let Some(event_set) = provider_ref.find_set(level.into(), keyword) { | ||
black_box(event_set.enabled()); // Check if tracepoint is being listened to | ||
} | ||
}); | ||
}); | ||
|
||
// Signal worker threads to stop | ||
stop_flag.store(true, Ordering::Relaxed); | ||
|
||
// Wait for all worker threads to complete | ||
for handle in worker_handles { | ||
let _ = handle.join(); | ||
} | ||
} | ||
} | ||
|
||
criterion_group!( | ||
benches, | ||
benchmark_find_set_single, | ||
benchmark_find_set_concurrent | ||
); | ||
criterion_main!(benches); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we can simply re-use the existing stress test? (copy it over to contribute repo?)