control.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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_H
  10. #define TRACE__CONTROL_H
  11. #include "event-internal.h"
  12. typedef struct TraceEventIter {
  13. size_t event;
  14. size_t group;
  15. const char *pattern;
  16. } TraceEventIter;
  17. /**
  18. * trace_event_iter_init:
  19. * @iter: the event iterator struct
  20. * @pattern: optional pattern to filter events on name
  21. *
  22. * Initialize the event iterator struct @iter,
  23. * optionally using @pattern to filter out events
  24. * with non-matching names.
  25. */
  26. void trace_event_iter_init(TraceEventIter *iter, const char *pattern);
  27. /**
  28. * trace_event_iter_next:
  29. * @iter: the event iterator struct
  30. *
  31. * Get the next event, if any. When this returns NULL,
  32. * the iterator should no longer be used.
  33. *
  34. * Returns: the next event, or NULL if no more events exist
  35. */
  36. TraceEvent *trace_event_iter_next(TraceEventIter *iter);
  37. /**
  38. * trace_event_name:
  39. * @id: Event name.
  40. *
  41. * Search an event by its name.
  42. *
  43. * Returns: pointer to #TraceEvent or NULL if not found.
  44. */
  45. TraceEvent *trace_event_name(const char *name);
  46. /**
  47. * trace_event_is_pattern:
  48. *
  49. * Whether the given string is an event name pattern.
  50. */
  51. static bool trace_event_is_pattern(const char *str);
  52. /**
  53. * trace_event_get_id:
  54. *
  55. * Get the identifier of an event.
  56. */
  57. static uint32_t trace_event_get_id(TraceEvent *ev);
  58. /**
  59. * trace_event_get_vcpu_id:
  60. *
  61. * Get the per-vCPU identifier of an event.
  62. *
  63. * Special value #TRACE_VCPU_EVENT_NONE means the event is not vCPU-specific
  64. * (does not have the "vcpu" property).
  65. */
  66. static uint32_t trace_event_get_vcpu_id(TraceEvent *ev);
  67. /**
  68. * trace_event_is_vcpu:
  69. *
  70. * Whether this is a per-vCPU event.
  71. */
  72. static bool trace_event_is_vcpu(TraceEvent *ev);
  73. /**
  74. * trace_event_get_name:
  75. *
  76. * Get the name of an event.
  77. */
  78. static const char * trace_event_get_name(TraceEvent *ev);
  79. /**
  80. * trace_event_get_state:
  81. * @id: Event identifier name.
  82. *
  83. * Get the tracing state of an event, both static and the QEMU dynamic state.
  84. *
  85. * If the event has the disabled property, the check will have no performance
  86. * impact.
  87. */
  88. #define trace_event_get_state(id) \
  89. ((id ##_ENABLED) && trace_event_get_state_dynamic_by_id(id))
  90. /**
  91. * trace_event_get_state_backends:
  92. * @id: Event identifier name.
  93. *
  94. * Get the tracing state of an event, both static and dynamic state from all
  95. * compiled-in backends.
  96. *
  97. * If the event has the disabled property, the check will have no performance
  98. * impact.
  99. *
  100. * Returns: true if at least one backend has the event enabled and the event
  101. * does not have the disabled property.
  102. */
  103. #define trace_event_get_state_backends(id) \
  104. ((id ##_ENABLED) && id ##_BACKEND_DSTATE())
  105. /**
  106. * trace_event_get_state_static:
  107. * @id: Event identifier.
  108. *
  109. * Get the static tracing state of an event.
  110. *
  111. * Use the define 'TRACE_${EVENT_NAME}_ENABLED' for compile-time checks (it will
  112. * be set to 1 or 0 according to the presence of the disabled property).
  113. */
  114. static bool trace_event_get_state_static(TraceEvent *ev);
  115. /**
  116. * trace_event_get_state_dynamic:
  117. *
  118. * Get the dynamic tracing state of an event.
  119. *
  120. * If the event has the 'vcpu' property, gets the OR'ed state of all vCPUs.
  121. */
  122. static bool trace_event_get_state_dynamic(TraceEvent *ev);
  123. /**
  124. * trace_event_set_state_dynamic:
  125. *
  126. * Set the dynamic tracing state of an event.
  127. *
  128. * If the event has the 'vcpu' property, sets the state on all vCPUs.
  129. *
  130. * Pre-condition: trace_event_get_state_static(ev) == true
  131. */
  132. void trace_event_set_state_dynamic(TraceEvent *ev, bool state);
  133. /**
  134. * trace_event_set_vcpu_state_dynamic:
  135. *
  136. * Set the dynamic tracing state of an event for the given vCPU.
  137. *
  138. * Pre-condition: trace_event_get_vcpu_state_static(ev) == true
  139. *
  140. * Note: Changes for execution-time events with the 'tcg' property will not be
  141. * propagated until the next TB is executed (iff executing in TCG mode).
  142. */
  143. void trace_event_set_vcpu_state_dynamic(CPUState *vcpu,
  144. TraceEvent *ev, bool state);
  145. /**
  146. * trace_init_backends:
  147. * @file: Name of trace output file; may be NULL.
  148. * Corresponds to commandline option "--trace file=...".
  149. *
  150. * Initialize the tracing backend.
  151. *
  152. * Returns: Whether the backends could be successfully initialized.
  153. */
  154. bool trace_init_backends(void);
  155. /**
  156. * trace_init_file:
  157. * @file: Name of trace output file; may be NULL.
  158. * Corresponds to commandline option "--trace file=...".
  159. *
  160. * Record the name of the output file for the tracing backend.
  161. * Exits if no selected backend does not support specifying the
  162. * output file, and a non-NULL file was passed.
  163. */
  164. void trace_init_file(const char *file);
  165. /**
  166. * trace_init_vcpu:
  167. * @vcpu: Added vCPU.
  168. *
  169. * Set initial dynamic event state for a hot-plugged vCPU.
  170. */
  171. void trace_init_vcpu(CPUState *vcpu);
  172. /**
  173. * trace_fini_vcpu:
  174. * @vcpu: Removed vCPU.
  175. *
  176. * Disable dynamic event state for a hot-unplugged vCPU.
  177. */
  178. void trace_fini_vcpu(CPUState *vcpu);
  179. /**
  180. * trace_list_events:
  181. *
  182. * List all available events.
  183. */
  184. void trace_list_events(void);
  185. /**
  186. * trace_enable_events:
  187. * @line_buf: A string with a glob pattern of events to be enabled or,
  188. * if the string starts with '-', disabled.
  189. *
  190. * Enable or disable matching events.
  191. */
  192. void trace_enable_events(const char *line_buf);
  193. /**
  194. * Definition of QEMU options describing trace subsystem configuration
  195. */
  196. extern QemuOptsList qemu_trace_opts;
  197. /**
  198. * trace_opt_parse:
  199. * @optarg: A string argument of --trace command line argument
  200. *
  201. * Initialize tracing subsystem.
  202. *
  203. * Returns the filename to save trace to. It must be freed with g_free().
  204. */
  205. char *trace_opt_parse(const char *optarg);
  206. /**
  207. * trace_get_vcpu_event_count:
  208. *
  209. * Return the number of known vcpu-specific events
  210. */
  211. uint32_t trace_get_vcpu_event_count(void);
  212. #include "control-internal.h"
  213. #endif /* TRACE__CONTROL_H */