Run a Java Micro Benchmark Harness This assumes the binary supports the standard command line options, notably `-Dbenchmark_filter`
| 32 | |
| 33 | |
| 34 | class JavaMicrobenchmarkHarnessCommand(Command): |
| 35 | """ Run a Java Micro Benchmark Harness |
| 36 | |
| 37 | This assumes the binary supports the standard command line options, |
| 38 | notably `-Dbenchmark_filter` |
| 39 | """ |
| 40 | |
| 41 | def __init__(self, build, benchmark_filter=None): |
| 42 | self.benchmark_filter = benchmark_filter |
| 43 | self.build = build |
| 44 | self.maven = Maven() |
| 45 | |
| 46 | """ Extract benchmark names from output between "Benchmarks:" and "[INFO]". |
| 47 | Assume the following output: |
| 48 | ... |
| 49 | Benchmarks: |
| 50 | org.apache.arrow.vector.IntBenchmarks.setIntDirectly |
| 51 | ... |
| 52 | org.apache.arrow.vector.IntBenchmarks.setWithValueHolder |
| 53 | org.apache.arrow.vector.IntBenchmarks.setWithWriter |
| 54 | ... |
| 55 | [INFO] |
| 56 | """ |
| 57 | |
| 58 | def list_benchmarks(self): |
| 59 | argv = [] |
| 60 | if self.benchmark_filter: |
| 61 | argv.append(f"-Dbenchmark.filter={self.benchmark_filter}") |
| 62 | result = self.build.list( |
| 63 | *argv, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 64 | |
| 65 | lists = [] |
| 66 | benchmarks = False |
| 67 | for line in str.splitlines(result.stdout.decode("utf-8")): |
| 68 | if not benchmarks: |
| 69 | if line.startswith("Benchmarks:"): |
| 70 | benchmarks = True |
| 71 | else: |
| 72 | if line.startswith("org.apache.arrow"): |
| 73 | lists.append(line) |
| 74 | if line.startswith("[INFO]"): |
| 75 | break |
| 76 | return lists |
| 77 | |
| 78 | def results(self, repetitions): |
| 79 | with NamedTemporaryFile(suffix=".json") as out: |
| 80 | argv = [f"-Dbenchmark.runs={repetitions}", |
| 81 | f"-Dbenchmark.resultfile={out.name}", |
| 82 | "-Dbenchmark.resultformat=json"] |
| 83 | if self.benchmark_filter: |
| 84 | argv.append(f"-Dbenchmark.filter={self.benchmark_filter}") |
| 85 | |
| 86 | self.build.benchmark(*argv, check=True) |
| 87 | return json.load(out) |
| 88 | |
| 89 | |
| 90 | class JavaMicrobenchmarkHarnessObservation: |
no outgoing calls
no test coverage detected