diff --git a/python-libs/poulpe/benchmarks.py b/python-libs/poulpe/benchmarks.py index 5d175cf9fd4bf86938e7f71dc22d0cdbc32f3e1f_cHl0aG9uLWxpYnMvcG91bHBlL2JlbmNobWFya3MucHk=..ae879b6da02ab53065446a8b7e5eff194ea20ac1_cHl0aG9uLWxpYnMvcG91bHBlL2JlbmNobWFya3MucHk= 100644 --- 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 index 5d175cf9fd4bf86938e7f71dc22d0cdbc32f3e1f_c3VpdGVzL2hnL2JlbmNobWFya3MvbGliL3NpbXBsZS1jb21tYW5kLnBrbA==..ae879b6da02ab53065446a8b7e5eff194ea20ac1_c3VpdGVzL2hnL2JlbmNobWFya3MvbGliL3NpbXBsZS1jb21tYW5kLnBrbA== 100644 --- a/suites/hg/benchmarks/lib/simple-command.pkl +++ b/suites/hg/benchmarks/lib/simple-command.pkl @@ -7,6 +7,6 @@ /// 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? @@ -11,5 +11,8 @@ 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 }