hw/openrisc: Constify VMState
[qemu/kevin.git] / scripts / tracetool / vcpu.py
blobd232cb1d06560866c0de31e893061310afadf85b
1 # -*- coding: utf-8 -*-
3 """
4 Generic management for the 'vcpu' property.
6 """
8 __author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
9 __copyright__ = "Copyright 2016, 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"
16 from tracetool import Arguments, try_import
19 def transform_event(event):
20 """Transform event to comply with the 'vcpu' property (if present)."""
21 if "vcpu" in event.properties:
22 event.args = Arguments([("void *", "__cpu"), event.args])
23 fmt = "\"cpu=%p \""
24 event.fmt = fmt + event.fmt
25 return event
28 def transform_args(format, event, *args, **kwargs):
29 """Transforms the arguments to suit the specified format.
31 The format module must implement function 'vcpu_args', which receives the
32 implicit arguments added by the 'vcpu' property, and must return suitable
33 arguments for the given format.
35 The function is only called for events with the 'vcpu' property.
37 Parameters
38 ==========
39 format : str
40 Format module name.
41 event : Event
42 args, kwargs
43 Passed to 'vcpu_transform_args'.
45 Returns
46 =======
47 Arguments
48 The transformed arguments, including the non-implicit ones.
50 """
51 if "vcpu" in event.properties:
52 ok, func = try_import("tracetool.format." + format,
53 "vcpu_transform_args")
54 assert ok
55 assert func
56 return Arguments([func(event.args[:1], *args, **kwargs),
57 event.args[1:]])
58 else:
59 return event.args