vcpu.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. # events with 'tcg-trans' and 'tcg-exec' are auto-generated from
  15. # already-patched events
  16. assert "tcg-trans" not in event.properties
  17. assert "tcg-exec" not in event.properties
  18. event.args = Arguments([("void *", "__cpu"), event.args])
  19. if "tcg" in event.properties:
  20. fmt = "\"cpu=%p \""
  21. event.fmt = [fmt + event.fmt[0],
  22. fmt + event.fmt[1]]
  23. else:
  24. fmt = "\"cpu=%p \""
  25. event.fmt = fmt + event.fmt
  26. return event
  27. def transform_args(format, event, *args, **kwargs):
  28. """Transforms the arguments to suit the specified format.
  29. The format module must implement function 'vcpu_args', which receives the
  30. implicit arguments added by the 'vcpu' property, and must return suitable
  31. arguments for the given format.
  32. The function is only called for events with the 'vcpu' property.
  33. Parameters
  34. ==========
  35. format : str
  36. Format module name.
  37. event : Event
  38. args, kwargs
  39. Passed to 'vcpu_transform_args'.
  40. Returns
  41. =======
  42. Arguments
  43. The transformed arguments, including the non-implicit ones.
  44. """
  45. if "vcpu" in event.properties:
  46. ok, func = try_import("tracetool.format." + format,
  47. "vcpu_transform_args")
  48. assert ok
  49. assert func
  50. return Arguments([func(event.args[:1], *args, **kwargs),
  51. event.args[1:]])
  52. else:
  53. return event.args