From 9cb677bc06a002378562d01f998608f587ce3749 Mon Sep 17 00:00:00 2001 From: Shaun Cox Date: Sun, 4 Jun 2023 10:13:54 -0500 Subject: [PATCH] for benchmarking, enable reports and flamegraphs --- Cargo.toml | 6 ++++++ opentelemetry-sdk/Cargo.toml | 3 ++- opentelemetry-sdk/benches/trace.rs | 7 ++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 616c3781ed..3b991e7d54 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,3 +43,9 @@ members = [ "stress", ] exclude = ["examples/external-otlp-grpcio-async-std"] + +[profile.bench] +# https://doc.rust-lang.org/cargo/reference/profiles.html#bench +# See function names in profiling reports. +# 2/true is too much, 0 is not enough, 1 is just right for back traces +debug = 1 \ No newline at end of file diff --git a/opentelemetry-sdk/Cargo.toml b/opentelemetry-sdk/Cargo.toml index 5dc5e3ece4..6876f8dd9c 100644 --- a/opentelemetry-sdk/Cargo.toml +++ b/opentelemetry-sdk/Cargo.toml @@ -37,7 +37,8 @@ rustdoc-args = ["--cfg", "docsrs"] [dev-dependencies] bincode = "1.2" -criterion = "0.4.0" +criterion = { version = "0.4.0", features = ["html_reports"] } +pprof = { version = "0.11.1", features = ["flamegraph", "criterion"] } rand_distr = "0.4.0" crossbeam-queue = "0.3.1" diff --git a/opentelemetry-sdk/benches/trace.rs b/opentelemetry-sdk/benches/trace.rs index 4d75e7493c..82e1006656 100644 --- a/opentelemetry-sdk/benches/trace.rs +++ b/opentelemetry-sdk/benches/trace.rs @@ -8,6 +8,7 @@ use opentelemetry_sdk::{ export::trace::{ExportResult, SpanData, SpanExporter}, trace as sdktrace, }; +use pprof::criterion::{Output, PProfProfiler}; fn criterion_benchmark(c: &mut Criterion) { let mut group = c.benchmark_group("EvictedHashMap"); @@ -132,5 +133,9 @@ fn trace_benchmark_group(c: &mut Criterion, name: &str group.finish(); } -criterion_group!(benches, criterion_benchmark); +criterion_group! { + name = benches; + config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None))); + targets = criterion_benchmark +} criterion_main!(benches);