MAINTAINERS: Update mail address for COLO Proxy
[qemu/ar7.git] / scripts / tracetool / vcpu.py
blob452c7f589d3ee1ae76716ffe2c94e4ae4820cc5e
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 """
5 Generic management for the 'vcpu' property.
7 """
9 __author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
10 __copyright__ = "Copyright 2016, Lluís Vilanova <vilanova@ac.upc.edu>"
11 __license__ = "GPL version 2 or (at your option) any later version"
13 __maintainer__ = "Stefan Hajnoczi"
14 __email__ = "stefanha@linux.vnet.ibm.com"
17 from tracetool import Arguments, try_import
20 def transform_event(event):
21 """Transform event to comply with the 'vcpu' property (if present)."""
22 if "vcpu" in event.properties:
23 # events with 'tcg-trans' and 'tcg-exec' are auto-generated from
24 # already-patched events
25 assert "tcg-trans" not in event.properties
26 assert "tcg-exec" not in event.properties
28 event.args = Arguments([("CPUState *", "__cpu"), event.args])
29 if "tcg" in event.properties:
30 fmt = "\"cpu=%p \""
31 event.fmt = [fmt + event.fmt[0],
32 fmt + event.fmt[1]]
33 else:
34 fmt = "\"cpu=%p \""
35 event.fmt = fmt + event.fmt
36 return event
39 def transform_args(format, event, *args, **kwargs):
40 """Transforms the arguments to suit the specified format.
42 The format module must implement function 'vcpu_args', which receives the
43 implicit arguments added by the 'vcpu' property, and must return suitable
44 arguments for the given format.
46 The function is only called for events with the 'vcpu' property.
48 Parameters
49 ==========
50 format : str
51 Format module name.
52 event : Event
53 args, kwargs
54 Passed to 'vcpu_transform_args'.
56 Returns
57 =======
58 Arguments
59 The transformed arguments, including the non-implicit ones.
61 """
62 if "vcpu" in event.properties:
63 ok, func = try_import("tracetool.format." + format,
64 "vcpu_transform_args")
65 assert ok
66 assert func
67 return Arguments([func(event.args[:1], *args, **kwargs),
68 event.args[1:]])
69 else:
70 return event.args