|
| 1 | +package com.datadoghq.profiler.stresstest.scenarios; |
| 2 | + |
| 3 | +import com.datadoghq.profiler.JavaProfiler; |
| 4 | +import com.datadoghq.profiler.stresstest.Configuration; |
| 5 | +import org.openjdk.jmh.annotations.Benchmark; |
| 6 | +import org.openjdk.jmh.annotations.BenchmarkMode; |
| 7 | +import org.openjdk.jmh.annotations.Fork; |
| 8 | +import org.openjdk.jmh.annotations.Level; |
| 9 | +import org.openjdk.jmh.annotations.Measurement; |
| 10 | +import org.openjdk.jmh.annotations.Mode; |
| 11 | +import org.openjdk.jmh.annotations.OutputTimeUnit; |
| 12 | +import org.openjdk.jmh.annotations.Param; |
| 13 | +import org.openjdk.jmh.annotations.Scope; |
| 14 | +import org.openjdk.jmh.annotations.Setup; |
| 15 | +import org.openjdk.jmh.annotations.State; |
| 16 | +import org.openjdk.jmh.annotations.TearDown; |
| 17 | +import org.openjdk.jmh.annotations.Threads; |
| 18 | +import org.openjdk.jmh.annotations.Warmup; |
| 19 | +import org.openjdk.jmh.infra.Blackhole; |
| 20 | + |
| 21 | +import java.io.FileWriter; |
| 22 | +import java.io.IOException; |
| 23 | +import java.io.PrintWriter; |
| 24 | +import java.util.concurrent.CountDownLatch; |
| 25 | +import java.util.concurrent.ExecutorService; |
| 26 | +import java.util.concurrent.Executors; |
| 27 | +import java.util.concurrent.TimeUnit; |
| 28 | +import java.util.concurrent.atomic.AtomicBoolean; |
| 29 | +import java.util.concurrent.atomic.AtomicIntegerArray; |
| 30 | +import java.util.concurrent.atomic.AtomicLong; |
| 31 | +import java.util.stream.IntStream; |
| 32 | + |
| 33 | +@State(Scope.Benchmark) |
| 34 | +public class ThreadFilter2Benchmark extends Configuration { |
| 35 | + private JavaProfiler profiler; |
| 36 | + |
| 37 | + @Param(BASE_COMMAND + ",filter=1") |
| 38 | + public String command; |
| 39 | + |
| 40 | + @Param("true") |
| 41 | + public String skipResults; |
| 42 | + |
| 43 | + @Setup(Level.Trial) |
| 44 | + public void setup() throws IOException { |
| 45 | + profiler = JavaProfiler.getInstance(); |
| 46 | + } |
| 47 | + |
| 48 | + @Benchmark |
| 49 | + @BenchmarkMode(Mode.Throughput) |
| 50 | + @Fork(value = 3, warmups = 3) |
| 51 | + @Warmup(iterations = 5) |
| 52 | + @Measurement(iterations = 8) |
| 53 | + @Threads(1) |
| 54 | + @OutputTimeUnit(TimeUnit.MILLISECONDS) |
| 55 | + public void threadFilterStress01() throws InterruptedException { |
| 56 | + profiler.addThread(); |
| 57 | + // Simulate per-thread work |
| 58 | + Blackhole.consumeCPU(7); |
| 59 | + profiler.removeThread(); |
| 60 | + } |
| 61 | + |
| 62 | + @Benchmark |
| 63 | + @BenchmarkMode(Mode.Throughput) |
| 64 | + @Fork(value = 3, warmups = 3) |
| 65 | + @Warmup(iterations = 5) |
| 66 | + @Measurement(iterations = 8) |
| 67 | + @Threads(2) |
| 68 | + @OutputTimeUnit(TimeUnit.MILLISECONDS) |
| 69 | + public void threadFilterStress02() throws InterruptedException { |
| 70 | + profiler.addThread(); |
| 71 | + // Simulate per-thread work |
| 72 | + Blackhole.consumeCPU(7); |
| 73 | + profiler.removeThread(); |
| 74 | + } |
| 75 | + |
| 76 | + @Benchmark |
| 77 | + @BenchmarkMode(Mode.Throughput) |
| 78 | + @Fork(value = 3, warmups = 3) |
| 79 | + @Warmup(iterations = 5) |
| 80 | + @Measurement(iterations = 8) |
| 81 | + @Threads(4) |
| 82 | + @OutputTimeUnit(TimeUnit.MILLISECONDS) |
| 83 | + public void threadFilterStress04() throws InterruptedException { |
| 84 | + profiler.addThread(); |
| 85 | + // Simulate per-thread work |
| 86 | + Blackhole.consumeCPU(7); |
| 87 | + profiler.removeThread(); |
| 88 | + } |
| 89 | + |
| 90 | + @Benchmark |
| 91 | + @BenchmarkMode(Mode.Throughput) |
| 92 | + @Fork(value = 3, warmups = 3) |
| 93 | + @Warmup(iterations = 5) |
| 94 | + @Measurement(iterations = 8) |
| 95 | + @Threads(8) |
| 96 | + @OutputTimeUnit(TimeUnit.MILLISECONDS) |
| 97 | + public void threadFilterStress08() throws InterruptedException { |
| 98 | + profiler.addThread(); |
| 99 | + // Simulate per-thread work |
| 100 | + Blackhole.consumeCPU(7); |
| 101 | + profiler.removeThread(); |
| 102 | + } |
| 103 | + |
| 104 | + @Benchmark |
| 105 | + @BenchmarkMode(Mode.Throughput) |
| 106 | + @Fork(value = 3, warmups = 3) |
| 107 | + @Warmup(iterations = 5) |
| 108 | + @Measurement(iterations = 8) |
| 109 | + @Threads(16) |
| 110 | + @OutputTimeUnit(TimeUnit.MILLISECONDS) |
| 111 | + public void threadFilterStress16() throws InterruptedException { |
| 112 | + profiler.addThread(); |
| 113 | + // Simulate per-thread work |
| 114 | + Blackhole.consumeCPU(7); |
| 115 | + profiler.removeThread(); |
| 116 | + } |
| 117 | + |
| 118 | + @Benchmark |
| 119 | + @BenchmarkMode(Mode.Throughput) |
| 120 | + @Fork(value = 3, warmups = 3) |
| 121 | + @Warmup(iterations = 5) |
| 122 | + @Measurement(iterations = 8) |
| 123 | + @Threads(99) |
| 124 | + @OutputTimeUnit(TimeUnit.MILLISECONDS) |
| 125 | + public void threadFilterStress99() throws InterruptedException { |
| 126 | + profiler.addThread(); |
| 127 | + // Simulate per-thread work |
| 128 | + Blackhole.consumeCPU(7); |
| 129 | + profiler.removeThread(); |
| 130 | + } |
| 131 | +} |
0 commit comments