h.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. # -*- coding: utf-8 -*-
  2. """
  3. trace/generated-tracers.h
  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. def generate(events, backend, group):
  12. if group == "root":
  13. header = "trace/control-vcpu.h"
  14. else:
  15. header = "trace/control.h"
  16. out('/* This file is autogenerated by tracetool, do not edit. */',
  17. '',
  18. '#ifndef TRACE_%s_GENERATED_TRACERS_H' % group.upper(),
  19. '#define TRACE_%s_GENERATED_TRACERS_H' % group.upper(),
  20. '',
  21. '#include "%s"' % header,
  22. '')
  23. for e in events:
  24. out('extern TraceEvent %(event)s;',
  25. event = e.api(e.QEMU_EVENT))
  26. for e in events:
  27. out('extern uint16_t %s;' % e.api(e.QEMU_DSTATE))
  28. # static state
  29. for e in events:
  30. if 'disable' in e.properties:
  31. enabled = 0
  32. else:
  33. enabled = 1
  34. if "tcg-exec" in e.properties:
  35. # a single define for the two "sub-events"
  36. out('#define TRACE_%(name)s_ENABLED %(enabled)d',
  37. name=e.original.name.upper(),
  38. enabled=enabled)
  39. out('#define TRACE_%s_ENABLED %d' % (e.name.upper(), enabled))
  40. backend.generate_begin(events, group)
  41. for e in events:
  42. # tracer-specific dstate
  43. out('',
  44. '#define %(api)s() ( \\',
  45. api=e.api(e.QEMU_BACKEND_DSTATE))
  46. if "disable" not in e.properties:
  47. backend.generate_backend_dstate(e, group)
  48. out(' false)')
  49. # tracer without checks
  50. out('',
  51. 'static inline void %(api)s(%(args)s)',
  52. '{',
  53. api=e.api(e.QEMU_TRACE_NOCHECK),
  54. args=e.args)
  55. if "disable" not in e.properties:
  56. backend.generate(e, group)
  57. out('}')
  58. # tracer wrapper with checks (per-vCPU tracing)
  59. if "vcpu" in e.properties:
  60. trace_cpu = next(iter(e.args))[1]
  61. cond = "trace_event_get_vcpu_state(%(cpu)s,"\
  62. " TRACE_%(id)s)"\
  63. % dict(
  64. cpu=trace_cpu,
  65. id=e.name.upper())
  66. else:
  67. cond = "true"
  68. out('',
  69. 'static inline void %(api)s(%(args)s)',
  70. '{',
  71. ' if (%(cond)s) {',
  72. ' %(api_nocheck)s(%(names)s);',
  73. ' }',
  74. '}',
  75. api=e.api(),
  76. api_nocheck=e.api(e.QEMU_TRACE_NOCHECK),
  77. args=e.args,
  78. names=", ".join(e.args.names()),
  79. cond=cond)
  80. backend.generate_end(events, group)
  81. out('#endif /* TRACE_%s_GENERATED_TRACERS_H */' % group.upper())