From 32148c7a8dab43f33fd603937bd947e377ff72a8 Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Sat, 18 Jan 2025 23:16:49 +0000 Subject: [PATCH] =?UTF-8?q?Output=20env=20if=20it=E2=80=99s=20set=20in=20d?= =?UTF-8?q?ebug=20info?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - this also makes sure that the location that’s given to run() is explicitly passed for output Signed-off-by: Stefan Marr --- rebench/executor.py | 22 ++++++++-------- rebench/ui.py | 62 +++++++++++++++++++++++++++------------------ 2 files changed, 50 insertions(+), 34 deletions(-) diff --git a/rebench/executor.py b/rebench/executor.py index bad1e3e3..994b2bfa 100644 --- a/rebench/executor.py +++ b/rebench/executor.py @@ -531,18 +531,20 @@ def _generate_data_point(self, cmdline, gauge_adapter, run_id, output = "" try: - self.ui.debug_output_info("{ind}Starting run\n", run_id, cmdline) - - def _keep_alive(seconds): - self.ui.warning( - "Keep alive, current job runs for %dmin\n" % (seconds / 60), run_id, cmdline) - location = run_id.location if location: location = os.path.expanduser(location) + env = add_denoise_python_path_to_env(run_id.env) + + self.ui.debug_output_info("{ind}Starting run\n", run_id, cmdline, location, env) + + def _keep_alive(seconds): + self.ui.warning( + "Keep alive, current job runs for %dmin\n" % (seconds / 60), + run_id, cmdline, location, env) (return_code, output, _) = subprocess_timeout.run( - cmdline, env=add_denoise_python_path_to_env(run_id.env), + cmdline, env=env, cwd=location, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True, verbose=self.debug, timeout=run_id.max_invocation_time, @@ -557,7 +559,7 @@ def _keep_alive(seconds): + "{ind}{ind}File name: %s\n") % (err.strerror, err.filename) else: msg = str(err) - self.ui.error(msg, run_id, cmdline) + self.ui.error(msg, run_id, cmdline, location, env) run_id.report_run_failed(cmdline, 0, output) return True @@ -568,7 +570,7 @@ def _keep_alive(seconds): + "{ind}Return code: %d\n" + "{ind}{ind}%s.\n") % ( run_id.benchmark.suite.executor.name, return_code, output.strip()) - self.ui.error(msg, run_id, cmdline) + self.ui.error(msg, run_id, cmdline, location, env) run_id.report_run_failed(cmdline, return_code, output) run_id.executable_missing = True return True @@ -591,7 +593,7 @@ def _keep_alive(seconds): else: msg = "{ind}Run failed. Return code: %d\n" % return_code - self.ui.error(msg, run_id, cmdline) + self.ui.error(msg, run_id, cmdline, location, env) if output and output.strip(): lines = escape_braces(output).split('\n') diff --git a/rebench/ui.py b/rebench/ui.py index 3321c3d7..4373ba79 100644 --- a/rebench/ui.py +++ b/rebench/ui.py @@ -21,10 +21,14 @@ from io import StringIO from os import getcwd +from typing import Optional, TYPE_CHECKING from humanfriendly.terminal import terminal_supports_colors, ansi_wrap, auto_encode from humanfriendly.terminal.spinners import Spinner +if TYPE_CHECKING: + from .model.run_id import RunId + _DETAIL_INDENT = " " _ERASE_LINE = "\r\x1b[2K" @@ -42,6 +46,7 @@ def __init__(self): self._prev_run_id = None self._prev_cmd = None self._prev_cwd = None + self._prev_env = None self._progress_spinner = None self._need_to_erase_spinner = False self._error_once_cache = set() @@ -64,7 +69,8 @@ def step_spinner(self, completed_runs, label=None): self._progress_spinner.stream.flush() self._need_to_erase_spinner = self._progress_spinner.interactive - def _prepare_details(self, run_id, cmd, cwd): + def _prepare_details(self, run_id: Optional["RunId"], + cmd: Optional[str], cwd: Optional[str], env: Optional[dict[str, str]]): if not run_id and not cmd: return None @@ -92,14 +98,22 @@ def _prepare_details(self, run_id, cmd, cwd): else: text += _DETAIL_INDENT + "cwd: " + getcwd() + "\n" + if env: + text += _DETAIL_INDENT + "env:\n" + for k, v in env.items(): + text += f'{_DETAIL_INDENT}{_DETAIL_INDENT}{k}="{escape_braces(v)}"\n' + self._prev_run_id = run_id self._prev_cmd = cmd self._prev_cwd = cwd + self._prev_env = env return text - def _output_detail_header(self, run_id, cmd, cwd): - text = self._prepare_details(run_id, cmd, cwd) + def _output_detail_header(self, run_id: Optional["RunId"], + cmd: Optional[str], cwd: Optional[str], + env: Optional[dict[str, str]]): + text = self._prepare_details(run_id, cmd, cwd, env) if text: self._output(text, None) @@ -125,12 +139,12 @@ def _output(self, text, color, *args, **kw): self._output_on_stream(sys.stdout, sys.stdout, text, color, *args, **kw) sys.stdout.flush() - def warning(self, text, run_id=None, cmd=None, cwd=None, **kw): - self._output_detail_header(run_id, cmd, cwd) + def warning(self, text, run_id=None, cmd=None, cwd=None, env=None, **kw): + self._output_detail_header(run_id, cmd, cwd, env) self._output(text, "magenta", **kw) - def error(self, text, run_id=None, cmd=None, cwd=None, **kw): - self._output_detail_header(run_id, cmd, cwd) + def error(self, text, run_id=None, cmd=None, cwd=None, env=None, **kw): + self._output_detail_header(run_id, cmd, cwd, env) self._output(text, "red", **kw) def _is_first_error_with(self, text): @@ -139,33 +153,33 @@ def _is_first_error_with(self, text): return True return False - def error_once(self, text, run_id=None, cmd=None, cwd=None, **kw): + def error_once(self, text, run_id=None, cmd=None, cwd=None, env=None, **kw): stream = StringIO("") self._output_on_stream(stream, sys.stdout, text, "red", **kw) stream_str = stream.getvalue() if self._is_first_error_with(stream_str): - self._output_detail_header(run_id, cmd, cwd) + self._output_detail_header(run_id, cmd, cwd, env) self._output(text, "red", **kw) - def verbose_output_info(self, text, run_id=None, cmd=None, cwd=None, **kw): + def verbose_output_info(self, text, run_id=None, cmd=None, cwd=None, env=None, **kw): if self._verbose: - self._output_detail_header(run_id, cmd, cwd) + self._output_detail_header(run_id, cmd, cwd, env) self._output(text, None, faint=True, **kw) - def verbose_error_info(self, text, run_id=None, cmd=None, cwd=None, **kw): + def verbose_error_info(self, text, run_id=None, cmd=None, cwd=None, env=None, **kw): if self._verbose: - self._output_detail_header(run_id, cmd, cwd) + self._output_detail_header(run_id, cmd, cwd, env) self._output(text, "red", faint=True, **kw) - def debug_output_info(self, text, run_id=None, cmd=None, cwd=None, **kw): + def debug_output_info(self, text, run_id=None, cmd=None, cwd=None, env=None, **kw): if self._debug: - self._output_detail_header(run_id, cmd, cwd) + self._output_detail_header(run_id, cmd, cwd, env) self._output(text, None, faint=True, **kw) - def debug_error_info(self, text, run_id=None, cmd=None, cwd=None, **kw): + def debug_error_info(self, text, run_id=None, cmd=None, cwd=None, env=None, **kw): if self._debug: - self._output_detail_header(run_id, cmd, cwd) + self._output_detail_header(run_id, cmd, cwd, env) self._output(text, "red", faint=True, **kw) @@ -186,25 +200,25 @@ def step_spinner(self, completed_runs, label=None): def output(self, text, **kw): pass - def warning(self, text, run_id=None, cmd=None, cwd=None, **kw): + def warning(self, text, run_id=None, cmd=None, cwd=None, env=None, **kw): pass - def error(self, text, run_id=None, cmd=None, cwd=None, **kw): + def error(self, text, run_id=None, cmd=None, cwd=None, env=None, **kw): pass - def error_once(self, text, run_id=None, cmd=None, cwd=None, **kw): + def error_once(self, text, run_id=None, cmd=None, cwd=None, env=None, **kw): pass - def verbose_output_info(self, text, run_id=None, cmd=None, cwd=None, **kw): + def verbose_output_info(self, text, run_id=None, cmd=None, cwd=None, env=None, **kw): pass - def verbose_error_info(self, text, run_id=None, cmd=None, cwd=None, **kw): + def verbose_error_info(self, text, run_id=None, cmd=None, cwd=None, env=None, **kw): pass - def debug_output_info(self, text, run_id=None, cmd=None, cwd=None, **kw): + def debug_output_info(self, text, run_id=None, cmd=None, cwd=None, env=None, **kw): pass - def debug_error_info(self, text, run_id=None, cmd=None, cwd=None, **kw): + def debug_error_info(self, text, run_id=None, cmd=None, cwd=None, env=None, **kw): pass