control.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Interface for configuring and controlling the state of tracing events.
  3. *
  4. * Copyright (C) 2011-2014 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_H
  10. #define TRACE__CONTROL_H
  11. #include "qemu-common.h"
  12. #include "trace/generated-events.h"
  13. /**
  14. * TraceEventID:
  15. *
  16. * Unique tracing event identifier.
  17. *
  18. * These are named as 'TRACE_${EVENT_NAME}'.
  19. *
  20. * See also: "trace/generated-events.h"
  21. */
  22. enum TraceEventID;
  23. /**
  24. * trace_event_id:
  25. * @id: Event identifier.
  26. *
  27. * Get an event by its identifier.
  28. *
  29. * This routine has a constant cost, as opposed to trace_event_name and
  30. * trace_event_pattern.
  31. *
  32. * Pre-conditions: The identifier is valid.
  33. *
  34. * Returns: pointer to #TraceEvent.
  35. *
  36. */
  37. static TraceEvent *trace_event_id(TraceEventID id);
  38. /**
  39. * trace_event_name:
  40. * @id: Event name.
  41. *
  42. * Search an event by its name.
  43. *
  44. * Returns: pointer to #TraceEvent or NULL if not found.
  45. */
  46. TraceEvent *trace_event_name(const char *name);
  47. /**
  48. * trace_event_pattern:
  49. * @pat: Event name pattern.
  50. * @ev: Event to start searching from (not included).
  51. *
  52. * Get all events with a given name pattern.
  53. *
  54. * Returns: pointer to #TraceEvent or NULL if not found.
  55. */
  56. TraceEvent *trace_event_pattern(const char *pat, TraceEvent *ev);
  57. /**
  58. * trace_event_is_pattern:
  59. *
  60. * Whether the given string is an event name pattern.
  61. */
  62. static bool trace_event_is_pattern(const char *str);
  63. /**
  64. * trace_event_count:
  65. *
  66. * Return the number of events.
  67. */
  68. static TraceEventID trace_event_count(void);
  69. /**
  70. * trace_event_get_id:
  71. *
  72. * Get the identifier of an event.
  73. */
  74. static TraceEventID trace_event_get_id(TraceEvent *ev);
  75. /**
  76. * trace_event_get_name:
  77. *
  78. * Get the name of an event.
  79. */
  80. static const char * trace_event_get_name(TraceEvent *ev);
  81. /**
  82. * trace_event_get_state:
  83. * @id: Event identifier.
  84. *
  85. * Get the tracing state of an event (both static and dynamic).
  86. *
  87. * If the event has the disabled property, the check will have no performance
  88. * impact.
  89. *
  90. * As a down side, you must always use an immediate #TraceEventID value.
  91. */
  92. #define trace_event_get_state(id) \
  93. ((id ##_ENABLED) && trace_event_get_state_dynamic(trace_event_id(id)))
  94. /**
  95. * trace_event_get_state_static:
  96. * @id: Event identifier.
  97. *
  98. * Get the static tracing state of an event.
  99. *
  100. * Use the define 'TRACE_${EVENT_NAME}_ENABLED' for compile-time checks (it will
  101. * be set to 1 or 0 according to the presence of the disabled property).
  102. */
  103. static bool trace_event_get_state_static(TraceEvent *ev);
  104. /**
  105. * trace_event_get_state_dynamic:
  106. *
  107. * Get the dynamic tracing state of an event.
  108. */
  109. static bool trace_event_get_state_dynamic(TraceEvent *ev);
  110. /**
  111. * trace_event_set_state:
  112. *
  113. * Set the tracing state of an event (only if possible).
  114. */
  115. #define trace_event_set_state(id, state) \
  116. do { \
  117. if ((id ##_ENABLED)) { \
  118. TraceEvent *_e = trace_event_id(id); \
  119. trace_event_set_state_dynamic(_e, state); \
  120. } \
  121. } while (0)
  122. /**
  123. * trace_event_set_state_dynamic:
  124. *
  125. * Set the dynamic tracing state of an event.
  126. *
  127. * Pre-condition: trace_event_get_state_static(ev) == true
  128. */
  129. static void trace_event_set_state_dynamic(TraceEvent *ev, bool state);
  130. /**
  131. * trace_init_backends:
  132. * @events: Name of file with events to be enabled at startup; may be NULL.
  133. * Corresponds to commandline option "-trace events=...".
  134. * @file: Name of trace output file; may be NULL.
  135. * Corresponds to commandline option "-trace file=...".
  136. *
  137. * Initialize the tracing backend.
  138. *
  139. * Returns: Whether the backends could be successfully initialized.
  140. */
  141. bool trace_init_backends(const char *events, const char *file);
  142. #include "trace/control-internal.h"
  143. #endif /* TRACE__CONTROL_H */