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@linux.vnet.ibm.com"
21 from tracetool
import error_write
, out
22 import tracetool
.backend
23 import tracetool
.format
28 def error_opt(msg
= None):
30 error_write("Error: " + msg
+ "\n")
32 backend_descr
= "\n".join([ " %-15s %s" % (n
, d
)
33 for n
,d
in tracetool
.backend
.get_list() ])
34 format_descr
= "\n".join([ " %-15s %s" % (n
, d
)
35 for n
,d
in tracetool
.format
.get_list() ])
37 Usage: %(script)s --format=<format> --backends=<backends> [<options>]
46 --help This help message.
47 --list-backends Print list of available backends.
48 --check-backends Check if the given backend is valid.
49 --binary <path> Full path to QEMU binary.
50 --target-type <type> QEMU emulator target type ('system' or 'user').
51 --target-name <name> QEMU emulator target name.
52 --group <name> Name of the event group
53 --probe-prefix <prefix> Prefix for dtrace probe names
54 (default: qemu-<target-type>-<target-name>).\
57 "backends" : backend_descr
,
58 "formats" : format_descr
,
70 long_opts
= ["backends=", "format=", "help", "list-backends",
71 "check-backends", "group="]
72 long_opts
+= ["binary=", "target-type=", "target-name=", "probe-prefix="]
75 opts
, args
= getopt
.getopt(args
[1:], "", long_opts
)
76 except getopt
.GetoptError
as err
:
79 check_backends
= False
91 elif opt
== "--backends":
92 arg_backends
= arg
.split(",")
93 elif opt
== "--group":
95 elif opt
== "--format":
98 elif opt
== "--list-backends":
99 public_backends
= tracetool
.backend
.get_list(only_public
= True)
100 out(", ".join([ b
for b
,_
in public_backends
]))
102 elif opt
== "--check-backends":
103 check_backends
= True
105 elif opt
== "--binary":
107 elif opt
== '--target-type':
109 elif opt
== '--target-name':
111 elif opt
== '--probe-prefix':
115 error_opt("unhandled option: %s" % opt
)
117 if len(arg_backends
) == 0:
118 error_opt("no backends specified")
121 for backend
in arg_backends
:
122 if not tracetool
.backend
.exists(backend
):
126 if arg_group
is None:
127 error_opt("group name is required")
129 if arg_format
== "stap":
131 error_opt("--binary is required for SystemTAP tapset generator")
132 if probe_prefix
is None and target_type
is None:
133 error_opt("--target-type is required for SystemTAP tapset generator")
134 if probe_prefix
is None and target_name
is None:
135 error_opt("--target-name is required for SystemTAP tapset generator")
137 if probe_prefix
is None:
138 probe_prefix
= ".".join(["qemu", target_type
, target_name
])
141 error_opt("missing trace-events filepath")
144 with
open(arg
, "r") as fh
:
145 events
.extend(tracetool
.read_events(fh
))
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__":