aboutsummaryrefslogtreecommitdiff
path: root/scripts/tracetool/vcpu.py
blob: 452c7f589d3ee1ae76716ffe2c94e4ae4820cc5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Generic management for the 'vcpu' property.

"""

__author__     = "Lluís Vilanova <vilanova@ac.upc.edu>"
__copyright__  = "Copyright 2016, Lluís Vilanova <vilanova@ac.upc.edu>"
__license__    = "GPL version 2 or (at your option) any later version"

__maintainer__ = "Stefan Hajnoczi"
__email__      = "stefanha@linux.vnet.ibm.com"


from tracetool import Arguments, try_import


def transform_event(event):
    """Transform event to comply with the 'vcpu' property (if present)."""
    if "vcpu" in event.properties:
        # events with 'tcg-trans' and 'tcg-exec' are auto-generated from
        # already-patched events
        assert "tcg-trans" not in event.properties
        assert "tcg-exec" not in event.properties

        event.args = Arguments([("CPUState *", "__cpu"), event.args])
        if "tcg" in event.properties:
            fmt = "\"cpu=%p \""
            event.fmt = [fmt + event.fmt[0],
                         fmt + event.fmt[1]]
        else:
            fmt = "\"cpu=%p \""
            event.fmt = fmt + event.fmt
    return event


def transform_args(format, event, *args, **kwargs):
    """Transforms the arguments to suit the specified format.

    The format module must implement function 'vcpu_args', which receives the
    implicit arguments added by the 'vcpu' property, and must return suitable
    arguments for the given format.

    The function is only called for events with the 'vcpu' property.

    Parameters
    ==========
    format : str
        Format module name.
    event : Event
    args, kwargs
        Passed to 'vcpu_transform_args'.

    Returns
    =======
    Arguments
        The transformed arguments, including the non-implicit ones.

    """
    if "vcpu" in event.properties:
        ok, func = try_import("tracetool.format." + format,
                              "vcpu_transform_args")
        assert ok
        assert func
        return Arguments([func(event.args[:1], *args, **kwargs),
                          event.args[1:]])
    else:
        return event.args