dtrace.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. DTrace/SystemTAP backend.
  5. """
  6. __author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
  7. __copyright__ = "Copyright 2012, Lluís Vilanova <vilanova@ac.upc.edu>"
  8. __license__ = "GPL version 2 or (at your option) any later version"
  9. __maintainer__ = "Stefan Hajnoczi"
  10. __email__ = "stefanha@linux.vnet.ibm.com"
  11. from tracetool import out
  12. PROBEPREFIX = None
  13. def _probeprefix():
  14. if PROBEPREFIX is None:
  15. raise ValueError("you must set PROBEPREFIX")
  16. return PROBEPREFIX
  17. BINARY = None
  18. def _binary():
  19. if BINARY is None:
  20. raise ValueError("you must set BINARY")
  21. return BINARY
  22. def c(events):
  23. pass
  24. def h(events):
  25. out('#include "trace-dtrace.h"',
  26. '')
  27. for e in events:
  28. out('static inline void trace_%(name)s(%(args)s) {',
  29. ' QEMU_%(uppername)s(%(argnames)s);',
  30. '}',
  31. name = e.name,
  32. args = e.args,
  33. uppername = e.name.upper(),
  34. argnames = ", ".join(e.args.names()),
  35. )
  36. def d(events):
  37. out('provider qemu {')
  38. for e in events:
  39. args = str(e.args)
  40. # DTrace provider syntax expects foo() for empty
  41. # params, not foo(void)
  42. if args == 'void':
  43. args = ''
  44. # Define prototype for probe arguments
  45. out('',
  46. 'probe %(name)s(%(args)s);',
  47. name = e.name,
  48. args = args,
  49. )
  50. out('',
  51. '};')
  52. def stap(events):
  53. for e in events:
  54. # Define prototype for probe arguments
  55. out('probe %(probeprefix)s.%(name)s = process("%(binary)s").mark("%(name)s")',
  56. '{',
  57. probeprefix = _probeprefix(),
  58. name = e.name,
  59. binary = _binary(),
  60. )
  61. i = 1
  62. if len(e.args) > 0:
  63. for name in e.args.names():
  64. # Append underscore to reserved keywords
  65. if name in ('limit', 'in', 'next', 'self'):
  66. name += '_'
  67. out(' %s = $arg%d;' % (name, i))
  68. i += 1
  69. out('}')
  70. out()