From 7c34d16a9ab04e34f99ced22a26323742ec45ca3 Mon Sep 17 00:00:00 2001 From: Jack Berg Date: Wed, 28 Jan 2026 13:36:53 -0600 Subject: [PATCH] Delete obsolete exception serialization benchmarks --- .../sdk/trace/ExceptionBenchmark.java | 77 ------------------ .../sdk/trace/PrintThrowableBenchmark.java | 80 ------------------- 2 files changed, 157 deletions(-) delete mode 100644 sdk/trace/src/jmh/java/io/opentelemetry/sdk/trace/ExceptionBenchmark.java delete mode 100644 sdk/trace/src/jmh/java/io/opentelemetry/sdk/trace/PrintThrowableBenchmark.java diff --git a/sdk/trace/src/jmh/java/io/opentelemetry/sdk/trace/ExceptionBenchmark.java b/sdk/trace/src/jmh/java/io/opentelemetry/sdk/trace/ExceptionBenchmark.java deleted file mode 100644 index 7dd1298345b..00000000000 --- a/sdk/trace/src/jmh/java/io/opentelemetry/sdk/trace/ExceptionBenchmark.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.sdk.trace; - -import io.opentelemetry.api.trace.Span; -import io.opentelemetry.api.trace.SpanBuilder; -import io.opentelemetry.api.trace.Tracer; -import io.opentelemetry.sdk.trace.samplers.Sampler; -import java.util.concurrent.TimeUnit; -import org.openjdk.jmh.annotations.Benchmark; -import org.openjdk.jmh.annotations.BenchmarkMode; -import org.openjdk.jmh.annotations.Fork; -import org.openjdk.jmh.annotations.Level; -import org.openjdk.jmh.annotations.Measurement; -import org.openjdk.jmh.annotations.Mode; -import org.openjdk.jmh.annotations.OutputTimeUnit; -import org.openjdk.jmh.annotations.Scope; -import org.openjdk.jmh.annotations.Setup; -import org.openjdk.jmh.annotations.State; -import org.openjdk.jmh.annotations.Threads; -import org.openjdk.jmh.annotations.Warmup; - -@State(Scope.Benchmark) -public class ExceptionBenchmark { - @SuppressWarnings("NonFinalStaticField") - private static SpanBuilder spanBuilder; - - @Setup(Level.Trial) - public final void setup() { - SdkTracerProvider tracerProvider = - SdkTracerProvider.builder().setSampler(Sampler.alwaysOn()).build(); - - Tracer tracer = tracerProvider.get("benchmarkTracer"); - spanBuilder = tracer.spanBuilder("benchmarkSpanBuilder"); - } - - @Benchmark - @Threads(value = 1) - @Fork(1) - @Warmup(iterations = 5, time = 1) - @Measurement(iterations = 10, time = 1) - @OutputTimeUnit(TimeUnit.NANOSECONDS) - @BenchmarkMode(Mode.AverageTime) - public Span createSpan() { - Span span = spanBuilder.startSpan(); - span.end(); - return span; - } - - @Benchmark - @Threads(value = 1) - @Fork(1) - @Warmup(iterations = 5, time = 1) - @Measurement(iterations = 10, time = 1) - @OutputTimeUnit(TimeUnit.NANOSECONDS) - @BenchmarkMode(Mode.AverageTime) - public Span createSpanAndRecordException() { - Span span = spanBuilder.startSpan(); - span.recordException(new RuntimeException()); - span.end(); - return span; - } - - @Benchmark - @Threads(value = 1) - @Fork(1) - @Warmup(iterations = 5, time = 1) - @Measurement(iterations = 10, time = 1) - @OutputTimeUnit(TimeUnit.NANOSECONDS) - @BenchmarkMode(Mode.AverageTime) - public RuntimeException createException() { - return new RuntimeException(); - } -} diff --git a/sdk/trace/src/jmh/java/io/opentelemetry/sdk/trace/PrintThrowableBenchmark.java b/sdk/trace/src/jmh/java/io/opentelemetry/sdk/trace/PrintThrowableBenchmark.java deleted file mode 100644 index 153581fe733..00000000000 --- a/sdk/trace/src/jmh/java/io/opentelemetry/sdk/trace/PrintThrowableBenchmark.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.sdk.trace; - -import com.google.common.io.CharStreams; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.nio.charset.StandardCharsets; -import java.util.concurrent.TimeUnit; -import org.openjdk.jmh.annotations.Benchmark; -import org.openjdk.jmh.annotations.Fork; -import org.openjdk.jmh.annotations.Measurement; -import org.openjdk.jmh.annotations.OutputTimeUnit; -import org.openjdk.jmh.annotations.Threads; -import org.openjdk.jmh.annotations.Warmup; - -@Threads(value = 1) -@Fork(3) -@Warmup(iterations = 10, time = 1) -@Measurement(iterations = 20, time = 1) -@OutputTimeUnit(TimeUnit.MILLISECONDS) -public class PrintThrowableBenchmark { - - private static final int THROWABLE_SIZE = 50; - - private static final Throwable THROWABLE; - - static { - Throwable throwable = null; - try { - throwAfter(THROWABLE_SIZE); - } catch (Throwable t) { - throwable = t; - } - if (throwable == null) { - throw new AssertionError(); - } - THROWABLE = throwable; - } - - private static void throwAfter(int count) { - if (count == THROWABLE_SIZE) { - throw new AssertionError("threw"); - } else { - throwAfter(count + 1); - } - } - - /** Measures performance of {@link StringBuilder} + Guava {@link CharStreams}. */ - @Benchmark - public String normalPrintWriter() { - StringBuilder sb = new StringBuilder(); - PrintWriter writer = new PrintWriter(CharStreams.asWriter(sb)); - THROWABLE.printStackTrace(writer); - return sb.toString(); - } - - /** Measures performance of JDK {@link StringWriter}. */ - @Benchmark - public String stringWriter() { - StringWriter sw = new StringWriter(); - PrintWriter writer = new PrintWriter(sw); - THROWABLE.printStackTrace(writer); - return sw.toString(); - } - - /** Measures performance of a {@link PrintStream}. */ - @Benchmark - public String printStream() throws Exception { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - PrintStream stream = new PrintStream(bos); - THROWABLE.printStackTrace(stream); - return bos.toString(StandardCharsets.UTF_8.name()); - } -}