blob: 868b4cb04c457a7d47cddba7f7776067a350eb07 [file] [log] [blame]
Lluís Vilanova3d211d92016-02-25 17:43:38 +01001# -*- coding: utf-8 -*-
2
3"""
4Generic management for the 'vcpu' property.
5
6"""
7
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"
11
12__maintainer__ = "Stefan Hajnoczi"
Philippe Mathieu-Daudéf892b492020-05-11 10:28:16 +020013__email__ = "stefanha@redhat.com"
Lluís Vilanova3d211d92016-02-25 17:43:38 +010014
15
16from tracetool import Arguments, try_import
17
18
19def transform_event(event):
20 """Transform event to comply with the 'vcpu' property (if present)."""
21 if "vcpu" in event.properties:
22 # events with 'tcg-trans' and 'tcg-exec' are auto-generated from
23 # already-patched events
24 assert "tcg-trans" not in event.properties
25 assert "tcg-exec" not in event.properties
26
Roman Bolshakov5e7477b2020-07-17 12:35:15 +030027 event.args = Arguments([("void *", "__cpu"), event.args])
Lluís Vilanova3d211d92016-02-25 17:43:38 +010028 if "tcg" in event.properties:
29 fmt = "\"cpu=%p \""
30 event.fmt = [fmt + event.fmt[0],
31 fmt + event.fmt[1]]
32 else:
33 fmt = "\"cpu=%p \""
34 event.fmt = fmt + event.fmt
35 return event
36
37
38def transform_args(format, event, *args, **kwargs):
39 """Transforms the arguments to suit the specified format.
40
41 The format module must implement function 'vcpu_args', which receives the
42 implicit arguments added by the 'vcpu' property, and must return suitable
43 arguments for the given format.
44
45 The function is only called for events with the 'vcpu' property.
46
47 Parameters
48 ==========
49 format : str
50 Format module name.
51 event : Event
52 args, kwargs
53 Passed to 'vcpu_transform_args'.
54
55 Returns
56 =======
57 Arguments
58 The transformed arguments, including the non-implicit ones.
59
60 """
61 if "vcpu" in event.properties:
62 ok, func = try_import("tracetool.format." + format,
63 "vcpu_transform_args")
64 assert ok
65 assert func
66 return Arguments([func(event.args[:1], *args, **kwargs),
67 event.args[1:]])
68 else:
69 return event.args