Commit e1555158 authored by Noric Couderc's avatar Noric Couderc

Documented main for JMH trace benchmarks

parent 9bea7070
......@@ -12,32 +12,48 @@ import se.lth.cs.bcgen.BCBenchmarkPackage;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
public class Main {
public static void main(String[] args) {
System.out.println("Benchmarking traces");
try {
List<Options> benchmarkSpecs = prepareOptions("test-dacapo.csv"); System.out.println("Options created");
List<Options> benchmarkSpecs = prepareOptions("test-dacapo.csv");
System.out.println("Options created");
for (Options o : benchmarkSpecs) {
Runner runner = new Runner(o);;
Runner runner = new Runner(;;
} catch (RunnerException | IOException | ClassNotFoundException | IllegalAccessException | InstantiationException e) {
* Takes a file containing traces to benchmark and creates
* options for running them.
* It loads the data and groups the benchmarks by interface,
* then serializes each group of benchmarks to a file,
* which is then passed as a parameter to the JMH benchmark
* which will do the reloading of the list of benchmarks
* and run one with a specific index.
* (We do this because JMH does not allow giving data to a
* benchmark, except strings, so we have to serialize and
* pass the file name as parameter)
* @param fileName: The file from which to load the traces
* @return
* @throws IOException
* @throws IllegalAccessException
* @throws InstantiationException
* @throws ClassNotFoundException
private static List<Options> prepareOptions(String fileName)
throws IOException, IllegalAccessException, InstantiationException,
ClassNotFoundException {
......@@ -46,31 +62,36 @@ public class Main {
tl.readCsv(new FileReader(new File("test-dacapo.csv")), false)
FileOutputStream fo = new FileOutputStream("serialized-benchmarks");
ObjectOutputStream out = new ObjectOutputStream(fo);
Map<String, List<BCBenchmarkPackage<?>>> benchmarksByInterface =
x -> x.getInterfaceIdentifier()
Map<String, List<Integer>> indexes = new HashMap<>();
int index = 0;
for (BCBenchmarkPackage<?> b : benchmarks) {
String id = b.getInterfaceIdentifier();
if (indexes.containsKey(id)) {
} else {
indexes.put(id, new ArrayList<>());
// Because you cannot pass any data (except strings) to JMH
// We'll serialize this data that is expensive to compute
// and pass the file name to JMH so it can load it.
for (Map.Entry<String, List<BCBenchmarkPackage<?>>> e : benchmarksByInterface.entrySet()) {
String label = e.getKey();
FileOutputStream fo = new FileOutputStream(String.format("%s-serialized-benchmarks", label));
ObjectOutputStream out = new ObjectOutputStream(fo);
List<Options> result = new ArrayList<>();
for (Map.Entry<String, List<Integer>> e : indexes.entrySet()) {
for (Map.Entry<String, List<BCBenchmarkPackage<?>>> e : benchmarksByInterface.entrySet()) {
// This is the class we want to use for current benchmark run
String benchmarkName = e.getKey() + "TraceBenchmark";
Stream<Integer> benchmarkIds = e.getValue().stream();
String[] benchmarkIdsStrings =
// The range of benchmarks to run (in the traces)
// We just have 0,1,2,3,... to the number of benchmarks for this
// interface in the traces (the benchmark object will run the correct
// benchmark)
IntStream benchmarkIds = IntStream.range(0, e.getValue().size());
String[] benchmarkIdsStrings = new String[e.getValue().size()];
// Because in Java you can't map an IntStream to a generic stream...
i -> benchmarkIdsStrings[i] = Integer.toString(i)
Options o = new OptionsBuilder()
......@@ -78,10 +99,12 @@ public class Main {
.measurementTime(new TimeValue(250, TimeUnit.MILLISECONDS))
.warmupTime(new TimeValue(250, TimeUnit.MILLISECONDS))
.result(benchmarkName + ".csv")
// Which file to use to load the list of benchmark to run
.param("traceFileName", String.format("%s-serialized-benchmarks", e.getKey()))
// The array of indexes for each benchmark (arrays in the list serialized above)
.param("traceId", benchmarkIdsStrings)
.param("traceFileName", "serialized-benchmarks")
.result(e.getKey() + "-benchmarks-results.csv")
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