@@ -0,0 +1,2797 @@
+/*%0A * Copyright 2017, OpenCensus Authors%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage io.opencensus.contrib.agent.instrumentation;%0A%0Aimport io.grpc.Context;%0Aimport java.util.concurrent.TimeUnit;%0Aimport org.openjdk.jmh.annotations.Benchmark;%0Aimport org.openjdk.jmh.annotations.BenchmarkMode;%0Aimport org.openjdk.jmh.annotations.Fork;%0Aimport org.openjdk.jmh.annotations.Mode;%0Aimport org.openjdk.jmh.annotations.OutputTimeUnit;%0Aimport org.openjdk.jmh.infra.Blackhole;%0A%0A/** Naive benchmarks for automatic context propagation added by %7B@link ThreadInstrumentation%7D.*/%0Apublic class ThreadInstrumentationBenchmark %7B%0A%0A  private static final class MyRunnable implements Runnable %7B%0A%0A    private final Blackhole blackhole;%0A%0A    private MyRunnable(Blackhole blackhole) %7B%0A      this.blackhole = blackhole;%0A    %7D%0A%0A    @Override%0A    public void run() %7B%0A      blackhole.consume(Context.current());%0A    %7D%0A  %7D%0A%0A  /**%0A   * This benchmark attempts to measure the performance without any context propagation.%0A   *%0A   * @param blackhole a %7B@link Blackhole%7D object supplied by JMH%0A   */%0A  @Benchmark%0A  @BenchmarkMode(Mode.AverageTime)%0A  @OutputTimeUnit(TimeUnit.MICROSECONDS)%0A  @Fork%0A  public void none(Blackhole blackhole) throws InterruptedException %7B%0A    Thread t = new Thread(new MyRunnable(blackhole));%0A    t.start();%0A    t.join();%0A  %7D%0A%0A  /**%0A   * This benchmark attempts to measure the performance with manual context propagation.%0A   *%0A   * @param blackhole a %7B@link Blackhole%7D object supplied by JMH%0A   */%0A  @Benchmark%0A  @BenchmarkMode(Mode.AverageTime)%0A  @OutputTimeUnit(TimeUnit.MICROSECONDS)%0A  @Fork%0A  public void manual(Blackhole blackhole) throws InterruptedException %7B%0A    Thread t = new Thread((Context.current().wrap(new MyRunnable(blackhole))));%0A    t.start();%0A    t.join();%0A  %7D%0A%0A  /**%0A   * This benchmark attempts to measure the performance with automatic context propagation.%0A   *%0A   * @param blackhole a %7B@link Blackhole%7D object supplied by JMH%0A   */%0A  @Benchmark%0A  @BenchmarkMode(Mode.AverageTime)%0A  @OutputTimeUnit(TimeUnit.MICROSECONDS)%0A  @Fork(jvmArgsAppend = %22-javaagent:contrib/agent/build/libs/agent.jar%22)%0A  public void automatic(Blackhole blackhole) throws InterruptedException %7B%0A    Thread t = new Thread(new MyRunnable(blackhole));%0A    t.start();%0A    t.join();%0A  %7D%0A%7D%0A

Add a naive JMH benchmark for ThreadInstrumentation. (#523)