log.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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-2017, 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, group):
  14. out('#include "qemu/log-for-trace.h"',
  15. '')
  16. def generate_h(event, group):
  17. argnames = ", ".join(event.args.names())
  18. if len(event.args) > 0:
  19. argnames = ", " + argnames
  20. if "vcpu" in event.properties:
  21. # already checked on the generic format code
  22. cond = "true"
  23. else:
  24. cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper())
  25. out(' if (%(cond)s && qemu_loglevel_mask(LOG_TRACE)) {',
  26. ' struct timeval _now;',
  27. ' gettimeofday(&_now, NULL);',
  28. ' qemu_log("%%d@%%zu.%%06zu:%(name)s " %(fmt)s "\\n",',
  29. ' qemu_get_thread_id(),',
  30. ' (size_t)_now.tv_sec, (size_t)_now.tv_usec',
  31. ' %(argnames)s);',
  32. ' }',
  33. cond=cond,
  34. name=event.name,
  35. fmt=event.fmt.rstrip("\n"),
  36. argnames=argnames)
  37. def generate_h_backend_dstate(event, group):
  38. out(' trace_event_get_state_dynamic_by_id(%(event_id)s) || \\',
  39. event_id="TRACE_" + event.name.upper())