2
0

d.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. from sys import platform
  12. # Reserved keywords from
  13. # https://wikis.oracle.com/display/DTrace/Types,+Operators+and+Expressions
  14. RESERVED_WORDS = (
  15. 'auto', 'goto', 'sizeof', 'break', 'if', 'static', 'case', 'import',
  16. 'string', 'char', 'inline', 'stringof', 'const', 'int', 'struct',
  17. 'continue', 'long', 'switch', 'counter', 'offsetof', 'this',
  18. 'default', 'probe', 'translator', 'do', 'provider', 'typedef',
  19. 'double', 'register', 'union', 'else', 'restrict', 'unsigned',
  20. 'enum', 'return', 'void', 'extern', 'self', 'volatile', 'float',
  21. 'short', 'while', 'for', 'signed', 'xlate',
  22. )
  23. def generate(events, backend, group):
  24. events = [e for e in events
  25. if "disable" not in e.properties]
  26. # SystemTap's dtrace(1) warns about empty "provider qemu {}" but is happy
  27. # with an empty file. Avoid the warning.
  28. # But dtrace on macOS can't deal with empty files.
  29. if not events and platform != "darwin":
  30. return
  31. out('/* This file is autogenerated by tracetool, do not edit. */'
  32. '',
  33. 'provider qemu {')
  34. for e in events:
  35. args = []
  36. for type_, name in e.args:
  37. if platform == "darwin":
  38. # macOS dtrace accepts only C99 _Bool
  39. if type_ == 'bool':
  40. type_ = '_Bool'
  41. if type_ == 'bool *':
  42. type_ = '_Bool *'
  43. # It converts int8_t * in probe points to char * in header
  44. # files and introduces [-Wpointer-sign] warning.
  45. # Avoid it by changing probe type to signed char * beforehand.
  46. if type_ == 'int8_t *':
  47. type_ = 'signed char *'
  48. # SystemTap dtrace(1) emits a warning when long long is used
  49. type_ = type_.replace('unsigned long long', 'uint64_t')
  50. type_ = type_.replace('signed long long', 'int64_t')
  51. type_ = type_.replace('long long', 'int64_t')
  52. if name in RESERVED_WORDS:
  53. name += '_'
  54. args.append(type_ + ' ' + name)
  55. # Define prototype for probe arguments
  56. out('',
  57. 'probe %(name)s(%(args)s);',
  58. name=e.name,
  59. args=','.join(args))
  60. out('',
  61. '};')