2 # -*- coding: utf-8 -*-
5 Command-line wrapper for the tracetool machinery.
8 __author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
9 __copyright__ = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
10 __license__ = "GPL version 2 or (at your option) any later version"
12 __maintainer__ = "Stefan Hajnoczi"
13 __email__ = "stefanha@redhat.com"
19 from tracetool import error_write, out, out_open
20 import tracetool.backend
21 import tracetool.format
26 def error_opt(msg = None):
28 error_write("Error: " + msg + "\n")
30 backend_descr = "\n".join([ " %-15s %s" % (n, d)
31 for n,d in tracetool.backend.get_list() ])
32 format_descr = "\n".join([ " %-15s %s" % (n, d)
33 for n,d in tracetool.format.get_list() ])
35 Usage: %(script)s --format=<format> --backends=<backends> [<options>] <trace-events> ... <output>
44 --help This help message.
45 --list-backends Print list of available backends.
46 --check-backends Check if the given backend is valid.
47 --binary <path> Full path to QEMU binary.
48 --target-type <type> QEMU emulator target type ('system' or 'user').
49 --target-name <name> QEMU emulator target name.
50 --group <name> Name of the event group
51 --probe-prefix <prefix> Prefix for dtrace probe names
52 (default: qemu-<target-type>-<target-name>).\
55 "backends" : backend_descr,
56 "formats" : format_descr,
68 long_opts = ["backends=", "format=", "help", "list-backends",
69 "check-backends", "group="]
70 long_opts += ["binary=", "target-type=", "target-name=", "probe-prefix="]
73 opts, args = getopt.getopt(args[1:], "", long_opts)
74 except getopt.GetoptError as err:
77 check_backends = False
89 elif opt == "--backends":
90 arg_backends = arg.split(",")
91 elif opt == "--group":
93 elif opt == "--format":
96 elif opt == "--list-backends":
97 public_backends = tracetool.backend.get_list(only_public = True)
98 out(", ".join([ b for b,_ in public_backends ]))
100 elif opt == "--check-backends":
101 check_backends = True
103 elif opt == "--binary":
105 elif opt == '--target-type':
107 elif opt == '--target-name':
109 elif opt == '--probe-prefix':
113 error_opt("unhandled option: %s" % opt)
115 if len(arg_backends) == 0:
116 error_opt("no backends specified")
119 for backend in arg_backends:
120 if not tracetool.backend.exists(backend):
124 if arg_group is None:
125 error_opt("group name is required")
127 if arg_format == "stap":
129 error_opt("--binary is required for SystemTAP tapset generator")
130 if probe_prefix is None and target_type is None:
131 error_opt("--target-type is required for SystemTAP tapset generator")
132 if probe_prefix is None and target_name is None:
133 error_opt("--target-name is required for SystemTAP tapset generator")
135 if probe_prefix is None:
136 probe_prefix = ".".join(["qemu", target_type, target_name])
139 error_opt("missing trace-events and output filepaths")
141 for arg in args[:-1]:
142 with open(arg, "r") as fh:
143 events.extend(tracetool.read_events(fh, arg))
148 tracetool.generate(events, arg_group, arg_format, arg_backends,
149 binary=binary, probe_prefix=probe_prefix)
150 except tracetool.TracetoolError as e:
153 if __name__ == "__main__":