Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show env in debug info #280

Merged
merged 1 commit into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions rebench/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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')
Expand Down
62 changes: 38 additions & 24 deletions rebench/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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()
Expand All @@ -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

Expand Down Expand Up @@ -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)

Expand All @@ -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):
Expand All @@ -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)


Expand All @@ -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


Expand Down
Loading