Commit 7c0cb933 authored by René Schöne's avatar René Schöne
Browse files

Write out to result file, if sandboxed benchmark step is killed.

parent b49e842e
......@@ -32,7 +32,7 @@ import static java.nio.file.Files.exists;
@SuppressWarnings("WeakerAccess")
public class Benchmark {
private static final char SEPARATOR = ',';
protected static final char SEPARATOR = ',';
private static final DateFormat df = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss-SSS");
protected final List<BenchmarkableSolver> solvers;
......@@ -141,13 +141,11 @@ public class Benchmark {
if (solvers.isEmpty()) {
logger.warn("No solvers defined. Only model generation will be done.");
}
Path benchmarkPath = Paths.get(settings.path);
Path path, modelDirectory, solutionDirectory;
String start = makeNow();
try {
Path directory = benchmarkPath.resolve(getDirectory());
createDirIfNecessary(directory);
path = directory.resolve(stringFormat(resultFilePattern, e("date", start)));
path = getResultFilePath(start);
Path directory = path.getParent();
modelDirectory = directory.resolve("models");
createDirIfNecessary(modelDirectory);
......@@ -156,7 +154,6 @@ public class Benchmark {
createDirIfNecessary(solutionDirectory);
} catch (IOException e) {
logger.catching(e);
logger.fatal("Could not resolve directory: {}/{}", benchmarkPath, getDirectory());
return;
}
AtomicInteger failCount = new AtomicInteger(5);
......@@ -198,7 +195,14 @@ public class Benchmark {
}
}
private String makeNow() {
protected Path getResultFilePath(String start) throws IOException {
Path benchmarkPath = Paths.get(settings.path);
Path directory = benchmarkPath.resolve(getDirectory());
createDirIfNecessary(directory);
return directory.resolve(stringFormat(resultFilePattern, e("date", start)));
}
protected String makeNow() {
return df.format(new Date());
}
......
......@@ -11,12 +11,15 @@ import org.apache.logging.log4j.Logger;
import org.gradle.tooling.GradleConnector;
import org.gradle.tooling.ProjectConnection;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
/**
......@@ -28,9 +31,7 @@ public class FullBenchmarkMain {
private static Logger logger = LogManager.getLogger(FullBenchmarkMain.class);
static class InvokeJavaVMBenchmark extends Benchmark {
BenchmarkSettings settings;
int repetitions;
static class InvokeJavaVMBenchmark extends ScenarioBenchmark {
private boolean useGradleConnection = false;
private final String gradleCommand = System.getProperty("os.name")
.toLowerCase().contains("windows") ? "./gradle.bat" : "./gradlew";
......@@ -38,8 +39,7 @@ public class FullBenchmarkMain {
private final String gradleArgumentPrefix = "-PrunSettingsFile=";
InvokeJavaVMBenchmark(BenchmarkSettings settings, int repetitions) {
this.settings = settings;
this.repetitions = repetitions;
super(settings, Collections.emptyList(), repetitions);
}
InvokeJavaVMBenchmark setUseGradleConnection(boolean useGradleConnection) {
......@@ -92,10 +92,23 @@ public class FullBenchmarkMain {
boolean finishedInTime = p.waitFor(settings.basic.timeoutValue * 2,
TimeUnit.valueOf(settings.basic.timeoutUnit));
if(!finishedInTime) {
logger.error("Aborting benchmark step, timeout exceeded.");
p.destroy();
p.destroyForcibly();
// wait for the process to actually end
p.waitFor();
// write out csv entry, if the process is terminated this way
StringBuilder sb = createRow();
Path resultFile = getResultFilePath("");
logger.info("Writing out to {}", resultFile);
try (BufferedWriter writer = Files.newBufferedWriter(resultFile,
StandardOpenOption.APPEND, StandardOpenOption.CREATE)) {
writeOutResult(writer, resultFile, new AtomicInteger(1), sb);
} catch (IOException e) {
logger.catching(e);
logger.fatal("Could not create or write to the benchmark file {}.",
resultFile.toAbsolutePath());
}
// skip remaining repetitions, as this timeout is considered as an error
if (settings.skipOnError) {
continue nextSolver;
......@@ -112,6 +125,31 @@ public class FullBenchmarkMain {
}
}
StringBuilder createRow() {
StringBuilder sb = new StringBuilder(makeNow()).append(SEPARATOR);
return sb.append(0).append(SEPARATOR)
.append(settings.basic.minTopLevelComponents).append(SEPARATOR)
.append(settings.basic.minAvgNumCompSubComponents).append(SEPARATOR)
.append(settings.basic.minImplSubComponentDerivation).append(SEPARATOR)
.append(settings.basic.minAvgNumCompSubComponents).append(SEPARATOR)
.append(settings.basic.minCompSubComponentDerivation).append(SEPARATOR)
.append(settings.basic.minComponentDepth).append(SEPARATOR)
.append(settings.basic.minNumImplementations).append(SEPARATOR)
.append(settings.basic.minResourceRatio).append(SEPARATOR)
.append(settings.basic.minRequests).append(SEPARATOR)
.append(settings.basic.minCpus).append(SEPARATOR)
.append(settings.basic.seed).append(SEPARATOR)
.append(-1).append(SEPARATOR) // model.numComponents
.append(-1).append(SEPARATOR) // model.numImplementations
.append(-1).append(SEPARATOR) // modelGeneration
.append(-1).append(SEPARATOR) // initialObjective
.append(-1).append(SEPARATOR) // generation time
.append(-1).append(SEPARATOR) // solving time
.append(-1).append(SEPARATOR) // objective
.append(false).append(SEPARATOR) // validSolution
.append(true).append("\n"); // hadTimeout
}
private File getCurrentDir() {
// hacky solution to get to the root of the repository
File maybeCurrentDir = new File("").getAbsoluteFile();
......
......@@ -18,7 +18,7 @@ import java.util.concurrent.atomic.AtomicInteger;
*/
public class ScenarioBenchmark extends Benchmark {
private int repetitions;
protected int repetitions;
public ScenarioBenchmark(BenchmarkSettings settings, List<BenchmarkableSolver> solvers, int repetitions) {
super();
......
Supports Markdown
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