diff --git a/docs/benchmarks.rst b/docs/benchmarks.rst index 10df08131fc706b98f1da1af955b3402c3629544_ZG9jcy9iZW5jaG1hcmtzLnJzdA==..e93c95be7964186f23a043861150ff78e16e263d_ZG9jcy9iZW5jaG1hcmtzLnJzdA== 100644 --- a/docs/benchmarks.rst +++ b/docs/benchmarks.rst @@ -48,6 +48,15 @@ When true, the benchmark is run a copy of the data-environment. Any alteration will be destroyed at the end of the iteration. +section: environment +-------------------- + +A section that allow to set environment variable to be used when running the +command. This is useful to replace some of the command argument with. Each +sub-key is a an environment variable to replace. + +Value supports the `DATA-VARS:` notation if necessary + Simple-command configuration ============================ diff --git a/python-libs/poulpe/benchmarks.py b/python-libs/poulpe/benchmarks.py index 10df08131fc706b98f1da1af955b3402c3629544_cHl0aG9uLWxpYnMvcG91bHBlL2JlbmNobWFya3MucHk=..e93c95be7964186f23a043861150ff78e16e263d_cHl0aG9uLWxpYnMvcG91bHBlL2JlbmNobWFya3MucHk= 100644 --- a/python-libs/poulpe/benchmarks.py +++ b/python-libs/poulpe/benchmarks.py @@ -132,4 +132,24 @@ return c @property + def environment(self): + env = self._data.get('environment', {}) + for dimension, variants in sorted(self.all_dimensions.items()): + selected = self._selected_variants[dimension] + values = variants[selected] + var_env = values.get('environment') + if var_env is not None: + env.update(var_env) + return env + + @staticmethod + def apply_data_on_env(data_env, env): + new_env = env.copy() + for env_key, value in env.items(): + data_key = data_vars_key(value) + if data_key is not None: + new_env[env_key] = data_env.get_benchmark_input_vars(data_key) + return new_env + + @property def needed_vars(self): @@ -135,5 +155,10 @@ def needed_vars(self): - return set() + nvars = set() + for k, v in self.environment.items(): + key = data_vars_key(v) + if key is not None: + nvars.add(key) + return nvars class SimpleCommandBenchmark(Benchmark): @@ -193,6 +218,11 @@ data_env_path = os.path.abspath(data_env_path) shell_path = poulpe.bin_env_script(bin_env_path) + data_env = data_mod.get_data_env(data_env_path) + our_env = self.apply_data_on_env(data_env, self.environment) + env = os.environ.copy() + env.update(our_env) + with tempfile.NamedTemporaryFile('w') as tmp_result: time_cmd = [ shell_path, @@ -209,7 +239,6 @@ cwd = data_env_path if cmd.cwd is not None: cwd = os.path.join(cwd, cmd.cwd) - r = subprocess.run( time_cmd, cwd=cwd, @@ -213,6 +242,7 @@ r = subprocess.run( time_cmd, cwd=cwd, + env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) @@ -356,9 +386,14 @@ cfg_cwd = data_var(key) cwd = os.path.join(cwd, cfg_cwd) + data_env = data_mod.get_data_env(data_env_path) + our_env = self.apply_data_on_env(data_env, self.environment) + env = os.environ.copy() + env.update(our_env) + setup_script = self.get_var('hg-perf-ext.setup-script') if setup_script is not None: subprocess.check_call( setup_script, shell=True, cwd=cwd, @@ -359,9 +394,10 @@ setup_script = self.get_var('hg-perf-ext.setup-script') if setup_script is not None: subprocess.check_call( setup_script, shell=True, cwd=cwd, + env=env, executable='/bin/bash', ) @@ -400,6 +436,7 @@ raise errors.BenchmarkRunFailure( command=cmd, cwd=cwd, + env=env, return_code=r.returncode, stdout=r.stdout, stderr=r.stderr,