ust.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. LTTng User Space Tracing backend.
  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. PUBLIC = True
  13. def c(events):
  14. pass
  15. def h(events):
  16. out('#include <lttng/tracepoint.h>',
  17. '#include "trace/generated-ust-provider.h"',
  18. '')
  19. for e in events:
  20. argnames = ", ".join(e.args.names())
  21. if len(e.args) > 0:
  22. argnames = ", " + argnames
  23. out('static inline void %(api)s(%(args)s)',
  24. '{',
  25. ' tracepoint(qemu, %(name)s%(tp_args)s);',
  26. '}',
  27. '',
  28. api = e.api()
  29. name = e.name,
  30. args = e.args,
  31. tp_args = argnames,
  32. )
  33. def ust_events_c(events):
  34. pass
  35. def ust_events_h(events):
  36. for e in events:
  37. if len(e.args) > 0:
  38. out('TRACEPOINT_EVENT(',
  39. ' qemu,',
  40. ' %(name)s,',
  41. ' TP_ARGS(%(args)s),',
  42. ' TP_FIELDS(',
  43. name = e.name,
  44. args = ", ".join(", ".join(i) for i in e.args),
  45. )
  46. for t,n in e.args:
  47. if ('int' in t) or ('long' in t) or ('unsigned' in t) or ('size_t' in t):
  48. out(' ctf_integer(' + t + ', ' + n + ', ' + n + ')')
  49. elif ('double' in t) or ('float' in t):
  50. out(' ctf_float(' + t + ', ' + n + ', ' + n + ')')
  51. elif ('char *' in t) or ('char*' in t):
  52. out(' ctf_string(' + n + ', ' + n + ')')
  53. elif ('void *' in t) or ('void*' in t):
  54. out(' ctf_integer_hex(unsigned long, ' + n + ', ' + n + ')')
  55. out(' )',
  56. ')',
  57. '')
  58. else:
  59. out('TRACEPOINT_EVENT(',
  60. ' qemu,',
  61. ' %(name)s,',
  62. ' TP_ARGS(void),',
  63. ' TP_FIELDS()',
  64. ')',
  65. '',
  66. name = e.name,
  67. )