xref: /openbmc/qemu/scripts/tracetool/format/c.py (revision 64552b6b)
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4"""
5trace/generated-tracers.c
6"""
7
8__author__     = "Lluís Vilanova <vilanova@ac.upc.edu>"
9__copyright__  = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
10__license__    = "GPL version 2 or (at your option) any later version"
11
12__maintainer__ = "Stefan Hajnoczi"
13__email__      = "stefanha@linux.vnet.ibm.com"
14
15
16from tracetool import out
17
18
19def generate(events, backend, group):
20    active_events = [e for e in events
21                     if "disable" not in e.properties]
22
23    if group == "root":
24        header = "trace-root.h"
25    else:
26        header = "trace.h"
27
28    out('/* This file is autogenerated by tracetool, do not edit. */',
29        '',
30        '#include "qemu/osdep.h"',
31        '#include "qemu/module.h"',
32        '#include "%s"' % header,
33        '')
34
35    for e in events:
36        out('uint16_t %s;' % e.api(e.QEMU_DSTATE))
37
38    for e in events:
39        if "vcpu" in e.properties:
40            vcpu_id = 0
41        else:
42            vcpu_id = "TRACE_VCPU_EVENT_NONE"
43        out('TraceEvent %(event)s = {',
44            '    .id = 0,',
45            '    .vcpu_id = %(vcpu_id)s,',
46            '    .name = \"%(name)s\",',
47            '    .sstate = %(sstate)s,',
48            '    .dstate = &%(dstate)s ',
49            '};',
50            event = e.api(e.QEMU_EVENT),
51            vcpu_id = vcpu_id,
52            name = e.name,
53            sstate = "TRACE_%s_ENABLED" % e.name.upper(),
54            dstate = e.api(e.QEMU_DSTATE))
55
56    out('TraceEvent *%(group)s_trace_events[] = {',
57        group = group.lower())
58
59    for e in events:
60        out('    &%(event)s,', event = e.api(e.QEMU_EVENT))
61
62    out('  NULL,',
63        '};',
64        '')
65
66    out('static void trace_%(group)s_register_events(void)',
67        '{',
68        '    trace_event_register_group(%(group)s_trace_events);',
69        '}',
70        'trace_init(trace_%(group)s_register_events)',
71        group = group.lower())
72
73    backend.generate_begin(active_events, group)
74    for event in active_events:
75        backend.generate(event, group)
76    backend.generate_end(active_events, group)
77