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