2012-04-03 22:47:39 +04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- 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"
|
|
|
|
__email__ = "stefanha@linux.vnet.ibm.com"
|
|
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import getopt
|
2016-10-04 16:35:59 +03:00
|
|
|
import os.path
|
|
|
|
import re
|
2012-04-03 22:47:39 +04:00
|
|
|
|
|
|
|
from tracetool import error_write, out
|
|
|
|
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("""\
|
2014-05-27 17:02:14 +04:00
|
|
|
Usage: %(script)s --format=<format> --backends=<backends> [<options>]
|
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.
|
2012-04-03 22:48:12 +04:00
|
|
|
--binary <path> Full path to QEMU binary.
|
|
|
|
--target-type <type> QEMU emulator target type ('system' or 'user').
|
2013-06-04 16:45:26 +04:00
|
|
|
--target-name <name> QEMU emulator target name.
|
2012-04-03 22:48:12 +04:00
|
|
|
--probe-prefix <prefix> Prefix for dtrace probe names
|
2013-06-04 16:45:26 +04:00
|
|
|
(default: qemu-<target-type>-<target-name>).\
|
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)
|
|
|
|
|
2016-10-04 16:35:59 +03:00
|
|
|
def make_group_name(filename):
|
|
|
|
dirname = os.path.realpath(os.path.dirname(filename))
|
|
|
|
basedir = os.path.join(os.path.dirname(__file__), os.pardir)
|
|
|
|
basedir = os.path.realpath(os.path.abspath(basedir))
|
|
|
|
dirname = dirname[len(basedir) + 1:]
|
|
|
|
|
|
|
|
if dirname == "":
|
|
|
|
return "common"
|
2016-10-13 21:29:30 +03:00
|
|
|
return re.sub(r"[^A-Za-z0-9]", "_", dirname)
|
2012-04-03 22:47:39 +04:00
|
|
|
|
|
|
|
def main(args):
|
|
|
|
global _SCRIPT
|
|
|
|
_SCRIPT = args[0]
|
|
|
|
|
2014-05-27 17:02:14 +04:00
|
|
|
long_opts = ["backends=", "format=", "help", "list-backends",
|
|
|
|
"check-backends"]
|
|
|
|
long_opts += ["binary=", "target-type=", "target-name=", "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 = ""
|
2012-04-03 22:48:12 +04:00
|
|
|
binary = None
|
|
|
|
target_type = None
|
2013-06-04 16:45:26 +04:00
|
|
|
target_name = None
|
2012-04-03 22:48:12 +04:00
|
|
|
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(",")
|
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 == '--target-type':
|
|
|
|
target_type = arg
|
2013-06-04 16:45:26 +04:00
|
|
|
elif opt == '--target-name':
|
|
|
|
target_name = arg
|
2012-04-03 22:48:12 +04:00
|
|
|
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
|
|
|
|
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 and target_type is None:
|
|
|
|
error_opt("--target-type is required for SystemTAP tapset generator")
|
2013-06-04 16:45:26 +04:00
|
|
|
if probe_prefix is None and target_name is None:
|
|
|
|
error_opt("--target-name is required for SystemTAP tapset generator")
|
2012-04-03 22:48:12 +04:00
|
|
|
|
|
|
|
if probe_prefix is None:
|
2014-05-27 17:02:14 +04:00
|
|
|
probe_prefix = ".".join(["qemu", target_type, target_name])
|
2012-04-03 22:48:12 +04:00
|
|
|
|
2016-10-04 16:35:58 +03:00
|
|
|
if len(args) != 1:
|
|
|
|
error_opt("missing trace-events filepath")
|
|
|
|
with open(args[0], "r") as fh:
|
|
|
|
events = tracetool.read_events(fh)
|
2016-10-04 16:35:57 +03:00
|
|
|
|
2016-10-04 16:35:59 +03:00
|
|
|
group = make_group_name(args[0])
|
|
|
|
|
2012-04-03 22:47:39 +04:00
|
|
|
try:
|
2016-10-04 16:35:59 +03:00
|
|
|
tracetool.generate(events, 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)
|