2
0

stap.py 1.6 KB

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