summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@redhat.com>2020-08-27 15:29:12 +0100
committerStefan Hajnoczi <stefanha@redhat.com>2021-01-04 14:24:58 +0000
commitc05012a365c2d7d42d205b1efa895bf2144bab88 (patch)
treeb7a25025de22f351f41d84dfdf621d16dc87fa3b /scripts
parent6745c8a01f759b64d3c4cd1e0a69bb793cead268 (diff)
tracetool: add output filename command-line argument
The tracetool.py script writes to stdout. This means the output filename is not available to the script. Add the output filename to the command-line so that the script has access to the filename. This also simplifies the tracetool.py invocation. It's no longer necessary to use meson's custom_build(capture : true) to save output. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Message-Id: <20200827142915.108730-2-stefanha@redhat.com>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/tracetool.py12
-rw-r--r--scripts/tracetool/__init__.py18
2 files changed, 23 insertions, 7 deletions
diff --git a/scripts/tracetool.py b/scripts/tracetool.py
index 31146242b7..ab7653a5ce 100755
--- a/scripts/tracetool.py
+++ b/scripts/tracetool.py
@@ -16,7 +16,7 @@ __email__ = "stefanha@redhat.com"
import sys
import getopt
-from tracetool import error_write, out
+from tracetool import error_write, out, out_open
import tracetool.backend
import tracetool.format
@@ -32,7 +32,7 @@ def error_opt(msg = None):
format_descr = "\n".join([ " %-15s %s" % (n, d)
for n,d in tracetool.format.get_list() ])
error_write("""\
-Usage: %(script)s --format=<format> --backends=<backends> [<options>]
+Usage: %(script)s --format=<format> --backends=<backends> [<options>] <trace-events> ... <output>
Backends:
%(backends)s
@@ -135,13 +135,15 @@ def main(args):
if probe_prefix is None:
probe_prefix = ".".join(["qemu", target_type, target_name])
- if len(args) < 1:
- error_opt("missing trace-events filepath")
+ if len(args) < 2:
+ error_opt("missing trace-events and output filepaths")
events = []
- for arg in args:
+ for arg in args[:-1]:
with open(arg, "r") as fh:
events.extend(tracetool.read_events(fh, arg))
+ out_open(args[-1])
+
try:
tracetool.generate(events, arg_group, arg_format, arg_backends,
binary=binary, probe_prefix=probe_prefix)
diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py
index 3ee54be223..a6013389a0 100644
--- a/scripts/tracetool/__init__.py
+++ b/scripts/tracetool/__init__.py
@@ -31,14 +31,28 @@ def error(*lines):
sys.exit(1)
+out_filename = '<none>'
+out_fobj = sys.stdout
+
+def out_open(filename):
+ global out_filename, out_fobj
+ out_filename = filename
+ out_fobj = open(filename, 'wt')
+
def out(*lines, **kwargs):
"""Write a set of output lines.
You can use kwargs as a shorthand for mapping variables when formatting all
the strings in lines.
+
+ The 'out_filename' kwarg is automatically added with the output filename.
"""
- lines = [ l % kwargs for l in lines ]
- sys.stdout.writelines("\n".join(lines) + "\n")
+ output = []
+ for l in lines:
+ kwargs['out_filename'] = out_filename
+ output.append(l % kwargs)
+
+ out_fobj.writelines("\n".join(output) + "\n")
# We only want to allow standard C types or fixed sized
# integer types. We don't want QEMU specific types