summaryrefslogtreecommitdiffstats
path: root/scripts/tracetool
diff options
context:
space:
mode:
authorStefan Hajnoczi2020-08-27 16:29:12 +0200
committerStefan Hajnoczi2021-01-04 15:24:58 +0100
commitc05012a365c2d7d42d205b1efa895bf2144bab88 (patch)
treeb7a25025de22f351f41d84dfdf621d16dc87fa3b /scripts/tracetool
parenttrace: Send "-d trace:help" output to stdout (diff)
downloadqemu-c05012a365c2d7d42d205b1efa895bf2144bab88.tar.gz
qemu-c05012a365c2d7d42d205b1efa895bf2144bab88.tar.xz
qemu-c05012a365c2d7d42d205b1efa895bf2144bab88.zip
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/tracetool')
-rw-r--r--scripts/tracetool/__init__.py18
1 files changed, 16 insertions, 2 deletions
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