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

Use actual new process to start Gradle for sandbox run.

- using a new process rather than the GradleConnection is now the default, but can be changed in scenarios.json using the key useGradleConnection
parent 896578ff
No related branches found
No related tags found
No related merge requests found
...@@ -32,12 +32,20 @@ public class FullBenchmarkMain { ...@@ -32,12 +32,20 @@ public class FullBenchmarkMain {
static class InvokeJavaVMBenchmark extends Benchmark { static class InvokeJavaVMBenchmark extends Benchmark {
BenchmarkSettings settings; BenchmarkSettings settings;
int repetitions; int repetitions;
private boolean useGradleConnection = false;
private final String gradleCommand = System.getProperty("os.name")
.toLowerCase().contains("windows") ? "./gradle.bat" : "./gradlew";
InvokeJavaVMBenchmark(BenchmarkSettings settings, int repetitions) { InvokeJavaVMBenchmark(BenchmarkSettings settings, int repetitions) {
this.settings = settings; this.settings = settings;
this.repetitions = repetitions; this.repetitions = repetitions;
} }
InvokeJavaVMBenchmark setUseGradleConnection(boolean useGradleConnection) {
this.useGradleConnection = useGradleConnection;
return this;
}
@Override @Override
public void run() { public void run() {
for (int i = 0; i < this.repetitions; i++) { for (int i = 0; i < this.repetitions; i++) {
...@@ -49,7 +57,8 @@ public class FullBenchmarkMain { ...@@ -49,7 +57,8 @@ 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.");
} }
// invoke Gradle target if (useGradleConnection) {
// invoke Gradle target directly
ProjectConnection connection = GradleConnector.newConnector() ProjectConnection connection = GradleConnector.newConnector()
.forProjectDirectory(new File(".")) .forProjectDirectory(new File("."))
.connect(); .connect();
...@@ -62,10 +71,34 @@ public class FullBenchmarkMain { ...@@ -62,10 +71,34 @@ public class FullBenchmarkMain {
} finally { } finally {
connection.close(); connection.close();
} }
} else {
// start a new process calling gradle
File currentDir = getCurrentDir();
try {
ProcessBuilder pb = new ProcessBuilder(gradleCommand, "sandboxRun",
"-PrunSettingsFile=" + tempPath.toAbsolutePath().toString());
pb.redirectOutput(ProcessBuilder.Redirect.INHERIT);
pb.redirectError(ProcessBuilder.Redirect.INHERIT);
pb.directory(currentDir);
Process p = pb.start();
p.waitFor();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
} }
} }
} }
private File getCurrentDir() {
// hacky solution to get to the root of the repository
File maybeCurrentDir = new File("").getAbsoluteFile();
if ("jastadd-mquat-benchmark".equals(maybeCurrentDir.getName())) {
maybeCurrentDir = maybeCurrentDir.getParentFile();
}
return maybeCurrentDir;
}
}
public static void main(String[] args) { public static void main(String[] args) {
List<Benchmark> benchmarks = createFromConfig(args); List<Benchmark> benchmarks = createFromConfig(args);
if (benchmarks == null || benchmarks.isEmpty()) { if (benchmarks == null || benchmarks.isEmpty()) {
...@@ -95,7 +128,7 @@ public class FullBenchmarkMain { ...@@ -95,7 +128,7 @@ public class FullBenchmarkMain {
.map(SolverFactory::getSolverByName).collect(Collectors.toList()); .map(SolverFactory::getSolverByName).collect(Collectors.toList());
return settings.scenarios.stream() return settings.scenarios.stream()
.filter(data -> takeAll || allowedIds.contains(data.getId()) || allowedNames.contains(data.name)) .filter(data -> takeAll || allowedIds.contains(data.getId()) || allowedNames.contains(data.name))
.map(data -> create(from(settings, data), solvers, settings.repetitions, settings.sandBoxed)) .map(data -> create(settings, data, solvers))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
...@@ -143,10 +176,15 @@ public class FullBenchmarkMain { ...@@ -143,10 +176,15 @@ public class FullBenchmarkMain {
return result; return result;
} }
private static Benchmark create(BenchmarkSettings settings, List<BenchmarkableSolver> solvers, int repetitions, boolean sandBoxed) { private static Benchmark create(ScenarioSettings scenarioSettings, ScenarioData data,
return sandBoxed ? List<BenchmarkableSolver> solvers) {
new InvokeJavaVMBenchmark(settings, repetitions) : BenchmarkSettings settings = from(scenarioSettings, data);
new ScenarioBenchmark(settings, solvers, repetitions); if (scenarioSettings.sandBoxed) {
return new InvokeJavaVMBenchmark(settings, scenarioSettings.repetitions)
.setUseGradleConnection(scenarioSettings.useGradleConnection);
} else {
return new ScenarioBenchmark(settings, solvers, scenarioSettings.repetitions);
}
} }
} }
...@@ -17,4 +17,5 @@ public class ScenarioSettings { ...@@ -17,4 +17,5 @@ public class ScenarioSettings {
public int repetitions = 1; public int repetitions = 1;
public List<ScenarioData> scenarios; public List<ScenarioData> scenarios;
public boolean sandBoxed; public boolean sandBoxed;
public boolean useGradleConnection = false;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment