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