Skip to content

Apache DataFusion SQL Query Engine

ARROW-5269: [C++][Archery] Mark relevant benchmarks as regression

François Saint-Jacquesfd844900d939
diff --git a/dev/archery/archery/benchmark/google.py b/dev/archery/archery/benchmark/google.py
index bd2793eb4e..49e6ad1b05 100644
--- a/dev/archery/archery/benchmark/google.py
+++ b/dev/archery/archery/benchmark/google.py
@@ -30,6 +30,9 @@ def partition(pred, iterable):
return list(filter(pred, t1)), list(filterfalse(pred, t2))
+DEFAULT_REPETITIONS = 10
+
+
class GoogleBenchmarkCommand(Command):
""" Run a google benchmark binary.
@@ -49,9 +52,9 @@ class GoogleBenchmarkCommand(Command):
stderr=subprocess.PIPE)
return str.splitlines(result.stdout.decode("utf-8"))
- def results(self):
+ def results(self, repetitions=DEFAULT_REPETITIONS):
with NamedTemporaryFile() as out:
- argv = ["--benchmark_repetitions=20",
+ argv = [f"--benchmark_repetitions={repetitions}",
f"--benchmark_out={out.name}",
"--benchmark_out_format=json"]
@@ -87,13 +90,14 @@ class GoogleBenchmarkObservation:
"""
def __init__(self, name, real_time, cpu_time, time_unit, size=None,
- bytes_per_second=None, **kwargs):
+ bytes_per_second=None, items_per_second=None, **kwargs):
self._name = name
self.real_time = real_time
self.cpu_time = cpu_time
self.time_unit = time_unit
self.size = size
self.bytes_per_second = bytes_per_second
+ self.items_per_second = items_per_second
@property
def is_agg(self):
@@ -118,11 +122,16 @@ class GoogleBenchmarkObservation:
@property
def value(self):
""" Return the benchmark value."""
- return self.bytes_per_second if self.size else self.time
+ return self.bytes_per_second or self.items_per_second or self.time
@property
def unit(self):
- return "bytes_per_second" if self.size else self.time_unit
+ if self.bytes_per_second:
+ return "bytes_per_second"
+ elif self.items_per_second:
+ return "items_per_second"
+ else:
+ return self.time_unit
def __repr__(self):
return f"{self.value}"
@@ -147,9 +156,7 @@ class GoogleBenchmark(Benchmark):
_, runs = partition(lambda b: b.is_agg, runs)
self.runs = sorted(runs, key=lambda b: b.value)
unit = self.runs[0].unit
- # If `size` is found in the json dict, then the benchmark is reported
- # in bytes per second
- less_is_better = self.runs[0].size is None
+ less_is_better = not unit.endswith("per_second")
values = [b.value for b in self.runs]
super().__init__(name, unit, less_is_better, values)
diff --git a/dev/archery/archery/benchmark/runner.py b/dev/archery/archery/benchmark/runner.py
index dbbb3f5713..5cee7782c8 100644
--- a/dev/archery/archery/benchmark/runner.py
+++ b/dev/archery/archery/benchmark/runner.py
@@ -85,6 +85,12 @@ class StaticBenchmarkRunner(BenchmarkRunner):
self._suites = suites
super().__init__(**kwargs)
+ @property
+ def list_benchmarks(self):
+ for suite in self._suites:
+ for benchmark in suite.benchmarks:
+ yield f"{suite.name}.{benchmark.name}"
+
@property
def suites(self):
suite_fn = regex_filter(self.suite_filter)
@@ -146,6 +152,13 @@ class CppBenchmarkRunner(BenchmarkRunner):
benchmarks = GoogleBenchmark.from_json(results.get("benchmarks"))
return BenchmarkSuite(name, benchmarks)
+ @property
+ def list_benchmarks(self):
+ for suite_name, suite_bin in self.suites_binaries.items():
+ suite_cmd = GoogleBenchmarkCommand(suite_bin)
+ for benchmark_name in suite_cmd.list_benchmarks():
+ yield f"{suite_name}.{benchmark_name}"
+
@property
def suites(self):
""" Returns all suite for a runner. """
diff --git a/dev/archery/archery/cli.py b/dev/archery/archery/cli.py
index 0178d58a03..e2dd9ea1c9 100644
--- a/dev/archery/archery/cli.py
+++ b/dev/archery/archery/cli.py
@@ -37,10 +37,12 @@ logging.basicConfig(level=logging.INFO)
@click.group()
@click.option("--debug", type=bool, is_flag=True, default=False,
help="Increase logging with debugging output.")
[email protected]("--pdb", type=bool, is_flag=True, default=False,
+ help="Invoke pdb on uncaught exception.")
@click.option("-q", "--quiet", type=bool, is_flag=True, default=False,
help="Silence executed commands.")
@click.pass_context
-def archery(ctx, debug, quiet):
+def archery(ctx, debug, pdb, quiet):
""" Apache Arrow developer utilities.
See sub-commands help with `archery <cmd> --help`.
@@ -53,6 +55,10 @@ def archery(ctx, debug, quiet):
if debug:
logger.setLevel(logging.DEBUG)
+ if pdb:
+ import pdb
+ sys.excepthook = lambda t, v, e: pdb.pm()
+
def validate_arrow_sources(ctx, param, src):
""" Ensure a directory contains Arrow cpp sources. """
@@ -167,6 +173,39 @@ def benchmark(ctx):
pass
[email protected](name="list", short_help="List benchmark suite")
[email protected]("--src", metavar="<arrow_src>", show_default=True,
+ default=ArrowSources.find(),
+ callback=validate_arrow_sources,
+ help="Specify Arrow source directory")
[email protected]("--preserve", type=bool, default=False, show_default=True,
+ is_flag=True, help="Preserve workspace for investigation.")
[email protected]("--output", metavar="<output>",
+ type=click.File("w", encoding="utf8"), default="-",
+ help="Capture output result into file.")
[email protected]("--cmake-extras", type=str, multiple=True,
+ help="Extra flags/options to pass to cmake invocation. "
+ "Can be stacked")
[email protected]("rev_or_path", metavar="[<rev_or_path>]", default="WORKSPACE",
+ required=False)
+def benchmark_list(ctx, src, preserve, output, cmake_extras, rev_or_path):
+ """ List benchmark suite.
+ """
+ with tmpdir(preserve) as root:
+ logger.debug(f"Running benchmark {rev_or_path}")
+
+ conf = CppConfiguration(
+ build_type="release", with_tests=True, with_benchmarks=True,
+ with_python=False, cmake_extras=cmake_extras)
+
+ runner_base = BenchmarkRunner.from_rev_or_path(
+ src, root, rev_or_path, conf)
+
+ for b in runner_base.list_benchmarks:
+ click.echo(b, file=output)
+
+
@benchmark.command(name="run", short_help="Run benchmark suite")
@click.option("--src", metavar="<arrow_src>", show_default=True,
default=ArrowSources.find(),
@@ -175,7 +214,7 @@ def benchmark(ctx):
@click.option("--suite-filter", metavar="<regex>", show_default=True,
type=str, default=None, help="Regex filtering benchmark suites.")
@click.option("--benchmark-filter", metavar="<regex>", show_default=True,
- type=str, default=DEFAULT_BENCHMARK_FILTER,
+ type=str, default=None,
help="Regex filtering benchmark suites.")
@click.option("--preserve", type=bool, default=False, show_default=True,
is_flag=True, help="Preserve workspace for investigation.")
@@ -185,11 +224,11 @@ def benchmark(ctx):
@click.option("--cmake-extras", type=str, multiple=True,
help="Extra flags/options to pass to cmake invocation. "
"Can be stacked")
[email protected]("baseline", metavar="[<baseline>]]", default="master",
[email protected]("rev_or_path", metavar="[<rev_or_path>]", default="WORKSPACE",
required=False)
@click.pass_context
def benchmark_run(ctx, src, preserve, suite_filter, benchmark_filter,
- output, cmake_extras, baseline):
+ output, cmake_extras, rev_or_path):
""" Run benchmark suite.
This command will run the benchmark suite for a single build. This is
@@ -198,7 +237,6 @@ def benchmark_run(ctx, src, preserve, suite_filter, benchmark_filter,
The caller can optionally specify a target which is either a git revision
(commit, tag, special values like HEAD) or a cmake build directory.
-
When a commit is referenced, a local clone of the arrow sources (specified
via --src) is performed and the proper branch is created. This is done in
a temporary directory which can be left intact with the `---preserve` flag.
@@ -224,14 +262,14 @@ def benchmark_run(ctx, src, preserve, suite_filter, benchmark_filter,
archery benchmark run --output=run.json
"""
with tmpdir(preserve) as root:
- logger.debug(f"Running benchmark {baseline}")
+ logger.debug(f"Running benchmark {rev_or_path}")
conf = CppConfiguration(
build_type="release", with_tests=True, with_benchmarks=True,
with_python=False, cmake_extras=cmake_extras)
runner_base = BenchmarkRunner.from_rev_or_path(
- src, root, baseline, conf,
+ src, root, rev_or_path, conf,
suite_filter=suite_filter, benchmark_filter=benchmark_filter)
json.dump(runner_base, output, cls=JsonEncoder)
@@ -357,7 +395,7 @@ def benchmark_diff(ctx, src, preserve, suite_filter, benchmark_filter,
for comparator in runner_comp.comparisons:
regressions += comparator.regression
json.dump(comparator, output, cls=JsonEncoder)
- output.write('\n')
+ output.write("\n")
sys.exit(regressions)