stderr.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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-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 <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 %(api)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. api = e.api(),
  32. name = e.name,
  33. args = e.args,
  34. event_id = "TRACE_" + e.name.upper(),
  35. fmt = e.fmt.rstrip("\n"),
  36. argnames = argnames,
  37. )