# HG changeset patch # User Raphaël Gomès <rgomes@octobus.net> # Date 1734606413 -3600 # Thu Dec 19 12:06:53 2024 +0100 # Node ID ae879b6da02ab53065446a8b7e5eff194ea20ac1 # Parent 5d175cf9fd4bf86938e7f71dc22d0cdbc32f3e1f simple-command: add a way of running a cleanup script after each run This corresponds to the `--conclude` option of hyperfine and will be used in an upcoming test where a background process is spawned. diff --git a/python-libs/poulpe/benchmarks.py b/python-libs/poulpe/benchmarks.py --- a/python-libs/poulpe/benchmarks.py +++ b/python-libs/poulpe/benchmarks.py @@ -230,6 +230,7 @@ cmd.apply_data_env(data_env) prepare = self.get_var("simple-command.prepare-run") + cleanup = self.get_var("simple-command.cleanup-run") temp_dir = tempfile.mkdtemp() # TODO same tmp dir as `copy-data-env` try: r = self._time_command( @@ -238,6 +239,7 @@ cmd, temp_dir=temp_dir, prepare=prepare, + cleanup=cleanup, debug=debug, ) finally: @@ -263,6 +265,7 @@ cmd, temp_dir, prepare=None, + cleanup=None, debug=False, ): bin_env_path = os.path.abspath(bin_env_path) @@ -317,6 +320,13 @@ time_cmd.append("--prepare") time_cmd.append(prepare) + if cleanup is not None: + if not bool(self.get_var("simple-command.no-set-builtin")): + cleanup = f"set -eEuo pipefail; {cleanup}" + # beware that `--cleanup` is global to a hyperfine invocation + time_cmd.append("--conclude") + time_cmd.append(cleanup) + command = cmd.command if debug: command = f'echo "### starting command ###" ; date ; {command}' diff --git a/suites/hg/benchmarks/lib/simple-command.pkl b/suites/hg/benchmarks/lib/simple-command.pkl --- a/suites/hg/benchmarks/lib/simple-command.pkl +++ b/suites/hg/benchmarks/lib/simple-command.pkl @@ -7,9 +7,12 @@ /// It can we extended with variants (see next section) command = String -/// A command (or series of command) to run before each command run. +/// A command (or series of commands) to run before each command run. prepare_run: String? +/// A command (or series of commands) to run after each command run. +cleanup_run: String? + /// Variants allow for slight variation of a benchmark. For example, they allow to change the /// input data, of to turn some feature on and off. /// @@ -31,6 +34,9 @@ when (prepare_run != null) { ["prepare-run"] = prepare_run } + when (cleanup_run != null) { + ["cleanup-run"] = cleanup_run + } when (accept_failure) { ["accept-failure"] = accept_failure }