|
19 | 19 | import org.openjdk.jmh.annotations.TearDown; |
20 | 20 |
|
21 | 21 | /** |
22 | | - * Compares lambda {@code Runnable} allocation and submission with no agent, wrapping, and field |
23 | | - * injection. |
| 22 | + * Compares lambda {@code Runnable} allocation, execution, and submission with no agent, wrapping, |
| 23 | + * and field injection. |
24 | 24 | * |
25 | 25 | * <ul> |
26 | 26 | * <li>{@link NoAgent} — baseline, no agent. |
|
30 | 30 | * field-injected, so no wrapper is allocated and identity is preserved. |
31 | 31 | * </ul> |
32 | 32 | * |
33 | | - * <p>With the GC profiler, {@code allocateCapturingRunnable} isolates the injected field's object |
34 | | - * size cost while {@code submitLambda} includes the wrapper allocation tradeoff. Run with: |
| 33 | + * <p>{@code runUntracedLambda} isolates the advice cost when no context was attached. With the GC |
| 34 | + * profiler, {@code allocateCapturingRunnable} isolates the injected field's object size cost while |
| 35 | + * {@code submitLambda} includes the wrapper allocation tradeoff. Run with: |
35 | 36 | * |
36 | 37 | * <pre>{@code |
37 | 38 | * ./gradlew :dd-java-agent:benchmark:jmh \ |
@@ -82,12 +83,30 @@ public static class CapturingLambdaState { |
82 | 83 | public void run() {} |
83 | 84 | } |
84 | 85 |
|
| 86 | + @State(Scope.Thread) |
| 87 | + public static class DirectRunState { |
| 88 | + Runnable runnable; |
| 89 | + int executions; |
| 90 | + |
| 91 | + @Setup |
| 92 | + public void setup() { |
| 93 | + runnable = () -> executions++; |
| 94 | + } |
| 95 | + } |
| 96 | + |
85 | 97 | /** Allocates an untraced capturing Runnable. */ |
86 | 98 | @Benchmark |
87 | 99 | public Runnable allocateCapturingRunnable(CapturingLambdaState state) { |
88 | 100 | return state::run; |
89 | 101 | } |
90 | 102 |
|
| 103 | + /** Executes an already-created lambda Runnable without an active trace. */ |
| 104 | + @Benchmark |
| 105 | + public int runUntracedLambda(DirectRunState state) { |
| 106 | + state.runnable.run(); |
| 107 | + return state.executions; |
| 108 | + } |
| 109 | + |
91 | 110 | /** Submit a lambda Runnable to the executor under an active trace, and wait for it to run. */ |
92 | 111 | @Benchmark |
93 | 112 | public void submitLambda(ExecutorState state) throws InterruptedException { |
@@ -134,9 +153,9 @@ private static Object supplyTarget() { |
134 | 153 | @Fork |
135 | 154 | public static class NoAgent extends LambdaExecutorBenchmark {} |
136 | 155 |
|
137 | | - @Fork(jvmArgsAppend = AGENT) |
| 156 | + @Fork(jvmArgsAppend = {AGENT, "-Ddd.trace.lambda.enabled=false"}) |
138 | 157 | public static class AgentLambdaOff extends LambdaExecutorBenchmark {} |
139 | 158 |
|
140 | | - @Fork(jvmArgsAppend = {AGENT, "-Ddd.trace.lambda.enabled=true"}) |
| 159 | + @Fork(jvmArgsAppend = AGENT) |
141 | 160 | public static class AgentLambdaOn extends LambdaExecutorBenchmark {} |
142 | 161 | } |
0 commit comments