Skip to content

Commit

Permalink
Add JMH options
Browse files Browse the repository at this point in the history
  • Loading branch information
notoon committed May 3, 2017
1 parent f026de6 commit fa89afa
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 59 deletions.
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>org.seedstack.addons.jmh</groupId>
<artifactId>jmh</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>1.0.1-SNAPSHOT</version>
</parent>

<artifactId>jmh-core</artifactId>
Expand Down
162 changes: 114 additions & 48 deletions core/src/main/java/org/seedstack/jmh/JmhConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,88 @@
package org.seedstack.jmh;

import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.results.format.ResultFormatType;
import org.openjdk.jmh.runner.options.TimeValue;
import org.openjdk.jmh.runner.options.WarmupMode;
import org.seedstack.coffig.Config;
import org.seedstack.coffig.SingleValue;

import java.io.File;
import java.util.concurrent.TimeUnit;

@Config("jmh")
public class JmhConfig {
@SingleValue
private String include;
private String includeWarmup;
private String exclude;
private File result;
private ResultFormatType resultFormat;
private WarmupMode warmupMode = WarmupMode.BULK;
private Mode mode = Mode.AverageTime;
private TimeValue timeout = TimeValue.seconds(10);
private TimeUnit timeUnit = TimeUnit.MILLISECONDS;
private TimeValue warmupTime = TimeValue.seconds(1);
private int warmupIterations = 0;
private TimeValue measurementTime = TimeValue.seconds(1);
private int measurementIterations = 1;
private Computation warmup = new Computation(0, 1, TimeValue.seconds(1), 0);
private Computation measurement = new Computation(0, 1, TimeValue.seconds(1), 1);
private int operationsPerInvocation = 1;
private int threads = 1;
private int forks = 0;
private boolean failOnError = true;
private boolean garbageCollection = true;
private TimeValue timeout = TimeValue.seconds(10);
private TimeUnit timeUnit = TimeUnit.MILLISECONDS;
private String[] jvmArgs = new String[]{};

public static class Computation {
private int forks = 0;
private int batchSize = 1;
private TimeValue time = TimeValue.seconds(1);
private int iterations = 1;

public Computation() {
}

public Computation(int forks, int batchSize, TimeValue time, int iterations) {
this.forks = forks;
this.batchSize = batchSize;
this.time = time;
this.iterations = iterations;
}

public int getForks() {
return forks;
}

public Computation setForks(int forks) {
this.forks = forks;
return this;
}

public int getBatchSize() {
return batchSize;
}

public Computation setBatchSize(int batchSize) {
this.batchSize = batchSize;
return this;
}

public TimeValue getTime() {
return time;
}

public Computation setTime(TimeValue time) {
this.time = time;
return this;
}

public int getIterations() {
return iterations;
}

public Computation setIterations(int iterations) {
this.iterations = iterations;
return this;
}
}

public String getInclude() {
return include;
}
Expand All @@ -42,75 +99,75 @@ public JmhConfig setInclude(String include) {
return this;
}

public String getExclude() {
return exclude;
public String getIncludeWarmup() {
return includeWarmup;
}

public JmhConfig setExclude(String exclude) {
this.exclude = exclude;
public JmhConfig setIncludeWarmup(String includeWarmup) {
this.includeWarmup = includeWarmup;
return this;
}

public Mode getMode() {
return mode;
public String getExclude() {
return exclude;
}

public JmhConfig setMode(Mode mode) {
this.mode = mode;
public JmhConfig setExclude(String exclude) {
this.exclude = exclude;
return this;
}

public TimeValue getTimeout() {
return timeout;
public File getResult() {
return result;
}

public JmhConfig setTimeout(TimeValue timeout) {
this.timeout = timeout;
public JmhConfig setResult(File result) {
this.result = result;
return this;
}

public TimeUnit getTimeUnit() {
return timeUnit;
public ResultFormatType getResultFormat() {
return resultFormat;
}

public JmhConfig setTimeUnit(TimeUnit timeUnit) {
this.timeUnit = timeUnit;
public JmhConfig setResultFormat(ResultFormatType resultFormat) {
this.resultFormat = resultFormat;
return this;
}

public TimeValue getWarmupTime() {
return warmupTime;
public WarmupMode getWarmupMode() {
return warmupMode;
}

public JmhConfig setWarmupTime(TimeValue warmupTime) {
this.warmupTime = warmupTime;
public JmhConfig setWarmupMode(WarmupMode warmupMode) {
this.warmupMode = warmupMode;
return this;
}

public int getWarmupIterations() {
return warmupIterations;
public Mode getMode() {
return mode;
}

public JmhConfig setWarmupIterations(int warmupIterations) {
this.warmupIterations = warmupIterations;
public JmhConfig setMode(Mode mode) {
this.mode = mode;
return this;
}

public TimeValue getMeasurementTime() {
return measurementTime;
public Computation getWarmup() {
return warmup;
}

public JmhConfig setMeasurementTime(TimeValue measurementTime) {
this.measurementTime = measurementTime;
public JmhConfig setWarmup(Computation warmup) {
this.warmup = warmup;
return this;
}

public int getMeasurementIterations() {
return measurementIterations;
public Computation getMeasurement() {
return measurement;
}

public JmhConfig setMeasurementIterations(int measurementIterations) {
this.measurementIterations = measurementIterations;
public JmhConfig setMeasurement(Computation measurement) {
this.measurement = measurement;
return this;
}

Expand All @@ -132,15 +189,6 @@ public JmhConfig setThreads(int threads) {
return this;
}

public int getForks() {
return forks;
}

public JmhConfig setForks(int forks) {
this.forks = forks;
return this;
}

public boolean isFailOnError() {
return failOnError;
}
Expand All @@ -159,6 +207,24 @@ public JmhConfig setGarbageCollection(boolean garbageCollection) {
return this;
}

public TimeValue getTimeout() {
return timeout;
}

public JmhConfig setTimeout(TimeValue timeout) {
this.timeout = timeout;
return this;
}

public TimeUnit getTimeUnit() {
return timeUnit;
}

public JmhConfig setTimeUnit(TimeUnit timeUnit) {
this.timeUnit = timeUnit;
return this;
}

public String[] getJvmArgs() {
return jvmArgs;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,40 @@
*/
package org.seedstack.jmh.internal;

import org.openjdk.jmh.results.format.ResultFormatType;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.SeedJmhRunner;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.seedstack.jmh.JmhConfig;

import java.io.File;
import java.util.Optional;

class JmhRunnerFactory {
Runner createRunner(JmhConfig jmhConfig) {
OptionsBuilder optionsBuilder = new OptionsBuilder();
Optional.ofNullable(jmhConfig.getInclude()).ifPresent(optionsBuilder::include);
Optional.ofNullable(jmhConfig.getIncludeWarmup()).ifPresent(optionsBuilder::includeWarmup);
Optional.ofNullable(jmhConfig.getExclude()).ifPresent(optionsBuilder::exclude);
Optional.ofNullable(jmhConfig.getResult()).map(File::getAbsolutePath).ifPresent(optionsBuilder::result);
Optional.ofNullable(jmhConfig.getResultFormat()).ifPresent(optionsBuilder::resultFormat);
optionsBuilder
.warmupMode(jmhConfig.getWarmupMode())
.warmupForks(jmhConfig.getWarmup().getForks())
.warmupBatchSize(jmhConfig.getWarmup().getBatchSize())
.warmupTime(jmhConfig.getWarmup().getTime())
.warmupIterations(jmhConfig.getWarmup().getIterations())
.mode(jmhConfig.getMode())
.timeout(jmhConfig.getTimeout())
.timeUnit(jmhConfig.getTimeUnit())
.warmupTime(jmhConfig.getWarmupTime())
.warmupIterations(jmhConfig.getWarmupIterations())
.measurementTime(jmhConfig.getMeasurementTime())
.measurementIterations(jmhConfig.getMeasurementIterations())
.forks(jmhConfig.getMeasurement().getForks())
.measurementBatchSize(jmhConfig.getMeasurement().getBatchSize())
.measurementTime(jmhConfig.getMeasurement().getTime())
.measurementIterations(jmhConfig.getMeasurement().getIterations())
.operationsPerInvocation(jmhConfig.getOperationsPerInvocation())
.threads(jmhConfig.getThreads())
.forks(jmhConfig.getForks())
.shouldFailOnError(jmhConfig.isFailOnError())
.shouldDoGC(jmhConfig.isGarbageCollection())
.timeout(jmhConfig.getTimeout())
.timeUnit(jmhConfig.getTimeUnit())
.jvmArgs(jmhConfig.getJvmArgs());
return new SeedJmhRunner(optionsBuilder.build());
}
Expand Down
2 changes: 1 addition & 1 deletion launcher/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>org.seedstack.addons.jmh</groupId>
<artifactId>jmh</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>1.0.1-SNAPSHOT</version>
</parent>

<artifactId>jmh-launcher</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void launch(String[] args) throws Exception {
Coffig coffig = Seed.baseConfiguration();
JmhConfig jmhConfig = coffig.get(JmhConfig.class);

if (jmhConfig.getForks() == 0) {
if (jmhConfig.getMeasurement().getForks() == 0) {
kernel = Seed.createKernel();
JmhPlugin jmhPlugin = getJmhPlugin(kernel);
jmhPlugin.getRunner().run();
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<groupId>org.seedstack.addons.jmh</groupId>
<artifactId>jmh</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>1.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
Expand Down

0 comments on commit fa89afa

Please sign in to comment.