]>
git.proxmox.com Git - mirror_qemu.git/blob - scripts/tracetool.py
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 (required for 'stap' backend).
48 --group <name> Name of the event group.
49 --probe-prefix <prefix> Prefix for dtrace probe names (required for 'stap' backend).
52 "backends" : backend_descr
,
53 "formats" : format_descr
,
65 long_opts
= ["backends=", "format=", "help", "list-backends",
66 "check-backends", "group="]
67 long_opts
+= ["binary=", "probe-prefix="]
70 opts
, args
= getopt
.getopt(args
[1:], "", long_opts
)
71 except getopt
.GetoptError
as err
:
74 check_backends
= False
84 elif opt
== "--backends":
85 arg_backends
= arg
.split(",")
86 elif opt
== "--group":
88 elif opt
== "--format":
91 elif opt
== "--list-backends":
92 public_backends
= tracetool
.backend
.get_list(only_public
= True)
93 out(", ".join([ b
for b
,_
in public_backends
]))
95 elif opt
== "--check-backends":
98 elif opt
== "--binary":
100 elif opt
== '--probe-prefix':
104 error_opt("unhandled option: %s" % opt
)
106 if len(arg_backends
) == 0:
107 error_opt("no backends specified")
110 for backend
in arg_backends
:
111 if not tracetool
.backend
.exists(backend
):
115 if arg_group
is None:
116 error_opt("group name is required")
118 if arg_format
== "stap":
120 error_opt("--binary is required for SystemTAP tapset generator")
121 if probe_prefix
is None:
122 error_opt("--probe-prefix is required for SystemTAP tapset generator")
125 error_opt("missing trace-events and output filepaths")
127 for arg
in args
[:-1]:
128 with
open(arg
, "r") as fh
:
129 events
.extend(tracetool
.read_events(fh
, arg
))
134 tracetool
.generate(events
, arg_group
, arg_format
, arg_backends
,
135 binary
=binary
, probe_prefix
=probe_prefix
)
136 except tracetool
.TracetoolError
as e
:
139 if __name__
== "__main__":