stderr.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. PUBLIC = True
  13. def c(events):
  14. pass
  15. def h(events):
  16. out('#include <stdio.h>',
  17. '#include "trace/control.h"',
  18. '',
  19. )
  20. for e in events:
  21. argnames = ", ".join(e.args.names())
  22. if len(e.args) > 0:
  23. argnames = ", " + argnames
  24. out('static inline void trace_%(name)s(%(args)s)',
  25. '{',
  26. ' bool _state = trace_event_get_state(%(event_id)s);',
  27. ' if (_state) {',
  28. ' fprintf(stderr, "%(name)s " %(fmt)s "\\n" %(argnames)s);',
  29. ' }',
  30. '}',
  31. name = e.name,
  32. args = e.args,
  33. event_id = "TRACE_" + e.name.upper(),
  34. fmt = e.fmt.rstrip("\n"),
  35. argnames = argnames,
  36. )