xref: /openbmc/qemu/scripts/tracetool/format/d.py (revision ad9e5aa2)
1# -*- coding: utf-8 -*-
2
3"""
4trace/generated-tracers.dtrace (DTrace only).
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
18# Reserved keywords from
19# https://wikis.oracle.com/display/DTrace/Types,+Operators+and+Expressions
20RESERVED_WORDS = (
21    'auto', 'goto', 'sizeof', 'break', 'if', 'static', 'case', 'import',
22    'string', 'char', 'inline', 'stringof', 'const', 'int', 'struct',
23    'continue', 'long', 'switch', 'counter', 'offsetof', 'this',
24    'default', 'probe', 'translator', 'do', 'provider', 'typedef',
25    'double', 'register', 'union', 'else', 'restrict', 'unsigned',
26    'enum', 'return', 'void', 'extern', 'self', 'volatile', 'float',
27    'short', 'while', 'for', 'signed', 'xlate',
28)
29
30
31def generate(events, backend, group):
32    events = [e for e in events
33              if "disable" not in e.properties]
34
35    # SystemTap's dtrace(1) warns about empty "provider qemu {}" but is happy
36    # with an empty file.  Avoid the warning.
37    if not events:
38        return
39
40    out('/* This file is autogenerated by tracetool, do not edit. */'
41        '',
42        'provider qemu {')
43
44    for e in events:
45        args = []
46        for type_, name in e.args:
47            if name in RESERVED_WORDS:
48                name += '_'
49            args.append(type_ + ' ' + name)
50
51        # Define prototype for probe arguments
52        out('',
53            'probe %(name)s(%(args)s);',
54            name=e.name,
55            args=','.join(args))
56
57    out('',
58        '};')
59