2
0

vcpu.py 2.0 KB

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