Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,026 changes: 913 additions & 113 deletions Cargo.lock

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions crates/codspeed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,36 @@ serde = { workspace = true }
serde_json = { workspace = true }
statrs = { version = "0.18.0", default-features = false }

opentelemetry = { version = "0.33", default-features = false, features = ["trace"], optional = true }
opentelemetry_sdk = { version = "0.33", default-features = false, features = ["trace"], optional = true }
futures-executor = { version = "0.3", default-features = false, features = ["std"], optional = true }
opentelemetry-otlp = { version = "0.33", default-features = false, features = [
"trace",
"http-proto",
"reqwest-blocking-client",
], optional = true }
tracing = { version = "0.1", default-features = false, features = ["std"], optional = true }
tracing-opentelemetry = { version = "0.34", default-features = false, optional = true }
tracing-subscriber = { version = "0.3", default-features = false, features = [
"std",
"registry",
"env-filter",
], optional = true }
# Unused directly: raises the floor of `sharded-slab`'s `lazy_static = "1"`, which fails to build below 1.1
lazy_static = { version = "1.1", optional = true }

[features]
otel = [
"dep:futures-executor",
"dep:opentelemetry",
"dep:opentelemetry_sdk",
"dep:opentelemetry-otlp",
"dep:tracing",
"dep:tracing-opentelemetry",
"dep:tracing-subscriber",
"dep:lazy_static",
]

[[bench]]
name = "native"
harness = false
Expand Down
21 changes: 21 additions & 0 deletions crates/codspeed/src/benchmark_scope.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! The benchmark being run, which the exported telemetry is attributed to.
//!
//! Without the `otel` feature, entering and exiting a scope does nothing.

/// Marks the start of the benchmark `uri`. Spans started until [`exit`] carry its URI.
///
/// Call it outside the measured section.
pub fn enter(uri: &str) {
#[cfg(feature = "otel")]
crate::otel::enter_benchmark(uri);
#[cfg(not(feature = "otel"))]
let _ = uri;
}

/// Marks the end of the current benchmark and exports the spans held so far.
///
/// Call it outside the measured section, before the benchmark is reported as executed.
pub fn exit() {
#[cfg(feature = "otel")]
crate::otel::exit_benchmark();
}
11 changes: 9 additions & 2 deletions crates/codspeed/src/codspeed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ impl CodSpeed {
#[inline(always)]
pub fn start_benchmark(&mut self, name: &str) {
self.current_benchmark = CString::new(name).expect("CString::new failed");
crate::benchmark_scope::enter(name);

if let InstrumentationStatus::InstrumentHooks(hooks_instance) = &self.instrumentation_status
{
Expand All @@ -99,9 +100,15 @@ impl CodSpeed {
// The overhead in case we are not running valgrind is extremely low, and we do not want to
// add a conditionnal branch to valgrind measurements.
measurement::stop(&self.current_benchmark);
if let InstrumentationStatus::InstrumentHooks(hooks_instance) = &self.instrumentation_status
{
let hooks_instance = match &self.instrumentation_status {
InstrumentationStatus::InstrumentHooks(hooks_instance) => Some(*hooks_instance),
_ => None,
};
if let Some(hooks_instance) = hooks_instance {
let _ = hooks_instance.stop_benchmark();
}
crate::benchmark_scope::exit();
if let Some(hooks_instance) = hooks_instance {
let _ =
hooks_instance.set_executed_benchmark(&self.current_benchmark.to_string_lossy());
}
Expand Down
3 changes: 3 additions & 0 deletions crates/codspeed/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
pub mod benchmark_scope;
pub mod codspeed;

pub mod instrument_hooks;

mod macros;
mod measurement;
#[cfg(feature = "otel")]
pub mod otel;
mod request;
pub mod utils;
pub mod walltime_results;
Loading
Loading