Merge tag 'kraxel-20221013-pull-request' of https://gitlab.com/kraxel/qemu into staging
[qemu/ar7.git] / scripts / tracetool / format / h.py
blobe94f0be7dafddd90d6f3757059937cc0b07f3984
1 # -*- coding: utf-8 -*-
3 """
4 trace/generated-tracers.h
5 """
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"
11 __maintainer__ = "Stefan Hajnoczi"
12 __email__ = "stefanha@redhat.com"
15 from tracetool import out
18 def generate(events, backend, group):
19 if group == "root":
20 header = "trace/control-vcpu.h"
21 else:
22 header = "trace/control.h"
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 '')
32 for e in events:
33 out('extern TraceEvent %(event)s;',
34 event = e.api(e.QEMU_EVENT))
36 for e in events:
37 out('extern uint16_t %s;' % e.api(e.QEMU_DSTATE))
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))
52 backend.generate_begin(events, group)
54 for e in events:
55 # tracer-specific dstate
56 out('',
57 '#define %(api)s() ( \\',
58 api=e.api(e.QEMU_BACKEND_DSTATE))
60 if "disable" not in e.properties:
61 backend.generate_backend_dstate(e, group)
63 out(' false)')
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)
72 if "disable" not in e.properties:
73 backend.generate(e, group)
75 out('}')
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"
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)
101 backend.generate_end(events, group)
103 out('#endif /* TRACE_%s_GENERATED_TRACERS_H */' % group.upper())