Skip to content

Commit cb66360

Browse files
bantonssonlalitb
andauthored
perf: use line tables only and make profiling optional (#3150)
Co-authored-by: Lalit Kumar Bhasin <lalit_fin@yahoo.com>
1 parent 5d2a05e commit cb66360

File tree

19 files changed

+67
-47
lines changed

19 files changed

+67
-47
lines changed

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ resolver = "2"
1313
exclude = ["opentelemetry-prometheus"]
1414

1515
[profile.bench]
16-
# https://doc.rust-lang.org/cargo/reference/profiles.html#bench
16+
# https://doc.rust-lang.org/cargo/reference/profiles.html#debug
1717
# See function names in profiling reports.
18-
# 2/true is too much, 0 is not enough, 1 is just right for back traces
19-
debug = 1
18+
# 2/true is too much, 0 is not enough, line-tables-only is just right for back traces
19+
debug = "line-tables-only"
2020

2121
[workspace.dependencies]
2222
async-trait = "0.1"
@@ -84,6 +84,7 @@ tracing-log = "0.2"
8484
tracing-opentelemetry = "0.32"
8585
typed-builder = "0.20"
8686
uuid = "1.3"
87+
pprof = { version = "0.14", features = ["flamegraph", "criterion"] }
8788

8889
# Aviod use of crates.io version of these crates through the tracing-opentelemetry dependencies
8990
[patch.crates-io]

opentelemetry-appender-tracing/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ criterion = { workspace = true }
3131
#tokio = { workspace = true, features = ["full"]}
3232

3333
[target.'cfg(not(target_os = "windows"))'.dev-dependencies]
34-
pprof = { version = "0.14", features = ["flamegraph", "criterion"] }
34+
pprof = { workspace = true }
3535

3636
[features]
3737
default = []
3838
experimental_metadata_attributes = ["dep:tracing-log"]
3939
spec_unstable_logs_enabled = ["opentelemetry/spec_unstable_logs_enabled"]
4040
experimental_use_tracing_span_context = ["tracing-opentelemetry"]
41+
bench_profiling = []
4142

4243

4344
[[bench]]

opentelemetry-appender-tracing/benches/log-attributes.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use opentelemetry_appender_tracing::layer as tracing_layer;
2828
use opentelemetry_sdk::error::OTelSdkResult;
2929
use opentelemetry_sdk::logs::{LogProcessor, SdkLogRecord, SdkLoggerProvider};
3030
use opentelemetry_sdk::Resource;
31-
#[cfg(not(target_os = "windows"))]
31+
#[cfg(all(not(target_os = "windows"), feature = "bench_profiling"))]
3232
use pprof::criterion::{Output, PProfProfiler};
3333
use tracing::error;
3434
use tracing_subscriber::prelude::*;
@@ -251,7 +251,7 @@ fn criterion_benchmark(c: &mut Criterion) {
251251
// }
252252
}
253253

254-
#[cfg(not(target_os = "windows"))]
254+
#[cfg(all(not(target_os = "windows"), feature = "bench_profiling"))]
255255
criterion_group! {
256256
name = benches;
257257
config = Criterion::default()
@@ -261,7 +261,7 @@ criterion_group! {
261261
targets = criterion_benchmark
262262
}
263263

264-
#[cfg(target_os = "windows")]
264+
#[cfg(any(target_os = "windows", not(feature = "bench_profiling")))]
265265
criterion_group! {
266266
name = benches;
267267
config = Criterion::default()

opentelemetry-appender-tracing/benches/logs.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use opentelemetry_appender_tracing::layer as tracing_layer;
2929
use opentelemetry_sdk::error::OTelSdkResult;
3030
use opentelemetry_sdk::logs::{LogProcessor, SdkLogRecord, SdkLoggerProvider};
3131
use opentelemetry_sdk::Resource;
32-
#[cfg(not(target_os = "windows"))]
32+
#[cfg(all(not(target_os = "windows"), feature = "bench_profiling"))]
3333
use pprof::criterion::{Output, PProfProfiler};
3434
use tracing::error;
3535
use tracing_subscriber::prelude::*;
@@ -161,7 +161,7 @@ fn criterion_benchmark(c: &mut Criterion) {
161161
benchmark_with_noop_layer(c, false, "noop_layer_disabled");
162162
}
163163

164-
#[cfg(not(target_os = "windows"))]
164+
#[cfg(all(not(target_os = "windows"), feature = "bench_profiling"))]
165165
criterion_group! {
166166
name = benches;
167167
config = Criterion::default()
@@ -170,7 +170,8 @@ criterion_group! {
170170
.with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
171171
targets = criterion_benchmark
172172
}
173-
#[cfg(target_os = "windows")]
173+
174+
#[cfg(any(target_os = "windows", not(feature = "bench_profiling")))]
174175
criterion_group! {
175176
name = benches;
176177
config = Criterion::default()

opentelemetry-sdk/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ rstest = { workspace = true }
3636
temp-env = { workspace = true }
3737

3838
[target.'cfg(not(target_os = "windows"))'.dev-dependencies]
39-
pprof = { version = "0.14", features = ["flamegraph", "criterion"] }
39+
pprof = { workspace = true }
4040

4141
[features]
4242
default = ["trace", "metrics", "logs", "internal-logs"]
@@ -57,6 +57,7 @@ experimental_logs_batch_log_processor_with_async_runtime = ["logs", "experimenta
5757
experimental_logs_concurrent_log_processor = ["logs"]
5858
experimental_trace_batch_span_processor_with_async_runtime = ["tokio/sync", "trace", "experimental_async_runtime"]
5959
experimental_metrics_disable_name_validation = ["metrics"]
60+
bench_profiling = []
6061

6162
[[bench]]
6263
name = "context"

opentelemetry-sdk/benches/context.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
1+
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
22
use opentelemetry::{
33
global::BoxedTracer,
44
trace::{
@@ -11,9 +11,10 @@ use opentelemetry_sdk::{
1111
error::OTelSdkResult,
1212
trace::{Sampler, SdkTracerProvider, SpanData, SpanExporter},
1313
};
14-
#[cfg(not(target_os = "windows"))]
14+
#[cfg(all(not(target_os = "windows"), feature = "bench_profiling"))]
1515
use pprof::criterion::{Output, PProfProfiler};
1616
use std::fmt::Display;
17+
use std::hint::black_box;
1718

1819
fn criterion_benchmark(c: &mut Criterion) {
1920
let mut group = c.benchmark_group("context");
@@ -170,7 +171,7 @@ impl SpanExporter for NoopExporter {
170171
}
171172
}
172173

173-
#[cfg(not(target_os = "windows"))]
174+
#[cfg(all(not(target_os = "windows"), feature = "bench_profiling"))]
174175
criterion_group! {
175176
name = benches;
176177
config = Criterion::default()
@@ -179,12 +180,14 @@ criterion_group! {
179180
.with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
180181
targets = criterion_benchmark
181182
}
182-
#[cfg(target_os = "windows")]
183+
184+
#[cfg(any(target_os = "windows", not(feature = "bench_profiling")))]
183185
criterion_group! {
184186
name = benches;
185187
config = Criterion::default()
186188
.warm_up_time(std::time::Duration::from_secs(1))
187189
.measurement_time(std::time::Duration::from_secs(2));
188190
targets = criterion_benchmark
189191
}
192+
190193
criterion_main!(benches);

opentelemetry-sdk/benches/log_enabled.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ where
5353

5454
c.bench_function(name, |b| {
5555
b.iter(|| {
56-
criterion::black_box(logger.event_enabled(
56+
std::hint::black_box(logger.event_enabled(
5757
opentelemetry::logs::Severity::Debug,
5858
"target",
5959
Some("name"),

opentelemetry-sdk/benches/log_exporter.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use opentelemetry_sdk::logs::LogBatch;
2222
use opentelemetry_sdk::logs::LogProcessor;
2323
use opentelemetry_sdk::logs::SdkLogRecord;
2424
use opentelemetry_sdk::logs::SdkLoggerProvider;
25-
#[cfg(not(target_os = "windows"))]
25+
#[cfg(all(not(target_os = "windows"), feature = "bench_profiling"))]
2626
use pprof::criterion::{Output, PProfProfiler};
2727
use std::fmt::Debug;
2828

@@ -164,7 +164,7 @@ fn exporter_without_future(c: &mut Criterion) {
164164
});
165165
}
166166

167-
#[cfg(not(target_os = "windows"))]
167+
#[cfg(all(not(target_os = "windows"), feature = "bench_profiling"))]
168168
criterion_group! {
169169
name = benches;
170170
config = Criterion::default()
@@ -173,7 +173,7 @@ criterion_group! {
173173
.with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
174174
targets = criterion_benchmark
175175
}
176-
#[cfg(target_os = "windows")]
176+
#[cfg(any(target_os = "windows", not(feature = "bench_profiling")))]
177177
criterion_group! {
178178
name = benches;
179179
config = Criterion::default()

opentelemetry-sdk/benches/metrics_counter.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use opentelemetry::{
2020
KeyValue,
2121
};
2222
use opentelemetry_sdk::metrics::{ManualReader, SdkMeterProvider};
23-
#[cfg(not(target_os = "windows"))]
23+
#[cfg(all(not(target_os = "windows"), feature = "bench_profiling"))]
2424
use pprof::criterion::{Output, PProfProfiler};
2525
use rand::{
2626
rngs::{self},
@@ -239,7 +239,7 @@ fn random_generator(c: &mut Criterion) {
239239
});
240240
}
241241

242-
#[cfg(not(target_os = "windows"))]
242+
#[cfg(all(not(target_os = "windows"), feature = "bench_profiling"))]
243243
criterion_group! {
244244
name = benches;
245245
config = Criterion::default()
@@ -248,7 +248,7 @@ criterion_group! {
248248
.with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
249249
targets = criterion_benchmark
250250
}
251-
#[cfg(target_os = "windows")]
251+
#[cfg(any(target_os = "windows", not(feature = "bench_profiling")))]
252252
criterion_group! {
253253
name = benches;
254254
config = Criterion::default()

opentelemetry-sdk/benches/metrics_histogram.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use opentelemetry::{
1818
KeyValue,
1919
};
2020
use opentelemetry_sdk::metrics::{ManualReader, SdkMeterProvider};
21-
#[cfg(not(target_os = "windows"))]
21+
#[cfg(all(not(target_os = "windows"), feature = "bench_profiling"))]
2222
use pprof::criterion::{Output, PProfProfiler};
2323
use rand::{
2424
rngs::{self},
@@ -143,7 +143,7 @@ fn histogram_record_with_non_static_values(c: &mut Criterion, attribute_values:
143143
});
144144
}
145145

146-
#[cfg(not(target_os = "windows"))]
146+
#[cfg(all(not(target_os = "windows"), feature = "bench_profiling"))]
147147
criterion_group! {
148148
name = benches;
149149
config = Criterion::default()
@@ -152,7 +152,7 @@ criterion_group! {
152152
.with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
153153
targets = criterion_benchmark
154154
}
155-
#[cfg(target_os = "windows")]
155+
#[cfg(any(target_os = "windows", not(feature = "bench_profiling")))]
156156
criterion_group! {
157157
name = benches;
158158
config = Criterion::default()

0 commit comments

Comments
 (0)