-
Notifications
You must be signed in to change notification settings - Fork 68
feat: auto listener benchmark #420
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
1385dc2
37e5c1f
89f98a0
61701e1
7c3b6b0
c6b5f71
f1d13de
a829f75
7e088fa
e20ad33
a00b229
2e2c479
950efdc
ec1b4bf
2c72726
871b652
0c4b3cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -5,21 +5,26 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||
Hardware: Apple M4 Pro | ||||||||||||||||||||||||||||||||||||||||||||||||||||
Total Number of Cores: 10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
(Inside multipass vm running Ubuntu 22.04) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
// When no listener | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
// When no listener (automatic disable via RAII guard) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| Test | Average time| | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|-----------------------------|-------------| | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| User_Event_4_Attributes | 8 ns | | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| User_Event_6_Attributes | 8 ns | | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| User_Event_4_Attributes | 19.2 ns | | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| User_Event_6_Attributes | 19.6 ns | | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| User_Event_4_Attributes_EventName_Custom | 20.2 ns | | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| User_Event_4_Attributes_EventName_FromLogRecord | 20.6 ns | | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
// When listener is enabled | ||||||||||||||||||||||||||||||||||||||||||||||||||||
// Run below to enable | ||||||||||||||||||||||||||||||||||||||||||||||||||||
// When listener is enabled (automatic enable via RAII guard) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
// The benchmark now automatically enables/disables the listener | ||||||||||||||||||||||||||||||||||||||||||||||||||||
// using the commands below internally: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
// echo 1 | sudo tee /sys/kernel/debug/tracing/events/user_events/myprovider_L2K1/enable | ||||||||||||||||||||||||||||||||||||||||||||||||||||
// Run below to disable | ||||||||||||||||||||||||||||||||||||||||||||||||||||
// echo 0 | sudo tee /sys/kernel/debug/tracing/events/user_events/myprovider_L2K1/enable | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| Test | Average time| | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|-----------------------------|-------------| | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| User_Event_4_Attributes | 530 ns | | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| User_Event_6_Attributes | 586 ns | | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| User_Event_4_Attributes_EventName_Custom | 590 ns | | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| User_Event_4_Attributes_EventName_FromLogRecord | 595 ns | | ||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
// running the following from the current directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -35,6 +40,129 @@ use opentelemetry_user_events_logs::Processor; | |||||||||||||||||||||||||||||||||||||||||||||||||||
use tracing::error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
use tracing_subscriber::prelude::*; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
use tracing_subscriber::Registry; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
use std::process::Command; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
/// RAII guard for enabling/disabling user events listener | ||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The documentation for UserEventsListenerGuard should explain the purpose of the Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||||||||||||||||||||||||||||||||
/// | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// This guard automatically enables the user events listener when created and | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// disables it when dropped, ensuring proper cleanup even if the benchmark | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// panics or exits early. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// The guard tracks whether the listener was already enabled before it was | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// created, and only disables it on drop if it wasn't already enabled. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// This prevents interfering with other tests or processes that might have | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// enabled the listener. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
struct UserEventsListenerGuard { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
provider_name: String, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
was_enabled: bool, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
impl UserEventsListenerGuard { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// Enable the user events listener for the given provider | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// This method: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// 1. Checks if the listener is already enabled | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// 2. Enables it if it's not already enabled | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// 3. Returns a guard that will disable the listener on drop (if it wasn't already enabled) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// # Arguments | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// * `provider_name` - The name of the provider to enable/disable | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// # Returns | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// * `Ok(Self)` - A guard that will disable the listener on drop | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// * `Err(String)` - Error message if enabling failed | ||||||||||||||||||||||||||||||||||||||||||||||||||||
fn enable(provider_name: &str) -> Result<Self, String> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
let enable_path = format!("/sys/kernel/debug/tracing/events/user_events/{}_L2K1/enable", provider_name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
artemziborev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
// Check if already enabled | ||||||||||||||||||||||||||||||||||||||||||||||||||||
let check_output = Command::new("sudo") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
.arg("cat") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
.arg(&enable_path) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
.output() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
.map_err(|e| format!("Failed to check listener status: {e}"))?; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
let was_enabled = check_output.status.success() && | ||||||||||||||||||||||||||||||||||||||||||||||||||||
String::from_utf8_lossy(&check_output.stdout).trim() == "1"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
// Enable the listener | ||||||||||||||||||||||||||||||||||||||||||||||||||||
let enable_output = Command::new("sudo") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
.arg("sh") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
.arg("-c") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
.arg(format!("echo 1 | sudo tee {}", enable_path)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
.output() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
.map_err(|e| format!("Failed to enable listener: {e}"))?; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
if !enable_output.status.success() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
return Err(format!( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
"Failed to enable listener. Error: {}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
String::from_utf8_lossy(&enable_output.stderr) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
)); | |
let was_enabled = match fs::read_to_string(&enable_path) { | |
Ok(contents) => contents.trim() == "1", | |
Err(e) => { | |
if e.kind() == io::ErrorKind::PermissionDenied { | |
return Err(format!( | |
"Insufficient permissions to read '{}'. Please run the benchmark as root or with appropriate capabilities (CAP_SYS_ADMIN). Error: {}", | |
enable_path, e | |
)); | |
} else { | |
return Err(format!("Failed to check listener status: {}", e)); | |
} | |
} | |
}; | |
// Enable the listener by writing "1" to the enable file | |
if let Err(e) = fs::write(&enable_path, b"1\n") { | |
if e.kind() == io::ErrorKind::PermissionDenied { | |
return Err(format!( | |
"Insufficient permissions to write to '{}'. Please run the benchmark as root or with appropriate capabilities (CAP_SYS_ADMIN). Error: {}", | |
enable_path, e | |
)); | |
} else { | |
return Err(format!("Failed to enable listener: {}", e)); | |
} |
Copilot uses AI. Check for mistakes.
artemziborev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Copilot
AI
Aug 14, 2025
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.
The check_user_events_available
function uses sudo
which may not be available in all benchmark environments. Consider checking file permissions first or providing a non-privileged alternative.
} | |
let path = "/sys/kernel/tracing/user_events_status"; | |
fs::read_to_string(path) | |
.map_err(|e| format!("Failed to read {}: {}", path, e)) |
Copilot uses AI. Check for mistakes.
artemziborev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
artemziborev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
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.
I don't think this works as the tracepoint name will not exist at this point! This should be done after the provider is built, which will build the user_events exporter, which will create the tracepoint names.
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.
Moved UserEventsListenerGuard::enable(PROVIDER_NAME) to occur after building the provider in all benchmarks, ensuring tracepoints exist first.
artemziborev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
Copilot
AI
Aug 14, 2025
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.
The error handling pattern with unwrap_or_else
and fallback to dummy_guard()
is repeated in multiple functions. Consider extracting this into a helper function to reduce code duplication and improve maintainability.
}); | |
let _guard = enable_listener_with_fallback(PROVIDER_NAME); |
Copilot uses AI. Check for mistakes.
Uh oh!
There was an error while loading. Please reload this page.