Commit fa06d420 authored by Eric Bruneton's avatar Eric Bruneton

Merge branch 'use-memory-profiler-only-for-memory-benchmarks' into 'master'

Use the memory profiler only for the memory benchmarks. This reduces the time…

See merge request !216
parents d8686cd6 bca84006
Pipeline #2835 passed with stage
in 6 minutes and 40 seconds
......@@ -45,7 +45,7 @@ import org.openjdk.jmh.infra.Blackhole;
*/
@Fork(1)
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 20, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 30, time = 1, timeUnit = TimeUnit.SECONDS)
@State(Scope.Thread)
public class AdapterBenchmark extends AbstractBenchmark {
......
......@@ -44,7 +44,7 @@ import org.openjdk.jmh.annotations.Warmup;
*/
@Fork(1)
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 20, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 30, time = 1, timeUnit = TimeUnit.SECONDS)
@State(Scope.Thread)
public class GeneratorBenchmark extends AbstractBenchmark {
......
......@@ -48,6 +48,7 @@ import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.openjdk.jmh.infra.BenchmarkParams;
import org.openjdk.jmh.infra.IterationParams;
......@@ -80,6 +81,9 @@ public class MemoryProfiler implements InternalProfiler {
@Override
public void beforeIteration(
final BenchmarkParams benchmarkParams, final IterationParams iterationParams) {
if (!appliesToBenchmark(benchmarkParams)) {
return;
}
references = new Object[100000];
referenceCount = 0;
usedMemoryBeforeIteration = getUsedMemory();
......@@ -90,6 +94,9 @@ public class MemoryProfiler implements InternalProfiler {
final BenchmarkParams benchmarkParams,
final IterationParams iterationParams,
final IterationResult result) {
if (!appliesToBenchmark(benchmarkParams)) {
return Collections.emptyList();
}
long usedMemoryAfterIteration = getUsedMemory();
references = null;
......@@ -101,6 +108,10 @@ public class MemoryProfiler implements InternalProfiler {
return results;
}
private static boolean appliesToBenchmark(final BenchmarkParams benchmarkParams) {
return benchmarkParams.getBenchmark().contains("MemoryBenchmark");
}
/**
* Triggers a gc, waits for completion and returns the used memory. Inspired from cache2k
* ForcedGcMemoryProfiler, itself inspired from the JMH approach.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment