d.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # -*- coding: utf-8 -*-
  2. """
  3. trace/generated-tracers.dtrace (DTrace only).
  4. """
  5. __author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
  6. __copyright__ = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
  7. __license__ = "GPL version 2 or (at your option) any later version"
  8. __maintainer__ = "Stefan Hajnoczi"
  9. __email__ = "stefanha@redhat.com"
  10. from tracetool import out
  11. # Reserved keywords from
  12. # https://wikis.oracle.com/display/DTrace/Types,+Operators+and+Expressions
  13. RESERVED_WORDS = (
  14. 'auto', 'goto', 'sizeof', 'break', 'if', 'static', 'case', 'import',
  15. 'string', 'char', 'inline', 'stringof', 'const', 'int', 'struct',
  16. 'continue', 'long', 'switch', 'counter', 'offsetof', 'this',
  17. 'default', 'probe', 'translator', 'do', 'provider', 'typedef',
  18. 'double', 'register', 'union', 'else', 'restrict', 'unsigned',
  19. 'enum', 'return', 'void', 'extern', 'self', 'volatile', 'float',
  20. 'short', 'while', 'for', 'signed', 'xlate',
  21. )
  22. def generate(events, backend, group):
  23. events = [e for e in events
  24. if "disable" not in e.properties]
  25. # SystemTap's dtrace(1) warns about empty "provider qemu {}" but is happy
  26. # with an empty file. Avoid the warning.
  27. if not events:
  28. return
  29. out('/* This file is autogenerated by tracetool, do not edit. */'
  30. '',
  31. 'provider qemu {')
  32. for e in events:
  33. args = []
  34. for type_, name in e.args:
  35. if name in RESERVED_WORDS:
  36. name += '_'
  37. args.append(type_ + ' ' + name)
  38. # Define prototype for probe arguments
  39. out('',
  40. 'probe %(name)s(%(args)s);',
  41. name=e.name,
  42. args=','.join(args))
  43. out('',
  44. '};')