log.py 1.3 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-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 generate_h_begin(events):
  14. out('#include <stdio.h>',
  15. '#include <sys/time.h>',
  16. '#include <sys/types.h>',
  17. '#include <unistd.h>',
  18. '#include "trace/control.h"',
  19. '#include "qemu/log.h"',
  20. '')
  21. def generate_h(event):
  22. argnames = ", ".join(event.args.names())
  23. if len(event.args) > 0:
  24. argnames = ", " + argnames
  25. out(' if (trace_event_get_state(%(event_id)s)) {',
  26. ' struct timeval _now;',
  27. ' gettimeofday(&_now, NULL);',
  28. ' qemu_log_mask(LOG_TRACE, "%%d@%%zd.%%06zd:%(name)s " %(fmt)s "\\n",',
  29. ' getpid(),',
  30. ' (size_t)_now.tv_sec, (size_t)_now.tv_usec',
  31. ' %(argnames)s);',
  32. ' }',
  33. event_id="TRACE_" + event.name.upper(),
  34. name=event.name,
  35. fmt=event.fmt.rstrip("\n"),
  36. argnames=argnames)