xref: /openbmc/qemu/scripts/tracetool/format/c.py (revision 64ed6f92)
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        if "vcpu" in e.properties:
36            vcpu_id = 0
37        else:
38            vcpu_id = "TRACE_VCPU_EVENT_NONE"
39        out('TraceEvent %(event)s = {',
40            '    .id = 0,',
41            '    .vcpu_id = %(vcpu_id)s,',
42            '    .name = \"%(name)s\",',
43            '    .sstate = %(sstate)s,',
44            '    .dstate = &%(dstate)s ',
45            '};',
46            event = e.api(e.QEMU_EVENT),
47            vcpu_id = vcpu_id,
48            name = e.name,
49            sstate = "TRACE_%s_ENABLED" % e.name.upper(),
50            dstate = e.api(e.QEMU_DSTATE))
51
52    out('TraceEvent *%(group)s_trace_events[] = {',
53        group = group.lower())
54
55    for e in events:
56        out('    &%(event)s,', event = e.api(e.QEMU_EVENT))
57
58    out('  NULL,',
59        '};',
60        '')
61
62    out('static void trace_%(group)s_register_events(void)',
63        '{',
64        '    trace_event_register_group(%(group)s_trace_events);',
65        '}',
66        'trace_init(trace_%(group)s_register_events)',
67        group = group.lower())
68
69    backend.generate_begin(active_events, group)
70    for event in active_events:
71        backend.generate(event, group)
72    backend.generate_end(active_events, group)
73