stap.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. Generate .stp file (DTrace with SystemTAP only).
  5. """
  6. __author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
  7. __copyright__ = "Copyright 2012-2014, 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. from tracetool.backend.dtrace import binary, probeprefix
  13. # Technically 'self' is not used by systemtap yet, but
  14. # they recommended we keep it in the reserved list anyway
  15. RESERVED_WORDS = (
  16. 'break', 'catch', 'continue', 'delete', 'else', 'for',
  17. 'foreach', 'function', 'global', 'if', 'in', 'limit',
  18. 'long', 'next', 'probe', 'return', 'self', 'string',
  19. 'try', 'while'
  20. )
  21. def stap_escape(identifier):
  22. # Append underscore to reserved keywords
  23. if identifier in RESERVED_WORDS:
  24. return identifier + '_'
  25. return identifier
  26. def generate(events, backend, group):
  27. events = [e for e in events
  28. if "disable" not in e.properties]
  29. out('/* This file is autogenerated by tracetool, do not edit. */',
  30. '')
  31. for e in events:
  32. # Define prototype for probe arguments
  33. out('probe %(probeprefix)s.%(name)s = process("%(binary)s").mark("%(name)s")',
  34. '{',
  35. probeprefix=probeprefix(),
  36. name=e.name,
  37. binary=binary())
  38. i = 1
  39. if len(e.args) > 0:
  40. for name in e.args.names():
  41. name = stap_escape(name)
  42. out(' %s = $arg%d;' % (name, i))
  43. i += 1
  44. out('}')
  45. out()