control-internal.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Interface for configuring and controlling the state of tracing events.
  3. *
  4. * Copyright (C) 2011-2016 Lluís Vilanova <vilanova@ac.upc.edu>
  5. *
  6. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  7. * See the COPYING file in the top-level directory.
  8. */
  9. #ifndef TRACE__CONTROL_INTERNAL_H
  10. #define TRACE__CONTROL_INTERNAL_H
  11. #include <stddef.h> /* size_t */
  12. #include "qom/cpu.h"
  13. extern TraceEvent trace_events[];
  14. extern uint16_t trace_events_dstate[];
  15. extern int trace_events_enabled_count;
  16. static inline TraceEventID trace_event_count(void)
  17. {
  18. return TRACE_EVENT_COUNT;
  19. }
  20. static inline TraceEvent *trace_event_id(TraceEventID id)
  21. {
  22. assert(id < trace_event_count());
  23. return &trace_events[id];
  24. }
  25. static inline bool trace_event_is_pattern(const char *str)
  26. {
  27. assert(str != NULL);
  28. return strchr(str, '*') != NULL;
  29. }
  30. static inline TraceEventID trace_event_get_id(TraceEvent *ev)
  31. {
  32. assert(ev != NULL);
  33. return ev->id;
  34. }
  35. static inline TraceEventVCPUID trace_event_get_vcpu_id(TraceEvent *ev)
  36. {
  37. return ev->vcpu_id;
  38. }
  39. static inline bool trace_event_is_vcpu(TraceEvent *ev)
  40. {
  41. return ev->vcpu_id != TRACE_VCPU_EVENT_COUNT;
  42. }
  43. static inline const char * trace_event_get_name(TraceEvent *ev)
  44. {
  45. assert(ev != NULL);
  46. return ev->name;
  47. }
  48. static inline bool trace_event_get_state_static(TraceEvent *ev)
  49. {
  50. assert(ev != NULL);
  51. return ev->sstate;
  52. }
  53. static inline bool trace_event_get_state_dynamic_by_id(TraceEventID id)
  54. {
  55. /* it's on fast path, avoid consistency checks (asserts) */
  56. return unlikely(trace_events_enabled_count) && trace_events_dstate[id];
  57. }
  58. static inline bool trace_event_get_state_dynamic(TraceEvent *ev)
  59. {
  60. TraceEventID id;
  61. assert(trace_event_get_state_static(ev));
  62. id = trace_event_get_id(ev);
  63. return trace_event_get_state_dynamic_by_id(id);
  64. }
  65. static inline bool trace_event_get_vcpu_state_dynamic_by_vcpu_id(CPUState *vcpu,
  66. TraceEventVCPUID id)
  67. {
  68. /* it's on fast path, avoid consistency checks (asserts) */
  69. if (unlikely(trace_events_enabled_count)) {
  70. return test_bit(id, vcpu->trace_dstate);
  71. } else {
  72. return false;
  73. }
  74. }
  75. static inline bool trace_event_get_vcpu_state_dynamic(CPUState *vcpu,
  76. TraceEvent *ev)
  77. {
  78. TraceEventVCPUID id;
  79. assert(trace_event_is_vcpu(ev));
  80. id = trace_event_get_vcpu_id(ev);
  81. return trace_event_get_vcpu_state_dynamic_by_vcpu_id(vcpu, id);
  82. }
  83. #endif /* TRACE__CONTROL_INTERNAL_H */