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