public static void runBenchmarks(Class<?> clazz, Mode... modes) throws RunnerException { Collection<RunResult> allResults = new ArrayList<>(); for (Mode mode : modes) { ChainedOptionsBuilder builder = makeOptionBuilder(clazz).param("mode", mode.name); for (String arg : mode.jvmArgs) { builder.jvmArgsAppend(arg); } allResults.addAll(new Runner(builder.build()).run()); } printResult(allResults); }
public static void main(String[] args) throws IOException { if (args.length != 4) { System.err.println( "Wrong arguments number: should be 4: [logFolder] [http address to push data] [mwg version] [commit id]"); System.exit(2); } StringBuilder jsonBuilder = new StringBuilder(); jsonBuilder .append(START_OBJ) .append(START_STRING) .append("commitId") .append(START_STRING) .append(DATA_VALUE_SEP) .append(START_STRING) .append(args[3]) .append(START_STRING) .append(DATA_SEP) .append(EOL) .append(START_STRING) .append("mwgVersion") .append(START_STRING) .append(DATA_VALUE_SEP) .append(START_STRING) .append(args[2]) .append(START_STRING) .append(DATA_SEP) .append(EOL) .append(START_STRING) .append("benchs") .append(START_STRING) .append(DATA_VALUE_SEP) .append(START_ARRAY) .append(EOL); Set<BenchmarkListEntry> benchmarks; { BenchmarkList list = BenchmarkList.defaultList(); Options options = new OptionsBuilder().build(); OutputFormat out = OutputFormatFactory.createFormatInstance(System.out, VerboseMode.NORMAL); benchmarks = list.find(out, options.getIncludes(), options.getExcludes()); } StringBuilder failedBench = new StringBuilder(); failedBench.append(INIT_FAILED_MSG); for (Iterator<BenchmarkListEntry> iterator = benchmarks.iterator(); iterator.hasNext(); ) { BenchmarkListEntry bench = iterator.next(); Optional<Map<String, String[]>> params = bench.getParams(); String[] keys; String[][] values; // get all executions if (params.hasValue()) { Map<String, String[]> paramsMap = params.get(); int nbSolution = 1; for (String[] paramValues : paramsMap.values()) { nbSolution *= paramValues.length; } keys = new String[paramsMap.keySet().size()]; { Iterator<String> itKey = paramsMap.keySet().iterator(); int index = 0; while (itKey.hasNext()) { keys[index] = itKey.next(); index++; } } values = new String[nbSolution][keys.length]; for (int sol = 0; sol < nbSolution; sol++) { int j = 1; int index = 0; String[] toAdd = new String[keys.length]; for (String[] v : paramsMap.values()) { toAdd[index] = v[(sol / j) % v.length]; index++; j *= v.length; } values[sol] = toAdd; } } else { keys = new String[0]; values = new String[1][0]; } // Run and create for (int nbExec = 0; nbExec < values.length; nbExec++) { jsonBuilder.append(START_OBJ); // name jsonBuilder .append(START_STRING) .append("name") .append(END_STRING) .append(DATA_VALUE_SEP) .append(START_STRING) .append(bench.getUsername()) .append(END_STRING) .append(DATA_SEP) .append(EOL); ChainedOptionsBuilder optionsBuilder = new OptionsBuilder().include(bench.getUsername()).shouldFailOnError(true); StringBuilder paramsStr = null; jsonBuilder .append(START_STRING) .append("params") .append(END_STRING) .append(DATA_VALUE_SEP) .append(START_OBJ) .append(EOL); paramsStr = new StringBuilder(); for (int numKey = 0; numKey < keys.length; numKey++) { optionsBuilder.param(keys[numKey], values[nbExec][numKey]); jsonBuilder .append(START_STRING) .append(keys[numKey]) .append(END_STRING) .append(DATA_VALUE_SEP) .append(START_STRING) .append(values[nbExec][numKey]) .append(END_STRING); paramsStr.append(keys[numKey]).append("=").append(values[nbExec][numKey]); jsonBuilder.append(DATA_SEP); paramsStr.append(DATA_SEP); jsonBuilder.append(EOL); } jsonBuilder .append(START_STRING) .append("batchSize") .append(END_STRING) .append(DATA_VALUE_SEP) .append(START_STRING) .append(bench.getMeasurementBatchSize().orElse(-1)) .append(END_STRING) .append(EOL); paramsStr .append("batchSize") .append("=") .append(bench.getMeasurementBatchSize().orElse(-1)); jsonBuilder.append(END_OBJ).append(DATA_SEP).append(EOL); Options options = optionsBuilder.build(); runBench(jsonBuilder, bench.getUsername(), options, failedBench, paramsStr); jsonBuilder.append(END_OBJ); if (nbExec <= values.length - 2) { jsonBuilder.append(DATA_SEP); } jsonBuilder.append(EOL); } if (iterator.hasNext()) { jsonBuilder.append(DATA_SEP); } } jsonBuilder.append(END_ARRAY).append(END_OBJ); File logFolder = new File(args[0]); logFolder.mkdirs(); File logFile = new File(logFolder.getAbsolutePath() + "/" + System.currentTimeMillis() + "-bench.json"); FileWriter logWriter = new FileWriter(logFile); logWriter.append(jsonBuilder); logWriter.flush(); logWriter.close(); RestCall.save(args[1], jsonBuilder.toString()); if (failedBench.length() > INIT_FAILED_MSG.length()) { throw new RuntimeException(failedBench.toString()); } }