Skip to content
Snippets Groups Projects
Commit fd919675 authored by René Schöne's avatar René Schöne
Browse files

Use separate process for each solver in benchmark run.

- new option skipOnErrors (only used for full/scenario-benchmark) to skip remaining repetitions of one solver on error
parent 3b037fb2
No related branches found
No related tags found
No related merge requests found
...@@ -15,9 +15,7 @@ import java.io.File; ...@@ -15,9 +15,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Arrays; import java.util.*;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -35,6 +33,8 @@ public class FullBenchmarkMain { ...@@ -35,6 +33,8 @@ public class FullBenchmarkMain {
private boolean useGradleConnection = false; private boolean useGradleConnection = false;
private final String gradleCommand = System.getProperty("os.name") private final String gradleCommand = System.getProperty("os.name")
.toLowerCase().contains("windows") ? "./gradle.bat" : "./gradlew"; .toLowerCase().contains("windows") ? "./gradle.bat" : "./gradlew";
private final String gradleTaskName = "sandboxRun";
private final String gradleArgumentPrefix = "-PrunSettingsFile=";
InvokeJavaVMBenchmark(BenchmarkSettings settings, int repetitions) { InvokeJavaVMBenchmark(BenchmarkSettings settings, int repetitions) {
this.settings = settings; this.settings = settings;
...@@ -48,7 +48,10 @@ public class FullBenchmarkMain { ...@@ -48,7 +48,10 @@ public class FullBenchmarkMain {
@Override @Override
public void run() { public void run() {
for (int i = 0; i < this.repetitions; i++) { // create a settings file for each solver
List<Path> pathList = new ArrayList<>();
for (String solverName : this.settings.solvers) {
settings.solvers = Collections.singletonList(solverName);
Path tempPath; Path tempPath;
try { try {
tempPath = Files.createTempFile("runSettings", ".json"); tempPath = Files.createTempFile("runSettings", ".json");
...@@ -57,33 +60,41 @@ public class FullBenchmarkMain { ...@@ -57,33 +60,41 @@ public class FullBenchmarkMain {
logger.catching(e); logger.catching(e);
throw new RuntimeException("Could not create temporary file for sandBoxed use. Exiting."); throw new RuntimeException("Could not create temporary file for sandBoxed use. Exiting.");
} }
if (useGradleConnection) { pathList.add(tempPath);
// invoke Gradle target directly }
ProjectConnection connection = GradleConnector.newConnector() nextSolver: for (Path path : pathList) {
.forProjectDirectory(new File(".")) for (int i = 0; i < this.repetitions; i++) {
.connect(); if (useGradleConnection) {
try { // invoke Gradle target directly
connection.newBuild() ProjectConnection connection = GradleConnector.newConnector()
.forTasks("sandboxRun") .forProjectDirectory(new File("."))
.withArguments("-PrunSettingsFile=" + tempPath.toAbsolutePath().toString()) .connect();
.setStandardOutput(System.out) try {
.run(); connection.newBuild()
} finally { .forTasks(gradleTaskName)
connection.close(); .withArguments(gradleArgumentPrefix + path.toAbsolutePath().toString())
} .setStandardOutput(System.out)
} else { .run();
// start a new process calling gradle } finally {
File currentDir = getCurrentDir(); connection.close();
try { }
ProcessBuilder pb = new ProcessBuilder(gradleCommand, "sandboxRun", } else {
"-PrunSettingsFile=" + tempPath.toAbsolutePath().toString()); // start a new process calling gradle
pb.redirectOutput(ProcessBuilder.Redirect.INHERIT); File currentDir = getCurrentDir();
pb.redirectError(ProcessBuilder.Redirect.INHERIT); try {
pb.directory(currentDir); ProcessBuilder pb = new ProcessBuilder(gradleCommand, gradleTaskName,
Process p = pb.start(); gradleArgumentPrefix + path.toAbsolutePath().toString());
p.waitFor(); pb.redirectOutput(ProcessBuilder.Redirect.INHERIT);
} catch (IOException | InterruptedException e) { pb.redirectError(ProcessBuilder.Redirect.INHERIT);
e.printStackTrace(); pb.directory(currentDir);
Process p = pb.start();
p.waitFor();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
if (settings.skipOnError) {
continue nextSolver;
}
}
} }
} }
} }
...@@ -150,6 +161,7 @@ public class FullBenchmarkMain { ...@@ -150,6 +161,7 @@ public class FullBenchmarkMain {
result.logLevel = settings.logLevel; result.logLevel = settings.logLevel;
result.path = settings.path; result.path = settings.path;
result.solvers = settings.solvers; result.solvers = settings.solvers;
result.skipOnError = settings.skipOnError;
TestGeneratorSettings tgs = new TestGeneratorSettings(); TestGeneratorSettings tgs = new TestGeneratorSettings();
tgs.minTopLevelComponents = tgs.maxTopLevelComponents = 1; tgs.minTopLevelComponents = tgs.maxTopLevelComponents = 1;
tgs.minAvgNumImplSubComponents = tgs.maxAvgNumImplSubComponents = 0; tgs.minAvgNumImplSubComponents = tgs.maxAvgNumImplSubComponents = 0;
......
...@@ -17,6 +17,7 @@ public class BenchmarkSettings { ...@@ -17,6 +17,7 @@ public class BenchmarkSettings {
public String solutionFilePattern = null; public String solutionFilePattern = null;
public List<String> solvers = null; public List<String> solvers = null;
public String logLevel = null; public String logLevel = null;
public Boolean skipOnError = true;
public final TestGeneratorSettings basic = new TestGeneratorSettings(); public final TestGeneratorSettings basic = new TestGeneratorSettings();
...@@ -26,6 +27,7 @@ public class BenchmarkSettings { ...@@ -26,6 +27,7 @@ public class BenchmarkSettings {
this.resultFilePattern = nonNullOrDefault(other.resultFilePattern, this.resultFilePattern); this.resultFilePattern = nonNullOrDefault(other.resultFilePattern, this.resultFilePattern);
this.solvers = nonNullOrDefault(other.solvers, this.solvers); this.solvers = nonNullOrDefault(other.solvers, this.solvers);
this.logLevel = nonNullOrDefault(other.logLevel, this.logLevel); this.logLevel = nonNullOrDefault(other.logLevel, this.logLevel);
this.skipOnError = nonNullOrDefault(other.skipOnError, this.skipOnError);
updateBasic(other.basic); updateBasic(other.basic);
} }
......
...@@ -18,4 +18,5 @@ public class ScenarioSettings { ...@@ -18,4 +18,5 @@ public class ScenarioSettings {
public List<ScenarioData> scenarios; public List<ScenarioData> scenarios;
public boolean sandBoxed; public boolean sandBoxed;
public boolean useGradleConnection = false; public boolean useGradleConnection = false;
public boolean skipOnError = true;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment