2020-01-30 19:32:25 +03:00
|
|
|
#!/usr/bin/env python3
|
2012-04-03 22:47:39 +04:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
Command-line wrapper for the tracetool machinery.
|
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
|
2014-05-27 17:02:14 +04:00
|
|
|
__copyright__ = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
|
2012-04-03 22:47:39 +04:00
|
|
|
__license__ = "GPL version 2 or (at your option) any later version"
|
|
|
|
|
|
|
|
__maintainer__ = "Stefan Hajnoczi"
|
2020-05-11 11:28:16 +03:00
|
|
|
__email__ = "stefanha@redhat.com"
|
2012-04-03 22:47:39 +04:00
|
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import getopt
|
|
|
|
|
2020-08-27 17:29:12 +03:00
|
|
|
from tracetool import error_write, out, out_open
|
2012-04-03 22:47:39 +04:00
|
|
|
import tracetool.backend
|
|
|
|
import tracetool.format
|
|
|
|
|
|
|
|
|
|
|
|
_SCRIPT = ""
|
|
|
|
|
|
|
|
def error_opt(msg = None):
|
|
|
|
if msg is not None:
|
|
|
|
error_write("Error: " + msg + "\n")
|
|
|
|
|
|
|
|
backend_descr = "\n".join([ " %-15s %s" % (n, d)
|
|
|
|
for n,d in tracetool.backend.get_list() ])
|
|
|
|
format_descr = "\n".join([ " %-15s %s" % (n, d)
|
|
|
|
for n,d in tracetool.format.get_list() ])
|
|
|
|
error_write("""\
|
2020-08-27 17:29:12 +03:00
|
|
|
Usage: %(script)s --format=<format> --backends=<backends> [<options>] <trace-events> ... <output>
|
2012-04-03 22:47:39 +04:00
|
|
|
|
|
|
|
Backends:
|
|
|
|
%(backends)s
|
|
|
|
|
|
|
|
Formats:
|
|
|
|
%(formats)s
|
|
|
|
|
|
|
|
Options:
|
|
|
|
--help This help message.
|
|
|
|
--list-backends Print list of available backends.
|
2014-05-27 17:02:14 +04:00
|
|
|
--check-backends Check if the given backend is valid.
|
2024-01-08 20:13:55 +03:00
|
|
|
--binary <path> Full path to QEMU binary (required for 'stap' backend).
|
|
|
|
--group <name> Name of the event group.
|
|
|
|
--probe-prefix <prefix> Prefix for dtrace probe names (required for 'stap' backend).
|
2012-04-03 22:47:39 +04:00
|
|
|
""" % {
|
|
|
|
"script" : _SCRIPT,
|
|
|
|
"backends" : backend_descr,
|
|
|
|
"formats" : format_descr,
|
|
|
|
})
|
|
|
|
|
|
|
|
if msg is None:
|
|
|
|
sys.exit(0)
|
|
|
|
else:
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
def main(args):
|
|
|
|
global _SCRIPT
|
|
|
|
_SCRIPT = args[0]
|
|
|
|
|
2014-05-27 17:02:14 +04:00
|
|
|
long_opts = ["backends=", "format=", "help", "list-backends",
|
2017-01-25 19:14:14 +03:00
|
|
|
"check-backends", "group="]
|
2024-01-08 20:13:55 +03:00
|
|
|
long_opts += ["binary=", "probe-prefix="]
|
2012-04-03 22:47:39 +04:00
|
|
|
|
|
|
|
try:
|
|
|
|
opts, args = getopt.getopt(args[1:], "", long_opts)
|
2015-12-18 10:52:43 +03:00
|
|
|
except getopt.GetoptError as err:
|
2012-04-03 22:47:39 +04:00
|
|
|
error_opt(str(err))
|
|
|
|
|
2014-05-27 17:02:14 +04:00
|
|
|
check_backends = False
|
|
|
|
arg_backends = []
|
2012-04-03 22:47:39 +04:00
|
|
|
arg_format = ""
|
2017-01-25 19:14:14 +03:00
|
|
|
arg_group = None
|
2012-04-03 22:48:12 +04:00
|
|
|
binary = None
|
|
|
|
probe_prefix = None
|
2012-04-03 22:47:39 +04:00
|
|
|
for opt, arg in opts:
|
|
|
|
if opt == "--help":
|
|
|
|
error_opt()
|
|
|
|
|
2014-05-27 17:02:14 +04:00
|
|
|
elif opt == "--backends":
|
|
|
|
arg_backends = arg.split(",")
|
2017-01-25 19:14:14 +03:00
|
|
|
elif opt == "--group":
|
|
|
|
arg_group = arg
|
2012-04-03 22:47:39 +04:00
|
|
|
elif opt == "--format":
|
|
|
|
arg_format = arg
|
|
|
|
|
|
|
|
elif opt == "--list-backends":
|
2013-03-05 17:47:26 +04:00
|
|
|
public_backends = tracetool.backend.get_list(only_public = True)
|
|
|
|
out(", ".join([ b for b,_ in public_backends ]))
|
2012-04-03 22:47:39 +04:00
|
|
|
sys.exit(0)
|
2014-05-27 17:02:14 +04:00
|
|
|
elif opt == "--check-backends":
|
|
|
|
check_backends = True
|
2012-04-03 22:47:39 +04:00
|
|
|
|
2012-04-03 22:48:12 +04:00
|
|
|
elif opt == "--binary":
|
|
|
|
binary = arg
|
|
|
|
elif opt == '--probe-prefix':
|
|
|
|
probe_prefix = arg
|
|
|
|
|
2012-04-03 22:47:39 +04:00
|
|
|
else:
|
|
|
|
error_opt("unhandled option: %s" % opt)
|
|
|
|
|
2014-05-27 17:02:14 +04:00
|
|
|
if len(arg_backends) == 0:
|
|
|
|
error_opt("no backends specified")
|
2012-04-03 22:47:39 +04:00
|
|
|
|
2014-05-27 17:02:14 +04:00
|
|
|
if check_backends:
|
|
|
|
for backend in arg_backends:
|
|
|
|
if not tracetool.backend.exists(backend):
|
|
|
|
sys.exit(1)
|
|
|
|
sys.exit(0)
|
2012-04-03 22:47:39 +04:00
|
|
|
|
2017-01-25 19:14:14 +03:00
|
|
|
if arg_group is None:
|
|
|
|
error_opt("group name is required")
|
|
|
|
|
2012-04-03 22:48:12 +04:00
|
|
|
if arg_format == "stap":
|
|
|
|
if binary is None:
|
|
|
|
error_opt("--binary is required for SystemTAP tapset generator")
|
|
|
|
if probe_prefix is None:
|
2024-01-08 20:13:55 +03:00
|
|
|
error_opt("--probe-prefix is required for SystemTAP tapset generator")
|
2012-04-03 22:48:12 +04:00
|
|
|
|
2020-08-27 17:29:12 +03:00
|
|
|
if len(args) < 2:
|
|
|
|
error_opt("missing trace-events and output filepaths")
|
2017-01-25 19:14:15 +03:00
|
|
|
events = []
|
2020-08-27 17:29:12 +03:00
|
|
|
for arg in args[:-1]:
|
2017-01-25 19:14:15 +03:00
|
|
|
with open(arg, "r") as fh:
|
2018-03-06 18:46:50 +03:00
|
|
|
events.extend(tracetool.read_events(fh, arg))
|
2016-10-04 16:35:57 +03:00
|
|
|
|
2020-08-27 17:29:12 +03:00
|
|
|
out_open(args[-1])
|
|
|
|
|
2012-04-03 22:47:39 +04:00
|
|
|
try:
|
2017-01-25 19:14:14 +03:00
|
|
|
tracetool.generate(events, arg_group, arg_format, arg_backends,
|
2014-05-27 17:02:14 +04:00
|
|
|
binary=binary, probe_prefix=probe_prefix)
|
2015-12-18 10:52:43 +03:00
|
|
|
except tracetool.TracetoolError as e:
|
2012-04-03 22:47:39 +04:00
|
|
|
error_opt(str(e))
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main(sys.argv)
|