log.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # -*- coding: utf-8 -*-
  2. """
  3. Stderr built-in backend.
  4. """
  5. __author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
  6. __copyright__ = "Copyright 2012-2017, Lluís Vilanova <vilanova@ac.upc.edu>"
  7. __license__ = "GPL version 2 or (at your option) any later version"
  8. __maintainer__ = "Stefan Hajnoczi"
  9. __email__ = "stefanha@redhat.com"
  10. from tracetool import out
  11. PUBLIC = True
  12. def generate_h_begin(events, group):
  13. out('#include "qemu/log-for-trace.h"',
  14. '')
  15. def generate_h(event, group):
  16. argnames = ", ".join(event.args.names())
  17. if len(event.args) > 0:
  18. argnames = ", " + argnames
  19. if "vcpu" in event.properties:
  20. # already checked on the generic format code
  21. cond = "true"
  22. else:
  23. cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper())
  24. out(' if (%(cond)s && qemu_loglevel_mask(LOG_TRACE)) {',
  25. ' struct timeval _now;',
  26. ' gettimeofday(&_now, NULL);',
  27. ' qemu_log("%%d@%%zu.%%06zu:%(name)s " %(fmt)s "\\n",',
  28. ' qemu_get_thread_id(),',
  29. ' (size_t)_now.tv_sec, (size_t)_now.tv_usec',
  30. ' %(argnames)s);',
  31. ' }',
  32. cond=cond,
  33. name=event.name,
  34. fmt=event.fmt.rstrip("\n"),
  35. argnames=argnames)
  36. def generate_h_backend_dstate(event, group):
  37. out(' trace_event_get_state_dynamic_by_id(%(event_id)s) || \\',
  38. event_id="TRACE_" + event.name.upper())