ust.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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, 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. def c(events):
  13. out('#include <ust/marker.h>',
  14. '#undef mutex_lock',
  15. '#undef mutex_unlock',
  16. '#undef inline',
  17. '#undef wmb',
  18. '#include "trace.h"')
  19. for e in events:
  20. argnames = ", ".join(e.args.names())
  21. if len(e.args) > 0:
  22. argnames = ', ' + argnames
  23. out('DEFINE_TRACE(ust_%(name)s);',
  24. '',
  25. 'static void ust_%(name)s_probe(%(args)s)',
  26. '{',
  27. ' trace_mark(ust, %(name)s, %(fmt)s%(argnames)s);',
  28. '}',
  29. name = e.name,
  30. args = e.args,
  31. fmt = e.fmt,
  32. argnames = argnames,
  33. )
  34. else:
  35. out('DEFINE_TRACE(ust_%(name)s);',
  36. '',
  37. 'static void ust_%(name)s_probe(%(args)s)',
  38. '{',
  39. ' trace_mark(ust, %(name)s, UST_MARKER_NOARGS);',
  40. '}',
  41. name = e.name,
  42. args = e.args,
  43. )
  44. # register probes
  45. out('',
  46. 'static void __attribute__((constructor)) trace_init(void)',
  47. '{')
  48. for e in events:
  49. out(' register_trace_ust_%(name)s(ust_%(name)s_probe);',
  50. name = e.name,
  51. )
  52. out('}')
  53. def h(events):
  54. out('#include <ust/tracepoint.h>',
  55. '#undef mutex_lock',
  56. '#undef mutex_unlock',
  57. '#undef inline',
  58. '#undef wmb')
  59. for e in events:
  60. if len(e.args) > 0:
  61. out('DECLARE_TRACE(ust_%(name)s, TP_PROTO(%(args)s), TP_ARGS(%(argnames)s));',
  62. '#define trace_%(name)s trace_ust_%(name)s',
  63. name = e.name,
  64. args = e.args,
  65. argnames = ", ".join(e.args.names()),
  66. )
  67. else:
  68. out('_DECLARE_TRACEPOINT_NOARGS(ust_%(name)s);',
  69. '#define trace_%(name)s trace_ust_%(name)s',
  70. name = e.name,
  71. )
  72. out()