xref: /openbmc/qemu/scripts/tracetool/format/h.py (revision ad9e5aa2)
1# -*- coding: utf-8 -*-
2
3"""
4trace/generated-tracers.h
5"""
6
7__author__     = "Lluís Vilanova <vilanova@ac.upc.edu>"
8__copyright__  = "Copyright 2012-2017, Lluís Vilanova <vilanova@ac.upc.edu>"
9__license__    = "GPL version 2 or (at your option) any later version"
10
11__maintainer__ = "Stefan Hajnoczi"
12__email__      = "stefanha@redhat.com"
13
14
15from tracetool import out
16
17
18def generate(events, backend, group):
19    if group == "root":
20        header = "trace/control-vcpu.h"
21    else:
22        header = "trace/control.h"
23
24    out('/* This file is autogenerated by tracetool, do not edit. */',
25        '',
26        '#ifndef TRACE_%s_GENERATED_TRACERS_H' % group.upper(),
27        '#define TRACE_%s_GENERATED_TRACERS_H' % group.upper(),
28        '',
29        '#include "%s"' % header,
30        '')
31
32    for e in events:
33        out('extern TraceEvent %(event)s;',
34            event = e.api(e.QEMU_EVENT))
35
36    for e in events:
37        out('extern uint16_t %s;' % e.api(e.QEMU_DSTATE))
38
39    # static state
40    for e in events:
41        if 'disable' in e.properties:
42            enabled = 0
43        else:
44            enabled = 1
45        if "tcg-exec" in e.properties:
46            # a single define for the two "sub-events"
47            out('#define TRACE_%(name)s_ENABLED %(enabled)d',
48                name=e.original.name.upper(),
49                enabled=enabled)
50        out('#define TRACE_%s_ENABLED %d' % (e.name.upper(), enabled))
51
52    backend.generate_begin(events, group)
53
54    for e in events:
55        # tracer-specific dstate
56        out('',
57            '#define %(api)s() ( \\',
58            api=e.api(e.QEMU_BACKEND_DSTATE))
59
60        if "disable" not in e.properties:
61            backend.generate_backend_dstate(e, group)
62
63        out('    false)')
64
65        # tracer without checks
66        out('',
67            'static inline void %(api)s(%(args)s)',
68            '{',
69            api=e.api(e.QEMU_TRACE_NOCHECK),
70            args=e.args)
71
72        if "disable" not in e.properties:
73            backend.generate(e, group)
74
75        out('}')
76
77        # tracer wrapper with checks (per-vCPU tracing)
78        if "vcpu" in e.properties:
79            trace_cpu = next(iter(e.args))[1]
80            cond = "trace_event_get_vcpu_state(%(cpu)s,"\
81                   " TRACE_%(id)s)"\
82                   % dict(
83                       cpu=trace_cpu,
84                       id=e.name.upper())
85        else:
86            cond = "true"
87
88        out('',
89            'static inline void %(api)s(%(args)s)',
90            '{',
91            '    if (%(cond)s) {',
92            '        %(api_nocheck)s(%(names)s);',
93            '    }',
94            '}',
95            api=e.api(),
96            api_nocheck=e.api(e.QEMU_TRACE_NOCHECK),
97            args=e.args,
98            names=", ".join(e.args.names()),
99            cond=cond)
100
101    backend.generate_end(events, group)
102
103    out('#endif /* TRACE_%s_GENERATED_TRACERS_H */' % group.upper())
104