|
| 1 | +// Copyright 2019, OpenCensus Authors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#include <string> |
| 16 | +#include <vector> |
| 17 | + |
| 18 | +#include "benchmark/benchmark.h" |
| 19 | +#include "opencensus/trace/sampler.h" |
| 20 | +#include "opencensus/trace/span.h" |
| 21 | +#include "opencensus/trace/span_context.h" |
| 22 | +#include "opencensus/trace/span_id.h" |
| 23 | +#include "opencensus/trace/trace_id.h" |
| 24 | + |
| 25 | +namespace opencensus { |
| 26 | +namespace trace { |
| 27 | +namespace { |
| 28 | + |
| 29 | +void BM_ProbabilitySampler(benchmark::State& state) { |
| 30 | + // Unused: |
| 31 | + SpanContext parent_context; |
| 32 | + bool has_remote_parent = true; |
| 33 | + SpanId span_id; |
| 34 | + std::string name = "MyName"; |
| 35 | + std::vector<Span*> parent_links; |
| 36 | + // Used: |
| 37 | + constexpr uint8_t trace_id_buf[TraceId::kSize] = { |
| 38 | + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; |
| 39 | + TraceId trace_id(trace_id_buf); |
| 40 | + static ProbabilitySampler sampler(.5); |
| 41 | + |
| 42 | + while (state.KeepRunning()) { |
| 43 | + sampler.ShouldSample(&parent_context, has_remote_parent, trace_id, span_id, |
| 44 | + name, parent_links); |
| 45 | + } |
| 46 | +} |
| 47 | +BENCHMARK(BM_ProbabilitySampler); |
| 48 | + |
| 49 | +} // namespace |
| 50 | +} // namespace trace |
| 51 | +} // namespace opencensus |
| 52 | + |
| 53 | +BENCHMARK_MAIN(); |
0 commit comments