Skip to content

Commit

Permalink
7903369: JMH: GC profiler options
Browse files Browse the repository at this point in the history
  • Loading branch information
shipilev committed Oct 20, 2022
1 parent e7b1218 commit 0cffac9
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,24 @@ public Object allocate() {
}

@Test
public void test() throws RunnerException {
public void testDefault() throws RunnerException {
testWith("");
}

@Test
public void testAlloc() throws RunnerException {
testWith("alloc=true");
}

@Test
public void testAll() throws RunnerException {
testWith("alloc=true;churn=true");
}

private void testWith(String initLine) throws RunnerException {
Options opts = new OptionsBuilder()
.include(Fixtures.getTestMask(this.getClass()))
.addProfiler(GCProfiler.class)
.addProfiler(GCProfiler.class, initLine)
.build();

RunResult rr = new Runner(opts).runSingle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,20 @@

import java.util.concurrent.TimeUnit;

/**
* Tests allocation profiler.
*/
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Fork(1) // 0 to enable debugging
public class GCProfilerTest {

@Benchmark
@Warmup(iterations = 0)
@Measurement(iterations = 20, time = 10, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 10, time = 10, timeUnit = TimeUnit.MILLISECONDS)
@BenchmarkMode(Mode.AverageTime)
public Object allocateObjectNoWarmup() {
return new Object();
}

@Benchmark
@Warmup(iterations = 2)
@Warmup(iterations = 2, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 2, time = 2, timeUnit = TimeUnit.SECONDS)
@BenchmarkMode(Mode.AverageTime)
public Object allocateObject() {
Expand All @@ -68,19 +65,46 @@ public Object allocateObjectSingleShot() {
}

@Benchmark
@Warmup(iterations = 2)
@Warmup(iterations = 2, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 1, time = 2, timeUnit = TimeUnit.SECONDS)
@BenchmarkMode(Mode.SampleTime)
public Object allocateObjectSampleTime() {
return new Object();
}

@Test
public void testAllocationProfiler() throws RunnerException {
public void testDefault() throws RunnerException {
Options opts = new OptionsBuilder()
.include(Fixtures.getTestMask(this.getClass()))
.addProfiler(GCProfiler.class)
.build();
new Runner(opts).run();
}

@Test
public void testAlloc() throws RunnerException {
Options opts = new OptionsBuilder()
.include(Fixtures.getTestMask(this.getClass()))
.addProfiler(GCProfiler.class, "alloc=true")
.build();
new Runner(opts).run();
}

@Test
public void testChurn() throws RunnerException {
Options opts = new OptionsBuilder()
.include(Fixtures.getTestMask(this.getClass()))
.addProfiler(GCProfiler.class, "churn=true;churnWait=1")
.build();
new Runner(opts).run();
}

@Test
public void testAll() throws RunnerException {
Options opts = new OptionsBuilder()
.include(Fixtures.getTestMask(this.getClass()))
.addProfiler(GCProfiler.class, "alloc=true;churn=true;churnWait=1")
.build();
new Runner(opts).run();
}
}
Loading

0 comments on commit 0cffac9

Please sign in to comment.