vcpu.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # -*- coding: utf-8 -*-
  2. """
  3. Generic management for the 'vcpu' property.
  4. """
  5. __author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
  6. __copyright__ = "Copyright 2016, 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 Arguments, try_import
  11. def transform_event(event):
  12. """Transform event to comply with the 'vcpu' property (if present)."""
  13. if "vcpu" in event.properties:
  14. event.args = Arguments([("void *", "__cpu"), event.args])
  15. fmt = "\"cpu=%p \""
  16. event.fmt = fmt + event.fmt
  17. return event
  18. def transform_args(format, event, *args, **kwargs):
  19. """Transforms the arguments to suit the specified format.
  20. The format module must implement function 'vcpu_args', which receives the
  21. implicit arguments added by the 'vcpu' property, and must return suitable
  22. arguments for the given format.
  23. The function is only called for events with the 'vcpu' property.
  24. Parameters
  25. ==========
  26. format : str
  27. Format module name.
  28. event : Event
  29. args, kwargs
  30. Passed to 'vcpu_transform_args'.
  31. Returns
  32. =======
  33. Arguments
  34. The transformed arguments, including the non-implicit ones.
  35. """
  36. if "vcpu" in event.properties:
  37. ok, func = try_import("tracetool.format." + format,
  38. "vcpu_transform_args")
  39. assert ok
  40. assert func
  41. return Arguments([func(event.args[:1], *args, **kwargs),
  42. event.args[1:]])
  43. else:
  44. return event.args