stderr.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. Stderr 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 <stdio.h>',
  23. '#include "trace/stderr.h"',
  24. '',
  25. 'extern TraceEvent trace_list[];')
  26. for num, e in enumerate(events):
  27. argnames = ", ".join(e.args.names())
  28. if len(e.args) > 0:
  29. argnames = ", " + argnames
  30. out('static inline void trace_%(name)s(%(args)s)',
  31. '{',
  32. ' if (trace_list[%(event_num)s].state != 0) {',
  33. ' fprintf(stderr, "%(name)s " %(fmt)s "\\n" %(argnames)s);',
  34. ' }',
  35. '}',
  36. name = e.name,
  37. args = e.args,
  38. event_num = num,
  39. fmt = e.fmt,
  40. argnames = argnames,
  41. )
  42. out('',
  43. '#define NR_TRACE_EVENTS %d' % len(events))