xref: /openbmc/qemu/scripts/tracetool/format/c.py (revision 581e109d)
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    if group == "root":
23        header = "trace-root.h"
24    else:
25        header = "trace.h"
26
27    out('/* This file is autogenerated by tracetool, do not edit. */',
28        '',
29        '#include "qemu/osdep.h"',
30        '#include "qemu/module.h"',
31        '#include "%s"' % header,
32        '')
33
34    for e in events:
35        out('uint16_t %s;' % e.api(e.QEMU_DSTATE))
36
37    for e in events:
38        if "vcpu" in e.properties:
39            vcpu_id = 0
40        else:
41            vcpu_id = "TRACE_VCPU_EVENT_NONE"
42        out('TraceEvent %(event)s = {',
43            '    .id = 0,',
44            '    .vcpu_id = %(vcpu_id)s,',
45            '    .name = \"%(name)s\",',
46            '    .sstate = %(sstate)s,',
47            '    .dstate = &%(dstate)s ',
48            '};',
49            event = e.api(e.QEMU_EVENT),
50            vcpu_id = vcpu_id,
51            name = e.name,
52            sstate = "TRACE_%s_ENABLED" % e.name.upper(),
53            dstate = e.api(e.QEMU_DSTATE))
54
55    out('TraceEvent *%(group)s_trace_events[] = {',
56        group = group.lower())
57
58    for e in events:
59        out('    &%(event)s,', event = e.api(e.QEMU_EVENT))
60
61    out('  NULL,',
62        '};',
63        '')
64
65    out('static void trace_%(group)s_register_events(void)',
66        '{',
67        '    trace_event_register_group(%(group)s_trace_events);',
68        '}',
69        'trace_init(trace_%(group)s_register_events)',
70        group = group.lower())
71
72    backend.generate_begin(active_events, group)
73    for event in active_events:
74        backend.generate(event, group)
75    backend.generate_end(active_events, group)
76