Add additional cases for benchmarking.
MODIFY
.gitignore
.gitignore
@@ -52,3 +52,5 @@ Thumbs.db
dd-java-agent/integrations/*/out
dd-trace-examples/*/out
derby.log
+
+!dd-java-agent/benchmark/releases/*.jar

MODIFY
dd-java-agent/benchmark/benchmark.gradle
dd-java-agent/benchmark/benchmark.gradle
@@ -7,6 +7,20 @@ apply from: "${rootDir}/gradle/java.gradle"
dependencies {
jmh project(':dd-trace-annotations')
jmh group: 'net.bytebuddy', name: 'byte-buddy-agent', version: '1.7.6'
+
+ // Add a bunch of dependencies so instrumentation is not disabled.
+ jmh group: 'javax.jms', name: 'javax.jms-api', version: '2.0.1'
+ jmh group: 'javax.servlet', name: 'javax.servlet-api', version: '3.0.1'
+ jmh group: 'org.mongodb', name: 'mongo-java-driver', version: '3.4.2'
+ jmh group: 'org.mongodb', name: 'mongodb-driver-async', version: '3.4.2'
+ jmh(group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.11.119') {
+ exclude(module: 'httpclient')
+ exclude(module: 'jackson-databind')
+ exclude(module: 'jackson-dataformat-cbor')
+ }
+ jmh group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.6.0'
+ jmh group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.3'
+ jmh(group: 'com.datastax.cassandra', name: 'cassandra-driver-core', version: '3.2.0')
}
configurations.testRuntimeClasspath.dependencies.clear()
@@ -15,14 +29,14 @@ configurations.testRuntimeClasspath.dependencies.clear()
jmh {
timeUnit = 'us' // Output time unit. Available time units are: [m, s, ms, us, ns].
benchmarkMode = ['thrpt', 'avgt']
- timeOnIteration = '1s'
- iterations = 1 // Number of measurement iterations to do.
- fork = 2 // How many times to forks a single benchmark. Use 0 to disable forking altogether
+// timeOnIteration = '5s'
+ iterations = 5 // Number of measurement iterations to do.
+ fork = 1 // How many times to forks a single benchmark. Use 0 to disable forking altogether
// jvmArgs = ["-Dasdf=123"]
// jvmArgs = ["-javaagent:${project(':dd-java-agent').shadowJar.archivePath}"]
failOnError = true // Should JMH fail immediately if any benchmark had experienced the unrecoverable error?
- warmup = '2s' // Time to spend at each warmup iteration.
- warmupIterations = 1 // Number of warmup iterations to do.
+// warmup = '2s' // Time to spend at each warmup iteration.
+// warmupIterations = 2 // Number of warmup iterations to do.
// warmupForks = 0 // How many warmup forks to make for a single benchmark. 0 to disable warmup forks.
// profilers = ['stack']
@@ -31,7 +45,7 @@ jmh {
// humanOutputFile = project.file("${project.buildDir}/reports/jmh/human.txt") // human-readable output file
// operationsPerInvocation = 10 // Operations per invocation.
// synchronizeIterations = false // Synchronize iterations?
-// timeout = '1s' // Timeout for benchmark iteration.
+ timeout = '1s' // Timeout for benchmark iteration.
includeTests = false
// Allows to include test sources into generate JMH jar, i.e. use it when benchmarks depend on the test classes.
@@ -46,13 +60,13 @@ task jmhAgent(type: JavaExec, dependsOn: project.tasks.jmhCompileGeneratedClasse
main = "org.openjdk.jmh.Main"
args += ["-tu", "us"]
args += ["-bm", "avgt"]
- args += ["-r", "1s"]
- args += ["-i", "1"]
- args += ["-f", "2"]
+ args += ["-prof", "stack"]
+// args += ["-r", "5s"]
+// args += ["-i", "5"]
+ args += ["-f", "1"]
args += ["-foe", "true"]
- args += ["-w", "2s"]
- args += ["-wi", "1"]
-// jvmArgs = ["-javaagent:${project(':dd-java-agent').shadowJar.archivePath}"]
+// args += ["-w", "2s"]
+// args += ["-wi", "2"]
}
tasks.jmhAgent.dependsOn project(':dd-java-agent').shadowJar

ADD
dd-java-agent/benchmark/releases/dd-java-agent-0.2.10.jar
dd-java-agent/benchmark/releases/dd-java-agent-0.2.10.jar
Binary files /dev/null and b/dd-java-agent/benchmark/releases/dd-java-agent-0.2.10.jar differ

ADD
dd-java-agent/benchmark/releases/dd-java-agent-0.2.2.jar
dd-java-agent/benchmark/releases/dd-java-agent-0.2.2.jar
Binary files /dev/null and b/dd-java-agent/benchmark/releases/dd-java-agent-0.2.2.jar differ

ADD
dd-java-agent/benchmark/releases/dd-java-agent-0.2.4.jar
dd-java-agent/benchmark/releases/dd-java-agent-0.2.4.jar
Binary files /dev/null and b/dd-java-agent/benchmark/releases/dd-java-agent-0.2.4.jar differ

ADD
dd-java-agent/benchmark/releases/dd-java-agent-0.2.6.jar
dd-java-agent/benchmark/releases/dd-java-agent-0.2.6.jar
Binary files /dev/null and b/dd-java-agent/benchmark/releases/dd-java-agent-0.2.6.jar differ

ADD
dd-java-agent/benchmark/releases/dd-java-agent-0.2.7.jar
dd-java-agent/benchmark/releases/dd-java-agent-0.2.7.jar
Binary files /dev/null and b/dd-java-agent/benchmark/releases/dd-java-agent-0.2.7.jar differ

ADD
dd-java-agent/benchmark/releases/dd-java-agent-0.2.8.jar
dd-java-agent/benchmark/releases/dd-java-agent-0.2.8.jar
Binary files /dev/null and b/dd-java-agent/benchmark/releases/dd-java-agent-0.2.8.jar differ

ADD
dd-java-agent/benchmark/releases/dd-java-agent-0.2.9.jar
dd-java-agent/benchmark/releases/dd-java-agent-0.2.9.jar
Binary files /dev/null and b/dd-java-agent/benchmark/releases/dd-java-agent-0.2.9.jar differ

DELETE
dd-java-agent/benchmark/src/jmh/java/com/datadoghq/agent/ClassRetransformingBenchmark.java
-package com.datadoghq.agent;
-
-import com.datadoghq.trace.Trace;
-import java.lang.instrument.Instrumentation;
-import java.lang.instrument.UnmodifiableClassException;
-import net.bytebuddy.agent.ByteBuddyAgent;
-import org.openjdk.jmh.annotations.Benchmark;
-import org.openjdk.jmh.annotations.Scope;
-import org.openjdk.jmh.annotations.State;
-
-public class ClassRetransformingBenchmark {
-
- @State(Scope.Benchmark)
- public static class BenchmarkState {
- private final Instrumentation inst = ByteBuddyAgent.install();
- }
-
- @Benchmark
- public void testIgnoredRetransform(final BenchmarkState state) throws UnmodifiableClassException {
- state.inst.retransformClasses(Object.class);
- }
-
- @Benchmark
- public void testSimpleRetransform(final BenchmarkState state) throws UnmodifiableClassException {
- state.inst.retransformClasses(SimpleClass.class);
- }
-
- @Benchmark
- public void testDeepRetransform(final BenchmarkState state) throws UnmodifiableClassException {
- state.inst.retransformClasses(DeepClass.class);
- }
-
- public static class SimpleClass {
- @Trace
- public void aMethodToTrace() {}
- }
-
- public static interface A {
- @Trace
- void interfaceTrace();
- }
-
- public static interface B extends A {
- void something();
- }
-
- public static interface C extends B {
- void somethingElse();
- }
-
- public static class DeepClass implements C {
-
- @Override
- public void interfaceTrace() {}
-
- @Override
- public void something() {}
-
- @Override
- public void somethingElse() {}
- }
-}

ADD
dd-java-agent/benchmark/src/jmh/java/com/datadoghq/benchmark/ClassRetransformingBenchmark.java
+package com.datadoghq.benchmark;
+
+import com.datadoghq.trace.Trace;
+import java.lang.instrument.Instrumentation;
+import java.lang.instrument.UnmodifiableClassException;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.nio.file.Paths;
+import net.bytebuddy.agent.ByteBuddyAgent;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.TearDown;
+
+public class ClassRetransformingBenchmark {
+ public static final String BENCHMARK_HOME =
+ Paths.get(".").toAbsolutePath().normalize().toString();
+
+ static {
+ if (!BENCHMARK_HOME.endsWith("benchmark")) {
+ throw new IllegalArgumentException("Invalid Home directory: " + BENCHMARK_HOME);
+ }
+ }
+
+ @State(Scope.Benchmark)
+ public static class BenchmarkState {
+ private final Instrumentation inst = ByteBuddyAgent.install();
+
+ @Setup
+ public void initializeInstrumentation() {
+ try {
+ final Class<?> manager = Class.forName("com.datadoghq.agent.InstrumentationRulesManager");
+ final Method registerClassLoad = manager.getMethod("registerClassLoad");
+ registerClassLoad.invoke(null);
+ } catch (final Exception e) {
+ }
+ }
+
+ @TearDown
+ public void stopAgent() {
+ try {
+ final Class<?> gt = Class.forName("io.opentracing.util.GlobalTracer");
+ final Field tracerField = gt.getDeclaredField("tracer");
+ tracerField.setAccessible(true);
+ final Object tracer = tracerField.get(null);
+ final Method close = tracer.getClass().getMethod("close");
+ close.invoke(tracer);
+ } catch (final Exception e) {
+ }
+ }
+ }
+
+ @Benchmark
+ public void testIgnoredRetransform(final BenchmarkState state) throws UnmodifiableClassException {
+ state.inst.retransformClasses(Object.class);
+ }
+
+ @Benchmark
+ public void testSimpleRetransform(final BenchmarkState state) throws UnmodifiableClassException {
+ state.inst.retransformClasses(SimpleClass.class);
+ }
+
+ @Benchmark
+ public void testDeepRetransform(final BenchmarkState state) throws UnmodifiableClassException {
+ state.inst.retransformClasses(DeepClass.class);
+ }
+
+ @Fork(jvmArgsAppend = "-javaagent:releases/dd-java-agent-0.2.2.jar")
+ public static class WithAgent022 extends ClassRetransformingBenchmark {}
+
+ @Fork(jvmArgsAppend = "-javaagent:releases/dd-java-agent-0.2.4.jar")
+ public static class WithAgent024 extends ClassRetransformingBenchmark {}
+
+ @Fork(jvmArgsAppend = "-javaagent:releases/dd-java-agent-0.2.6.jar")
+ public static class WithAgent026 extends ClassRetransformingBenchmark {}
+
+ @Fork(jvmArgsAppend = "-javaagent:releases/dd-java-agent-0.2.7.jar")
+ public static class WithAgent027 extends ClassRetransformingBenchmark {}
+
+ @Fork(jvmArgsAppend = "-javaagent:releases/dd-java-agent-0.2.8.jar")
+ public static class WithAgent028 extends ClassRetransformingBenchmark {}
+
+ @Fork(jvmArgsAppend = "-javaagent:releases/dd-java-agent-0.2.9.jar")
+ public static class WithAgent029 extends ClassRetransformingBenchmark {}
+
+ @Fork(jvmArgsAppend = "-javaagent:releases/dd-java-agent-0.2.10.jar")
+ public static class WithAgent0210 extends ClassRetransformingBenchmark {}
+
+ @Fork(jvmArgsAppend = "-javaagent:../build/libs/dd-java-agent.jar")
+ public static class WithAgent extends ClassRetransformingBenchmark {}
+
+ public static class SimpleClass {
+ @Trace
+ public void aMethodToTrace() {}
+ }
+
+ public static interface A {
+ @Trace
+ void interfaceTrace();
+ }
+
+ public static interface B extends A {
+ void something();
+ }
+
+ public static interface C extends B {
+ void somethingElse();
+ }
+
+ public static class DeepClass implements C {
+
+ @Override
+ public void interfaceTrace() {}
+
+ @Override
+ public void something() {}
+
+ @Override
+ public void somethingElse() {}
+ }
+}

ADD
dd-java-agent/benchmark/src/jmh/resources/dd-trace.yaml
+enableCustomAnnotationTracingOver: ["com.datadoghq.benchmark"]

Add additional cases for benchmarking.