h.py 2.8 KB

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