xref: /qemu/scripts/tracetool/format/d.py (revision bfa3ab61)
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):
33    events = [e for e in events
34              if "disable" not in e.properties]
35
36    out('/* This file is autogenerated by tracetool, do not edit. */'
37        '',
38        'provider qemu {')
39
40    for e in events:
41        args = []
42        for type_, name in e.args:
43            if name in RESERVED_WORDS:
44                name += '_'
45            args.append(type_ + ' ' + name)
46
47        # Define prototype for probe arguments
48        out('',
49            'probe %(name)s(%(args)s);',
50            name=e.name,
51            args=','.join(args))
52
53    out('',
54        '};')
55