python: Add a --silent-redirect option to gem5.

This complements the --redirect-stdout and --redirect-stderr options and
supresses the message about where those streams are being redirected
which print to the original stdout.

Usually this is very helpful since it lets you know where to look for
simulator output. If you're running gem5 in an automated environment
like our testing framework however, the file name is a random temp file
which will be deleted as soon as the test is finished running.

The --silent-redirect option can be used in these particular scenarios
to, for example, avoid lots and lots of useless lines in the test output
naming files that no longer exist.

Change-Id: If56b61567b3d98abd9cc9d9e9d661ea561be46f8
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/50588
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Gabe Black
2021-09-18 01:31:27 -07:00
parent b5ffa5418f
commit 0998e99131

View File

@@ -87,6 +87,8 @@ def parse_options():
help="Redirect stdout (& stderr, without -e) to file")
option('-e', "--redirect-stderr", action="store_true", default=False,
help="Redirect stderr to file")
option("--silent-redirect", action="store_true", default=False,
help="Suppress printing a message when redirecting stdout or stderr")
option("--stdout-file", metavar="FILE", default="simout",
help="Filename for -r redirection [Default: %default]")
option("--stderr-file", metavar="FILE", default="simerr",
@@ -247,14 +249,15 @@ def main(*args):
stdout_file = os.path.join(options.outdir, options.stdout_file)
stderr_file = os.path.join(options.outdir, options.stderr_file)
# Print redirection notices here before doing any redirection
if options.redirect_stdout and not options.redirect_stderr:
print("Redirecting stdout and stderr to", stdout_file)
else:
if options.redirect_stdout:
print("Redirecting stdout to", stdout_file)
if options.redirect_stderr:
print("Redirecting stderr to", stderr_file)
if not options.silent_redirect:
# Print redirection notices here before doing any redirection
if options.redirect_stdout and not options.redirect_stderr:
print("Redirecting stdout and stderr to", stdout_file)
else:
if options.redirect_stdout:
print("Redirecting stdout to", stdout_file)
if options.redirect_stderr:
print("Redirecting stderr to", stderr_file)
# Now redirect stdout/stderr as desired
if options.redirect_stdout: