simple.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. Simple built-in 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 "trace.h"',
  14. '',
  15. 'TraceEvent trace_list[] = {')
  16. for e in events:
  17. out('{.tp_name = "%(name)s", .state=0},',
  18. name = e.name,
  19. )
  20. out('};')
  21. def h(events):
  22. out('#include "trace/simple.h"',
  23. '')
  24. for num, e in enumerate(events):
  25. if len(e.args):
  26. argstr = e.args.names()
  27. arg_prefix = ', (uint64_t)(uintptr_t)'
  28. cast_args = arg_prefix + arg_prefix.join(argstr)
  29. simple_args = (str(num) + cast_args)
  30. else:
  31. simple_args = str(num)
  32. out('static inline void trace_%(name)s(%(args)s)',
  33. '{',
  34. ' trace%(argc)d(%(trace_args)s);',
  35. '}',
  36. name = e.name,
  37. args = e.args,
  38. argc = len(e.args),
  39. trace_args = simple_args,
  40. )
  41. out('#define NR_TRACE_EVENTS %d' % len(events))
  42. out('extern TraceEvent trace_list[NR_TRACE_EVENTS];')