xref: /openbmc/qemu/scripts/tracetool/format/h.py (revision 500eb6db)
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    out('/* This file is autogenerated by tracetool, do not edit. */',
21        '',
22        '#ifndef TRACE_%s_GENERATED_TRACERS_H' % group.upper(),
23        '#define TRACE_%s_GENERATED_TRACERS_H' % group.upper(),
24        '',
25        '#include "trace/control.h"',
26        '')
27
28    for e in events:
29        out('extern TraceEvent %(event)s;',
30            event = e.api(e.QEMU_EVENT))
31
32    for e in events:
33        out('extern uint16_t %s;' % e.api(e.QEMU_DSTATE))
34
35    # static state
36    for e in events:
37        if 'disable' in e.properties:
38            enabled = 0
39        else:
40            enabled = 1
41        if "tcg-exec" in e.properties:
42            # a single define for the two "sub-events"
43            out('#define TRACE_%(name)s_ENABLED %(enabled)d',
44                name=e.original.name.upper(),
45                enabled=enabled)
46        out('#define TRACE_%s_ENABLED %d' % (e.name.upper(), enabled))
47
48    backend.generate_begin(events, group)
49
50    for e in events:
51        # tracer-specific dstate
52        out('',
53            '#define %(api)s() ( \\',
54            api=e.api(e.QEMU_BACKEND_DSTATE))
55
56        if "disable" not in e.properties:
57            backend.generate_backend_dstate(e, group)
58
59        out('    false)')
60
61        # tracer without checks
62        out('',
63            'static inline void %(api)s(%(args)s)',
64            '{',
65            api=e.api(e.QEMU_TRACE_NOCHECK),
66            args=e.args)
67
68        if "disable" not in e.properties:
69            backend.generate(e, group)
70
71        out('}')
72
73        # tracer wrapper with checks (per-vCPU tracing)
74        if "vcpu" in e.properties:
75            trace_cpu = next(iter(e.args))[1]
76            cond = "trace_event_get_vcpu_state(%(cpu)s,"\
77                   " TRACE_%(id)s)"\
78                   % dict(
79                       cpu=trace_cpu,
80                       id=e.name.upper())
81        else:
82            cond = "true"
83
84        out('',
85            'static inline void %(api)s(%(args)s)',
86            '{',
87            '    if (%(cond)s) {',
88            '        %(api_nocheck)s(%(names)s);',
89            '    }',
90            '}',
91            api=e.api(),
92            api_nocheck=e.api(e.QEMU_TRACE_NOCHECK),
93            args=e.args,
94            names=", ".join(e.args.names()),
95            cond=cond)
96
97    backend.generate_end(events, group)
98
99    out('#endif /* TRACE_%s_GENERATED_TRACERS_H */' % group.upper())
100