]> git.proxmox.com Git - mirror_qemu.git/blame - scripts/tracetool.py
Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20210709' into...
[mirror_qemu.git] / scripts / tracetool.py
CommitLineData
3d004a37 1#!/usr/bin/env python3
650ab98d
LV
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"
f892b494 13__email__ = "stefanha@redhat.com"
650ab98d
LV
14
15
16import sys
17import getopt
18
c05012a3 19from tracetool import error_write, out, out_open
650ab98d
LV
20import tracetool.backend
21import tracetool.format
22
23
24_SCRIPT = ""
25
26def error_opt(msg = None):
27 if msg is not None:
28 error_write("Error: " + msg + "\n")
29
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() ])
34 error_write("""\
c05012a3 35Usage: %(script)s --format=<format> --backends=<backends> [<options>] <trace-events> ... <output>
650ab98d
LV
36
37Backends:
38%(backends)s
39
40Formats:
41%(formats)s
42
43Options:
44 --help This help message.
45 --list-backends Print list of available backends.
5b808275 46 --check-backends Check if the given backend is valid.
52ef093a
LV
47 --binary <path> Full path to QEMU binary.
48 --target-type <type> QEMU emulator target type ('system' or 'user').
b9a7b74f 49 --target-name <name> QEMU emulator target name.
2098c56a 50 --group <name> Name of the event group
52ef093a 51 --probe-prefix <prefix> Prefix for dtrace probe names
b9a7b74f 52 (default: qemu-<target-type>-<target-name>).\
650ab98d
LV
53""" % {
54 "script" : _SCRIPT,
55 "backends" : backend_descr,
56 "formats" : format_descr,
57 })
58
59 if msg is None:
60 sys.exit(0)
61 else:
62 sys.exit(1)
63
650ab98d
LV
64def main(args):
65 global _SCRIPT
66 _SCRIPT = args[0]
67
5b808275 68 long_opts = ["backends=", "format=", "help", "list-backends",
2098c56a 69 "check-backends", "group="]
5b808275 70 long_opts += ["binary=", "target-type=", "target-name=", "probe-prefix="]
650ab98d
LV
71
72 try:
73 opts, args = getopt.getopt(args[1:], "", long_opts)
86b227d9 74 except getopt.GetoptError as err:
650ab98d
LV
75 error_opt(str(err))
76
5b808275
LV
77 check_backends = False
78 arg_backends = []
650ab98d 79 arg_format = ""
2098c56a 80 arg_group = None
52ef093a
LV
81 binary = None
82 target_type = None
b9a7b74f 83 target_name = None
52ef093a 84 probe_prefix = None
650ab98d
LV
85 for opt, arg in opts:
86 if opt == "--help":
87 error_opt()
88
5b808275
LV
89 elif opt == "--backends":
90 arg_backends = arg.split(",")
2098c56a
DB
91 elif opt == "--group":
92 arg_group = arg
650ab98d
LV
93 elif opt == "--format":
94 arg_format = arg
95
96 elif opt == "--list-backends":
93fba161
LV
97 public_backends = tracetool.backend.get_list(only_public = True)
98 out(", ".join([ b for b,_ in public_backends ]))
650ab98d 99 sys.exit(0)
5b808275
LV
100 elif opt == "--check-backends":
101 check_backends = True
650ab98d 102
52ef093a
LV
103 elif opt == "--binary":
104 binary = arg
105 elif opt == '--target-type':
106 target_type = arg
b9a7b74f
PB
107 elif opt == '--target-name':
108 target_name = arg
52ef093a
LV
109 elif opt == '--probe-prefix':
110 probe_prefix = arg
111
650ab98d
LV
112 else:
113 error_opt("unhandled option: %s" % opt)
114
5b808275
LV
115 if len(arg_backends) == 0:
116 error_opt("no backends specified")
650ab98d 117
5b808275
LV
118 if check_backends:
119 for backend in arg_backends:
120 if not tracetool.backend.exists(backend):
121 sys.exit(1)
122 sys.exit(0)
650ab98d 123
2098c56a
DB
124 if arg_group is None:
125 error_opt("group name is required")
126
52ef093a
LV
127 if arg_format == "stap":
128 if binary is None:
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")
b9a7b74f
PB
132 if probe_prefix is None and target_name is None:
133 error_opt("--target-name is required for SystemTAP tapset generator")
52ef093a
LV
134
135 if probe_prefix is None:
5b808275 136 probe_prefix = ".".join(["qemu", target_type, target_name])
52ef093a 137
c05012a3
SH
138 if len(args) < 2:
139 error_opt("missing trace-events and output filepaths")
0ab8ed18 140 events = []
c05012a3 141 for arg in args[:-1]:
0ab8ed18 142 with open(arg, "r") as fh:
86b5aacf 143 events.extend(tracetool.read_events(fh, arg))
9096b78a 144
c05012a3
SH
145 out_open(args[-1])
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)