]> git.proxmox.com Git - mirror_qemu.git/blame - scripts/tracetool.py
rbd: Clean up qemu_rbd_create()'s detour through QemuOpts
[mirror_qemu.git] / scripts / tracetool.py
CommitLineData
650ab98d
LV
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4"""
5Command-line wrapper for the tracetool machinery.
6"""
7
8__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
5b808275 9__copyright__ = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
650ab98d
LV
10__license__ = "GPL version 2 or (at your option) any later version"
11
12__maintainer__ = "Stefan Hajnoczi"
13__email__ = "stefanha@linux.vnet.ibm.com"
14
15
16import sys
17import getopt
80dd5c49
DB
18import os.path
19import re
650ab98d
LV
20
21from tracetool import error_write, out
22import tracetool.backend
23import tracetool.format
24
25
26_SCRIPT = ""
27
28def error_opt(msg = None):
29 if msg is not None:
30 error_write("Error: " + msg + "\n")
31
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() ])
36 error_write("""\
5b808275 37Usage: %(script)s --format=<format> --backends=<backends> [<options>]
650ab98d
LV
38
39Backends:
40%(backends)s
41
42Formats:
43%(formats)s
44
45Options:
46 --help This help message.
47 --list-backends Print list of available backends.
5b808275 48 --check-backends Check if the given backend is valid.
52ef093a
LV
49 --binary <path> Full path to QEMU binary.
50 --target-type <type> QEMU emulator target type ('system' or 'user').
b9a7b74f 51 --target-name <name> QEMU emulator target name.
2098c56a 52 --group <name> Name of the event group
52ef093a 53 --probe-prefix <prefix> Prefix for dtrace probe names
b9a7b74f 54 (default: qemu-<target-type>-<target-name>).\
650ab98d
LV
55""" % {
56 "script" : _SCRIPT,
57 "backends" : backend_descr,
58 "formats" : format_descr,
59 })
60
61 if msg is None:
62 sys.exit(0)
63 else:
64 sys.exit(1)
65
650ab98d
LV
66def main(args):
67 global _SCRIPT
68 _SCRIPT = args[0]
69
5b808275 70 long_opts = ["backends=", "format=", "help", "list-backends",
2098c56a 71 "check-backends", "group="]
5b808275 72 long_opts += ["binary=", "target-type=", "target-name=", "probe-prefix="]
650ab98d
LV
73
74 try:
75 opts, args = getopt.getopt(args[1:], "", long_opts)
86b227d9 76 except getopt.GetoptError as err:
650ab98d
LV
77 error_opt(str(err))
78
5b808275
LV
79 check_backends = False
80 arg_backends = []
650ab98d 81 arg_format = ""
2098c56a 82 arg_group = None
52ef093a
LV
83 binary = None
84 target_type = None
b9a7b74f 85 target_name = None
52ef093a 86 probe_prefix = None
650ab98d
LV
87 for opt, arg in opts:
88 if opt == "--help":
89 error_opt()
90
5b808275
LV
91 elif opt == "--backends":
92 arg_backends = arg.split(",")
2098c56a
DB
93 elif opt == "--group":
94 arg_group = arg
650ab98d
LV
95 elif opt == "--format":
96 arg_format = arg
97
98 elif opt == "--list-backends":
93fba161
LV
99 public_backends = tracetool.backend.get_list(only_public = True)
100 out(", ".join([ b for b,_ in public_backends ]))
650ab98d 101 sys.exit(0)
5b808275
LV
102 elif opt == "--check-backends":
103 check_backends = True
650ab98d 104
52ef093a
LV
105 elif opt == "--binary":
106 binary = arg
107 elif opt == '--target-type':
108 target_type = arg
b9a7b74f
PB
109 elif opt == '--target-name':
110 target_name = arg
52ef093a
LV
111 elif opt == '--probe-prefix':
112 probe_prefix = arg
113
650ab98d
LV
114 else:
115 error_opt("unhandled option: %s" % opt)
116
5b808275
LV
117 if len(arg_backends) == 0:
118 error_opt("no backends specified")
650ab98d 119
5b808275
LV
120 if check_backends:
121 for backend in arg_backends:
122 if not tracetool.backend.exists(backend):
123 sys.exit(1)
124 sys.exit(0)
650ab98d 125
2098c56a
DB
126 if arg_group is None:
127 error_opt("group name is required")
128
52ef093a
LV
129 if arg_format == "stap":
130 if binary is None:
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")
b9a7b74f
PB
134 if probe_prefix is None and target_name is None:
135 error_opt("--target-name is required for SystemTAP tapset generator")
52ef093a
LV
136
137 if probe_prefix is None:
5b808275 138 probe_prefix = ".".join(["qemu", target_type, target_name])
52ef093a 139
0ab8ed18 140 if len(args) < 1:
0bc6484d 141 error_opt("missing trace-events filepath")
0ab8ed18
DB
142 events = []
143 for arg in args:
144 with open(arg, "r") as fh:
145 events.extend(tracetool.read_events(fh))
9096b78a 146
650ab98d 147 try:
2098c56a 148 tracetool.generate(events, arg_group, arg_format, arg_backends,
5b808275 149 binary=binary, probe_prefix=probe_prefix)
86b227d9 150 except tracetool.TracetoolError as e:
650ab98d
LV
151 error_opt(str(e))
152
153if __name__ == "__main__":
154 main(sys.argv)