Skip to content
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

Fixes span creation benchmark issue #1612. #1622

Merged
merged 2 commits into from
Sep 21, 2022
Merged
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
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::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::make_shared<AlwaysOffSampler>(), state);
std::unique_ptr<Sampler> sampler(new AlwaysOffSampler());
BenchmarkSpanCreation(std::move(sampler), state);
}
BENCHMARK(BM_NoopSpanCreation);

Expand Down