aboutsummaryrefslogtreecommitdiff
path: root/benchmarks/src/jmh/java/io/opencensus
diff options
context:
space:
mode:
authorBogdan Drutu <bdrutu@google.com>2017-06-06 13:56:55 -0700
committerGitHub <noreply@github.com>2017-06-06 13:56:55 -0700
commit80ec0c120bb133b3d3747406be7e4c543b9e0446 (patch)
tree94d30b9612fd44408026455597ac7c76492536b2 /benchmarks/src/jmh/java/io/opencensus
parent84d0f46e88faa89c0d822a73a7a610b9ac1bc471 (diff)
downloadopencensus-java-80ec0c120bb133b3d3747406be7e4c543b9e0446.tar.gz
Move internal & common & trace to the new package io.opencensus (#339)
Diffstat (limited to 'benchmarks/src/jmh/java/io/opencensus')
-rw-r--r--benchmarks/src/jmh/java/io/opencensus/trace/BinaryPropagationHandlerImplBenchmark.java75
-rw-r--r--benchmarks/src/jmh/java/io/opencensus/trace/RecordTraceEventsNonSampledSpanBenchmark.java83
-rw-r--r--benchmarks/src/jmh/java/io/opencensus/trace/RecordTraceEventsSampledSpanBenchmark.java83
-rw-r--r--benchmarks/src/jmh/java/io/opencensus/trace/StartEndSpanBenchmark.java127
4 files changed, 368 insertions, 0 deletions
diff --git a/benchmarks/src/jmh/java/io/opencensus/trace/BinaryPropagationHandlerImplBenchmark.java b/benchmarks/src/jmh/java/io/opencensus/trace/BinaryPropagationHandlerImplBenchmark.java
new file mode 100644
index 00000000..85302d25
--- /dev/null
+++ b/benchmarks/src/jmh/java/io/opencensus/trace/BinaryPropagationHandlerImplBenchmark.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2017, Google Inc.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.opencensus.trace;
+
+import java.text.ParseException;
+import java.util.concurrent.TimeUnit;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.State;
+
+/** Benchmarks for {@link BinaryPropagationHandlerImpl}. */
+@State(Scope.Benchmark)
+public class BinaryPropagationHandlerImplBenchmark {
+ private static final byte[] traceIdBytes =
+ new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'a'};
+ private static final TraceId traceId = TraceId.fromBytes(traceIdBytes);
+ private static final byte[] spanIdBytes = new byte[] {(byte) 0xFF, 0, 0, 0, 0, 0, 0, 0};
+ private static final SpanId spanId = SpanId.fromBytes(spanIdBytes);
+ private static final byte[] traceOptionsBytes = new byte[] {1};
+ private static final TraceOptions traceOptions = TraceOptions.fromBytes(traceOptionsBytes);
+ private static final SpanContext spanContext = SpanContext.create(traceId, spanId, traceOptions);
+ private static final BinaryPropagationHandler binaryPropagationHandler =
+ new BinaryPropagationHandlerImpl();
+ private static final byte[] spanContextBinary =
+ binaryPropagationHandler.toBinaryValue(spanContext);
+
+ /**
+ * This benchmark attempts to measure performance of {@link
+ * BinaryPropagationHandlerImpl#toBinaryValue(SpanContext)}.
+ */
+ @Benchmark
+ @BenchmarkMode(Mode.SampleTime)
+ @OutputTimeUnit(TimeUnit.NANOSECONDS)
+ public byte[] toBinaryValueSpanContext() {
+ return binaryPropagationHandler.toBinaryValue(spanContext);
+ }
+
+ /**
+ * This benchmark attempts to measure performance of {@link
+ * BinaryPropagationHandlerImpl#fromBinaryValue(byte[])}.
+ */
+ @Benchmark
+ @BenchmarkMode(Mode.SampleTime)
+ @OutputTimeUnit(TimeUnit.NANOSECONDS)
+ public SpanContext fromBinaryValueSpanContext() throws ParseException {
+ return binaryPropagationHandler.fromBinaryValue(spanContextBinary);
+ }
+
+ /**
+ * This benchmark attempts to measure performance of {@link
+ * BinaryPropagationHandlerImpl#toBinaryValue(SpanContext)} then {@link
+ * BinaryPropagationHandlerImpl#fromBinaryValue(byte[])}.
+ */
+ @Benchmark
+ @BenchmarkMode(Mode.SampleTime)
+ @OutputTimeUnit(TimeUnit.NANOSECONDS)
+ public SpanContext toFromBinarySpanContext() throws ParseException {
+ return binaryPropagationHandler.fromBinaryValue(
+ binaryPropagationHandler.toBinaryValue(spanContext));
+ }
+}
diff --git a/benchmarks/src/jmh/java/io/opencensus/trace/RecordTraceEventsNonSampledSpanBenchmark.java b/benchmarks/src/jmh/java/io/opencensus/trace/RecordTraceEventsNonSampledSpanBenchmark.java
new file mode 100644
index 00000000..0c3daa87
--- /dev/null
+++ b/benchmarks/src/jmh/java/io/opencensus/trace/RecordTraceEventsNonSampledSpanBenchmark.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2017, Google Inc.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.opencensus.trace;
+
+import java.util.HashMap;
+import java.util.concurrent.TimeUnit;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.TearDown;
+
+/** Benchmarks for {@link SpanImpl} to record trace events. */
+@State(Scope.Benchmark)
+public class RecordTraceEventsNonSampledSpanBenchmark {
+ private static final Tracer tracer = Tracing.getTracer();
+ private static final String SPAN_NAME = "MySpanName";
+ private static final String ANNOTATION_DESCRIPTION = "MyAnnotation";
+ private static final String ATTRIBUTE_KEY = "MyAttributeKey";
+ private static final String ATTRIBUTE_VALUE = "MyAttributeValue";
+ private Span linkedSpan =
+ tracer.spanBuilder(SPAN_NAME).becomeRoot().setSampler(Samplers.neverSample()).startSpan();
+ private Span span =
+ tracer.spanBuilder(SPAN_NAME).becomeRoot().setSampler(Samplers.neverSample()).startSpan();
+
+ /** TearDown method. */
+ @TearDown
+ public void doTearDown() {
+ span.end();
+ linkedSpan.end();
+ }
+
+ /** This benchmark attempts to measure performance of adding an attribute to the span. */
+ @Benchmark
+ @BenchmarkMode(Mode.SampleTime)
+ @OutputTimeUnit(TimeUnit.NANOSECONDS)
+ public Span addAttributes() {
+ HashMap<String, AttributeValue> attributes = new HashMap<String, AttributeValue>();
+ attributes.put(ATTRIBUTE_KEY, AttributeValue.stringAttributeValue(ATTRIBUTE_VALUE));
+ span.addAttributes(attributes);
+ return span;
+ }
+
+ /** This benchmark attempts to measure performance of adding an annotation to the span. */
+ @Benchmark
+ @BenchmarkMode(Mode.SampleTime)
+ @OutputTimeUnit(TimeUnit.NANOSECONDS)
+ public Span addAnnotation() {
+ span.addAnnotation(ANNOTATION_DESCRIPTION);
+ return span;
+ }
+
+ /** This benchmark attempts to measure performance of adding a network event to the span. */
+ @Benchmark
+ @BenchmarkMode(Mode.SampleTime)
+ @OutputTimeUnit(TimeUnit.NANOSECONDS)
+ public Span addNetworkEvent() {
+ span.addNetworkEvent(NetworkEvent.builder(NetworkEvent.Type.RECV, 1).setMessageSize(3).build());
+ return span;
+ }
+
+ /** This benchmark attempts to measure performance of adding a link to the span. */
+ @Benchmark
+ @BenchmarkMode(Mode.SampleTime)
+ @OutputTimeUnit(TimeUnit.NANOSECONDS)
+ public Span addLink() {
+ span.addLink(Link.fromSpanContext(linkedSpan.getContext(), Link.Type.PARENT));
+ return span;
+ }
+}
diff --git a/benchmarks/src/jmh/java/io/opencensus/trace/RecordTraceEventsSampledSpanBenchmark.java b/benchmarks/src/jmh/java/io/opencensus/trace/RecordTraceEventsSampledSpanBenchmark.java
new file mode 100644
index 00000000..78a587f4
--- /dev/null
+++ b/benchmarks/src/jmh/java/io/opencensus/trace/RecordTraceEventsSampledSpanBenchmark.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2017, Google Inc.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.opencensus.trace;
+
+import java.util.HashMap;
+import java.util.concurrent.TimeUnit;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.TearDown;
+
+/** Benchmarks for {@link SpanImpl} to record trace events. */
+@State(Scope.Benchmark)
+public class RecordTraceEventsSampledSpanBenchmark {
+ private static final Tracer tracer = Tracing.getTracer();
+ private static final String SPAN_NAME = "MySpanName";
+ private static final String ANNOTATION_DESCRIPTION = "MyAnnotation";
+ private static final String ATTRIBUTE_KEY = "MyAttributeKey";
+ private static final String ATTRIBUTE_VALUE = "MyAttributeValue";
+ private Span linkedSpan =
+ tracer.spanBuilder(SPAN_NAME).becomeRoot().setSampler(Samplers.alwaysSample()).startSpan();
+ private Span span =
+ tracer.spanBuilder(SPAN_NAME).becomeRoot().setSampler(Samplers.alwaysSample()).startSpan();
+
+ /** TearDown method. */
+ @TearDown
+ public void doTearDown() {
+ span.end();
+ linkedSpan.end();
+ }
+
+ /** This benchmark attempts to measure performance of adding an attribute to the span. */
+ @Benchmark
+ @BenchmarkMode(Mode.SampleTime)
+ @OutputTimeUnit(TimeUnit.NANOSECONDS)
+ public Span addAttributes() {
+ HashMap<String, AttributeValue> attributes = new HashMap<String, AttributeValue>();
+ attributes.put(ATTRIBUTE_KEY, AttributeValue.stringAttributeValue(ATTRIBUTE_VALUE));
+ span.addAttributes(attributes);
+ return span;
+ }
+
+ /** This benchmark attempts to measure performance of adding an annotation to the span. */
+ @Benchmark
+ @BenchmarkMode(Mode.SampleTime)
+ @OutputTimeUnit(TimeUnit.NANOSECONDS)
+ public Span addAnnotation() {
+ span.addAnnotation(ANNOTATION_DESCRIPTION);
+ return span;
+ }
+
+ /** This benchmark attempts to measure performance of adding a network event to the span. */
+ @Benchmark
+ @BenchmarkMode(Mode.SampleTime)
+ @OutputTimeUnit(TimeUnit.NANOSECONDS)
+ public Span addNetworkEvent() {
+ span.addNetworkEvent(NetworkEvent.builder(NetworkEvent.Type.RECV, 1).setMessageSize(3).build());
+ return span;
+ }
+
+ /** This benchmark attempts to measure performance of adding a link to the span. */
+ @Benchmark
+ @BenchmarkMode(Mode.SampleTime)
+ @OutputTimeUnit(TimeUnit.NANOSECONDS)
+ public Span addLink() {
+ span.addLink(Link.fromSpanContext(linkedSpan.getContext(), Link.Type.PARENT));
+ return span;
+ }
+}
diff --git a/benchmarks/src/jmh/java/io/opencensus/trace/StartEndSpanBenchmark.java b/benchmarks/src/jmh/java/io/opencensus/trace/StartEndSpanBenchmark.java
new file mode 100644
index 00000000..9a51ffbe
--- /dev/null
+++ b/benchmarks/src/jmh/java/io/opencensus/trace/StartEndSpanBenchmark.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright 2017, Google Inc.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.opencensus.trace;
+
+import java.util.concurrent.TimeUnit;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.TearDown;
+
+/** Benchmarks for {@link SpanFactoryImpl} and {@link SpanImpl}. */
+@State(Scope.Benchmark)
+public class StartEndSpanBenchmark {
+ private static final Tracer tracer = Tracing.getTracer();
+ private static final String SPAN_NAME = "MySpanName";
+ private Span rootSpan =
+ tracer.spanBuilder(SPAN_NAME).becomeRoot().setSampler(Samplers.neverSample()).startSpan();
+
+ @TearDown
+ public void doTearDown() {
+ rootSpan.end();
+ }
+
+ /**
+ * This benchmark attempts to measure performance of start/end for a non-sampled root {@code
+ * Span}.
+ */
+ @Benchmark
+ @BenchmarkMode(Mode.SampleTime)
+ @OutputTimeUnit(TimeUnit.NANOSECONDS)
+ public Span startEndNonSampledRootSpan() {
+ Span span =
+ tracer.spanBuilder(SPAN_NAME).becomeRoot().setSampler(Samplers.neverSample()).startSpan();
+ span.end();
+ return span;
+ }
+
+ /**
+ * This benchmark attempts to measure performance of start/end for a root {@code Span} with record
+ * events option.
+ */
+ @Benchmark
+ @BenchmarkMode(Mode.SampleTime)
+ @OutputTimeUnit(TimeUnit.NANOSECONDS)
+ public Span startEndRecordEventsRootSpan() {
+ Span span =
+ tracer
+ .spanBuilder(SPAN_NAME)
+ .becomeRoot()
+ .setSampler(Samplers.neverSample())
+ .setRecordEvents(true)
+ .startSpan();
+ span.end();
+ return span;
+ }
+
+ /**
+ * This benchmark attempts to measure performance of start/end for a sampled root {@code Span}.
+ */
+ @Benchmark
+ @BenchmarkMode(Mode.SampleTime)
+ @OutputTimeUnit(TimeUnit.NANOSECONDS)
+ public Span startEndSampledRootSpan() {
+ Span span = tracer.spanBuilder(SPAN_NAME).setSampler(Samplers.alwaysSample()).startSpan();
+ span.end();
+ return span;
+ }
+
+ /**
+ * This benchmark attempts to measure performance of start/end for a non-sampled child {@code
+ * Span}.
+ */
+ @Benchmark
+ @BenchmarkMode(Mode.SampleTime)
+ @OutputTimeUnit(TimeUnit.NANOSECONDS)
+ public Span startEndNonSampledChildSpan() {
+ Span span =
+ tracer.spanBuilder(rootSpan, SPAN_NAME).setSampler(Samplers.neverSample()).startSpan();
+ span.end();
+ return span;
+ }
+
+ /**
+ * This benchmark attempts to measure performance of start/end for a child {@code Span} with
+ * record events option.
+ */
+ @Benchmark
+ @BenchmarkMode(Mode.SampleTime)
+ @OutputTimeUnit(TimeUnit.NANOSECONDS)
+ public Span startEndRecordEventsChildSpan() {
+ Span span =
+ tracer
+ .spanBuilder(rootSpan, SPAN_NAME)
+ .setSampler(Samplers.neverSample())
+ .setRecordEvents(true)
+ .startSpan();
+ span.end();
+ return span;
+ }
+
+ /**
+ * This benchmark attempts to measure performance of start/end for a sampled child {@code Span}.
+ */
+ @Benchmark
+ @BenchmarkMode(Mode.SampleTime)
+ @OutputTimeUnit(TimeUnit.NANOSECONDS)
+ public Span startEndSampledChildSpan() {
+ Span span =
+ tracer.spanBuilder(rootSpan, SPAN_NAME).setSampler(Samplers.alwaysSample()).startSpan();
+ span.end();
+ return span;
+ }
+}