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