trace: avoid SystemTap dtrace(1) warnings on empty files
[qemu/ar7.git] / scripts / tracetool / format / d.py
blobc7cb2a93a6250ae75c0c8da66a0751dbc549c2e0
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 """
5 trace/generated-tracers.dtrace (DTrace only).
6 """
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"
12 __maintainer__ = "Stefan Hajnoczi"
13 __email__ = "stefanha@linux.vnet.ibm.com"
16 from tracetool import out
19 # Reserved keywords from
20 # https://wikis.oracle.com/display/DTrace/Types,+Operators+and+Expressions
21 RESERVED_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',
32 def generate(events, backend, group):
33 events = [e for e in events
34 if "disable" not in e.properties]
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
41 out('/* This file is autogenerated by tracetool, do not edit. */'
42 '',
43 'provider qemu {')
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)
52 # Define prototype for probe arguments
53 out('',
54 'probe %(name)s(%(args)s);',
55 name=e.name,
56 args=','.join(args))
58 out('',
59 '};')