Merge tag 'pull-loongarch-20241016' of https://gitlab.com/gaosong/qemu into staging
[qemu/armbru.git] / scripts / tracetool / format / c.py
blob69edf0d588ee84672e552ecfbf0e3db064d15e4e
1 # -*- coding: utf-8 -*-
3 """
4 trace/generated-tracers.c
5 """
7 __author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
8 __copyright__ = "Copyright 2012-2014, 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 active_events = [e for e in events
20 if "disable" not in e.properties]
22 header = "trace-" + group + ".h"
24 out('/* This file is autogenerated by tracetool, do not edit. */',
25 '',
26 '#include "qemu/osdep.h"',
27 '#include "qemu/module.h"',
28 '#include "%s"' % header,
29 '')
31 for e in events:
32 out('uint16_t %s;' % e.api(e.QEMU_DSTATE))
34 for e in events:
35 out('TraceEvent %(event)s = {',
36 ' .id = 0,',
37 ' .name = \"%(name)s\",',
38 ' .sstate = %(sstate)s,',
39 ' .dstate = &%(dstate)s ',
40 '};',
41 event = e.api(e.QEMU_EVENT),
42 name = e.name,
43 sstate = "TRACE_%s_ENABLED" % e.name.upper(),
44 dstate = e.api(e.QEMU_DSTATE))
46 out('TraceEvent *%(group)s_trace_events[] = {',
47 group = group.lower())
49 for e in events:
50 out(' &%(event)s,', event = e.api(e.QEMU_EVENT))
52 out(' NULL,',
53 '};',
54 '')
56 out('static void trace_%(group)s_register_events(void)',
57 '{',
58 ' trace_event_register_group(%(group)s_trace_events);',
59 '}',
60 'trace_init(trace_%(group)s_register_events)',
61 group = group.lower())
63 backend.generate_begin(active_events, group)
64 for event in active_events:
65 backend.generate(event, group)
66 backend.generate_end(active_events, group)