|
3 | 3 | import jakarta.xml.bind.JAXBException;
|
4 | 4 | import java.io.File;
|
5 | 5 | import java.io.IOException;
|
6 |
| -import java.util.ArrayList; |
7 | 6 | import java.util.Collection;
|
8 | 7 | import java.util.List;
|
9 |
| -import java.util.stream.Collectors; |
10 | 8 | import org.openjdk.jmh.results.RunResult;
|
11 |
| -import org.openjdk.jmh.runner.BenchmarkList; |
12 |
| -import org.openjdk.jmh.runner.BenchmarkListEntry; |
13 | 9 | import org.openjdk.jmh.runner.Runner;
|
14 | 10 | import org.openjdk.jmh.runner.RunnerException;
|
15 | 11 | import org.openjdk.jmh.runner.options.CommandLineOptionException;
|
|
21 | 17 | public class BenchmarksRunner {
|
22 | 18 | public static final File REPORT_FILE = new File("./bench-report.xml");
|
23 | 19 |
|
24 |
| - /** |
25 |
| - * @return A list of qualified names of all benchmarks visible to JMH. |
26 |
| - */ |
27 |
| - public List<String> getAvailable() { |
28 |
| - return BenchmarkList.defaultList().getAll(null, new ArrayList<>()).stream() |
29 |
| - .map(BenchmarkListEntry::getUsername) |
30 |
| - .collect(Collectors.toList()); |
31 |
| - } |
32 |
| - |
33 | 20 | public static void run(String[] args) throws RunnerException {
|
34 | 21 | CommandLineOptions cmdOpts = null;
|
35 | 22 | try {
|
@@ -75,35 +62,35 @@ public static void run(String[] args) throws RunnerException {
|
75 | 62 | }
|
76 | 63 | }
|
77 | 64 |
|
78 |
| - private static Collection<RunResult> runCompileOnly(List<String> includes) |
79 |
| - throws RunnerException { |
80 |
| - System.out.println("Running benchmarks " + includes + " in compileOnly mode"); |
| 65 | + /** |
| 66 | + * Results from compileOnly mode are not reported. Moreover, if some of the benchmarks in this |
| 67 | + * mode fails, the whole process immediately fails. This behavior is different to *normal* |
| 68 | + * benchmarks, where a single failure does not stop the whole process. |
| 69 | + */ |
| 70 | + private static void runCompileOnly(List<String> includes) { |
| 71 | + if (includes.isEmpty()) { |
| 72 | + System.out.println("Running all benchmarks in compileOnly mode"); |
| 73 | + } else { |
| 74 | + System.out.println("Running benchmarks " + includes + " in compileOnly mode"); |
| 75 | + } |
81 | 76 | var optsBuilder =
|
82 | 77 | new OptionsBuilder()
|
83 | 78 | .measurementTime(TimeValue.seconds(1))
|
84 | 79 | .measurementIterations(1)
|
85 | 80 | .warmupIterations(0)
|
| 81 | + .shouldFailOnError(true) |
86 | 82 | .forks(0);
|
87 | 83 | includes.forEach(optsBuilder::include);
|
88 | 84 | var opts = optsBuilder.build();
|
89 | 85 | var runner = new Runner(opts);
|
90 |
| - return runner.run(); |
91 |
| - } |
92 |
| - |
93 |
| - public static BenchmarkItem runSingle(String label) throws RunnerException, JAXBException { |
94 |
| - String includeRegex = "^" + label + "$"; |
95 |
| - if (Boolean.getBoolean("bench.compileOnly")) { |
96 |
| - var results = runCompileOnly(List.of(includeRegex)); |
97 |
| - var firstResult = results.iterator().next(); |
98 |
| - return reportResult(label, firstResult); |
99 |
| - } else { |
100 |
| - var opts = |
101 |
| - new OptionsBuilder() |
102 |
| - .jvmArgsAppend("-Xss16M", "-Dpolyglot.engine.MultiTier=false") |
103 |
| - .include(includeRegex) |
104 |
| - .build(); |
105 |
| - RunResult benchmarksResult = new Runner(opts).runSingle(); |
106 |
| - return reportResult(label, benchmarksResult); |
| 86 | + try { |
| 87 | + runner.run(); |
| 88 | + System.out.println( |
| 89 | + "benchmarks run successfully in compileOnly mode. Results are not reported."); |
| 90 | + } catch (RunnerException e) { |
| 91 | + System.err.println("Benchmark run failed: " + e.getMessage()); |
| 92 | + e.printStackTrace(System.err); |
| 93 | + System.exit(1); |
107 | 94 | }
|
108 | 95 | }
|
109 | 96 |
|
|
0 commit comments