control.h 6.2 KB

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