Skip to content

Commit

Permalink
Fixes issue open-telemetry#1612.
Browse files Browse the repository at this point in the history
  • Loading branch information
marcalff committed Sep 20, 2022
1 parent 82a8115 commit 7400349
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions sdk/test/trace/sampler_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,16 @@ void BM_TraceIdRatioBasedSamplerShouldSample(benchmark::State &state)
BENCHMARK(BM_TraceIdRatioBasedSamplerShouldSample);

// Sampler Helper Function
void BenchmarkSpanCreation(std::shared_ptr<Sampler> /* TODO: fix issue #1612 sampler */,
benchmark::State &state)
void BenchmarkSpanCreation(std::unique_ptr<Sampler> &&sampler, benchmark::State &state)
{
std::unique_ptr<SpanExporter> exporter(new InMemorySpanExporter());
std::unique_ptr<SpanProcessor> processor(new SimpleSpanProcessor(std::move(exporter)));
std::vector<std::unique_ptr<SpanProcessor>> processors;
processors.push_back(std::move(processor));
auto context = std::make_shared<TracerContext>(std::move(processors));
auto resource = opentelemetry::sdk::resource::Resource::Create({});
auto tracer = std::shared_ptr<opentelemetry::trace::Tracer>(new Tracer(context));
auto context =
std::make_shared<TracerContext>(std::move(processors), resource, std::move(sampler));
auto tracer = std::shared_ptr<opentelemetry::trace::Tracer>(new Tracer(context));

while (state.KeepRunning())
{
Expand All @@ -142,14 +142,16 @@ void BenchmarkSpanCreation(std::shared_ptr<Sampler> /* TODO: fix issue #1612 sam
// Test to measure performance for span creation
void BM_SpanCreation(benchmark::State &state)
{
BenchmarkSpanCreation(std::move(std::make_shared<AlwaysOnSampler>()), state);
std::unique_ptr<Sampler> sampler(new AlwaysOnSampler());
BenchmarkSpanCreation(std::move(sampler), state);
}
BENCHMARK(BM_SpanCreation);

// Test to measure performance overhead for no-op span creation
void BM_NoopSpanCreation(benchmark::State &state)
{
BenchmarkSpanCreation(std::move(std::make_shared<AlwaysOffSampler>()), state);
std::unique_ptr<Sampler> sampler(new AlwaysOffSampler());
BenchmarkSpanCreation(std::move(sampler), state);
}
BENCHMARK(BM_NoopSpanCreation);

Expand Down

0 comments on commit 7400349

Please sign in to comment.