xref: /openbmc/qemu/scripts/tracetool/format/c.py (revision 6d559996)
1# -*- coding: utf-8 -*-
2
3"""
4trace/generated-tracers.c
5"""
6
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"
10
11__maintainer__ = "Stefan Hajnoczi"
12__email__      = "stefanha@redhat.com"
13
14
15from tracetool import out
16
17
18def generate(events, backend, group):
19    active_events = [e for e in events
20                     if "disable" not in e.properties]
21
22    header = "trace-" + group + ".h"
23
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        '')
30
31    for e in events:
32        out('uint16_t %s;' % e.api(e.QEMU_DSTATE))
33
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))
45
46    out('TraceEvent *%(group)s_trace_events[] = {',
47        group = group.lower())
48
49    for e in events:
50        out('    &%(event)s,', event = e.api(e.QEMU_EVENT))
51
52    out('  NULL,',
53        '};',
54        '')
55
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())
62
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)
67