Lluís | e485897 | 2011-08-31 20:31:03 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Interface for configuring and controlling the state of tracing events. |
| 3 | * |
Lluís Vilanova | 3d211d9 | 2016-02-25 17:43:38 +0100 | [diff] [blame] | 4 | * Copyright (C) 2011-2016 Lluís Vilanova <vilanova@ac.upc.edu> |
Lluís | e485897 | 2011-08-31 20:31:03 +0200 | [diff] [blame] | 5 | * |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 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. |
Lluís | e485897 | 2011-08-31 20:31:03 +0200 | [diff] [blame] | 8 | */ |
| 9 | |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 10 | #ifndef TRACE__CONTROL_H |
| 11 | #define TRACE__CONTROL_H |
Lluís | e485897 | 2011-08-31 20:31:03 +0200 | [diff] [blame] | 12 | |
Lluís | fc76410 | 2011-08-31 20:31:18 +0200 | [diff] [blame] | 13 | #include "qemu-common.h" |
Daniel P. Berrange | 3477018 | 2016-10-04 14:35:55 +0100 | [diff] [blame] | 14 | #include "event-internal.h" |
Lluís | fc76410 | 2011-08-31 20:31:18 +0200 | [diff] [blame] | 15 | |
Daniel P. Berrange | 6a1b0f3 | 2016-10-04 14:35:42 +0100 | [diff] [blame] | 16 | typedef struct TraceEventIter { |
| 17 | size_t event; |
Daniel P. Berrange | fe4db84 | 2016-10-04 14:35:52 +0100 | [diff] [blame] | 18 | size_t group; |
Daniel P. Berrange | 6a1b0f3 | 2016-10-04 14:35:42 +0100 | [diff] [blame] | 19 | const char *pattern; |
| 20 | } TraceEventIter; |
Lluís | fc76410 | 2011-08-31 20:31:18 +0200 | [diff] [blame] | 21 | |
Daniel P. Berrange | 6a1b0f3 | 2016-10-04 14:35:42 +0100 | [diff] [blame] | 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 | |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 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 | /** |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 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 | |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 63 | |
| 64 | /** |
| 65 | * trace_event_get_id: |
| 66 | * |
| 67 | * Get the identifier of an event. |
| 68 | */ |
Daniel P. Berrange | ef4c9fc | 2016-10-04 14:35:49 +0100 | [diff] [blame] | 69 | static uint32_t trace_event_get_id(TraceEvent *ev); |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 70 | |
| 71 | /** |
Lluís Vilanova | 17f7ac7 | 2016-07-11 12:53:24 +0200 | [diff] [blame] | 72 | * trace_event_get_vcpu_id: |
| 73 | * |
| 74 | * Get the per-vCPU identifier of an event. |
| 75 | * |
Daniel P. Berrange | ef4c9fc | 2016-10-04 14:35:49 +0100 | [diff] [blame] | 76 | * Special value #TRACE_VCPU_EVENT_NONE means the event is not vCPU-specific |
Lluís Vilanova | 17f7ac7 | 2016-07-11 12:53:24 +0200 | [diff] [blame] | 77 | * (does not have the "vcpu" property). |
| 78 | */ |
Daniel P. Berrange | ef4c9fc | 2016-10-04 14:35:49 +0100 | [diff] [blame] | 79 | static uint32_t trace_event_get_vcpu_id(TraceEvent *ev); |
Lluís Vilanova | 17f7ac7 | 2016-07-11 12:53:24 +0200 | [diff] [blame] | 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 | /** |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 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: |
Daniel P. Berrange | ef4c9fc | 2016-10-04 14:35:49 +0100 | [diff] [blame] | 97 | * @id: Event identifier name. |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 98 | * |
Stefan Hajnoczi | d87aa13 | 2017-07-31 15:07:18 +0100 | [diff] [blame] | 99 | * Get the tracing state of an event, both static and the QEMU dynamic state. |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 100 | * |
| 101 | * If the event has the disabled property, the check will have no performance |
| 102 | * impact. |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 103 | */ |
| 104 | #define trace_event_get_state(id) \ |
Paolo Bonzini | 585ec72 | 2015-10-28 07:06:27 +0100 | [diff] [blame] | 105 | ((id ##_ENABLED) && trace_event_get_state_dynamic_by_id(id)) |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 106 | |
| 107 | /** |
Stefan Hajnoczi | d87aa13 | 2017-07-31 15:07:18 +0100 | [diff] [blame] | 108 | * trace_event_get_state_backends: |
| 109 | * @id: Event identifier name. |
| 110 | * |
| 111 | * Get the tracing state of an event, both static and dynamic state from all |
| 112 | * compiled-in backends. |
| 113 | * |
| 114 | * If the event has the disabled property, the check will have no performance |
| 115 | * impact. |
| 116 | * |
| 117 | * Returns: true if at least one backend has the event enabled and the event |
| 118 | * does not have the disabled property. |
| 119 | */ |
| 120 | #define trace_event_get_state_backends(id) \ |
| 121 | ((id ##_ENABLED) && id ##_BACKEND_DSTATE()) |
| 122 | |
| 123 | /** |
Lluís Vilanova | 4815185 | 2016-07-11 12:53:41 +0200 | [diff] [blame] | 124 | * trace_event_get_vcpu_state: |
| 125 | * @vcpu: Target vCPU. |
Daniel P. Berrange | ef4c9fc | 2016-10-04 14:35:49 +0100 | [diff] [blame] | 126 | * @id: Event identifier name. |
Lluís Vilanova | 4815185 | 2016-07-11 12:53:41 +0200 | [diff] [blame] | 127 | * |
| 128 | * Get the tracing state of an event (both static and dynamic) for the given |
| 129 | * vCPU. |
| 130 | * |
| 131 | * If the event has the disabled property, the check will have no performance |
| 132 | * impact. |
Lluís Vilanova | 4815185 | 2016-07-11 12:53:41 +0200 | [diff] [blame] | 133 | */ |
Daniel P. Berrange | ef4c9fc | 2016-10-04 14:35:49 +0100 | [diff] [blame] | 134 | #define trace_event_get_vcpu_state(vcpu, id) \ |
| 135 | ((id ##_ENABLED) && \ |
| 136 | trace_event_get_vcpu_state_dynamic_by_vcpu_id( \ |
| 137 | vcpu, _ ## id ## _EVENT.vcpu_id)) |
Lluís Vilanova | 4815185 | 2016-07-11 12:53:41 +0200 | [diff] [blame] | 138 | |
| 139 | /** |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 140 | * trace_event_get_state_static: |
| 141 | * @id: Event identifier. |
| 142 | * |
| 143 | * Get the static tracing state of an event. |
| 144 | * |
| 145 | * Use the define 'TRACE_${EVENT_NAME}_ENABLED' for compile-time checks (it will |
| 146 | * be set to 1 or 0 according to the presence of the disabled property). |
| 147 | */ |
| 148 | static bool trace_event_get_state_static(TraceEvent *ev); |
| 149 | |
| 150 | /** |
| 151 | * trace_event_get_state_dynamic: |
| 152 | * |
| 153 | * Get the dynamic tracing state of an event. |
Lluís Vilanova | 4815185 | 2016-07-11 12:53:41 +0200 | [diff] [blame] | 154 | * |
| 155 | * If the event has the 'vcpu' property, gets the OR'ed state of all vCPUs. |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 156 | */ |
| 157 | static bool trace_event_get_state_dynamic(TraceEvent *ev); |
| 158 | |
| 159 | /** |
Lluís Vilanova | 4815185 | 2016-07-11 12:53:41 +0200 | [diff] [blame] | 160 | * trace_event_get_vcpu_state_dynamic: |
| 161 | * |
| 162 | * Get the dynamic tracing state of an event for the given vCPU. |
| 163 | */ |
| 164 | static bool trace_event_get_vcpu_state_dynamic(CPUState *vcpu, TraceEvent *ev); |
| 165 | |
Lluís Vilanova | 4815185 | 2016-07-11 12:53:41 +0200 | [diff] [blame] | 166 | |
| 167 | /** |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 168 | * trace_event_set_state_dynamic: |
| 169 | * |
| 170 | * Set the dynamic tracing state of an event. |
| 171 | * |
Lluís Vilanova | 4815185 | 2016-07-11 12:53:41 +0200 | [diff] [blame] | 172 | * If the event has the 'vcpu' property, sets the state on all vCPUs. |
| 173 | * |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 174 | * Pre-condition: trace_event_get_state_static(ev) == true |
| 175 | */ |
Lluís Vilanova | 4815185 | 2016-07-11 12:53:41 +0200 | [diff] [blame] | 176 | void trace_event_set_state_dynamic(TraceEvent *ev, bool state); |
| 177 | |
| 178 | /** |
| 179 | * trace_event_set_vcpu_state_dynamic: |
| 180 | * |
| 181 | * Set the dynamic tracing state of an event for the given vCPU. |
| 182 | * |
| 183 | * Pre-condition: trace_event_get_vcpu_state_static(ev) == true |
Lluís Vilanova | 61a67f7 | 2017-07-04 10:42:32 +0200 | [diff] [blame] | 184 | * |
| 185 | * Note: Changes for execution-time events with the 'tcg' property will not be |
| 186 | * propagated until the next TB is executed (iff executing in TCG mode). |
Lluís Vilanova | 4815185 | 2016-07-11 12:53:41 +0200 | [diff] [blame] | 187 | */ |
| 188 | void trace_event_set_vcpu_state_dynamic(CPUState *vcpu, |
| 189 | TraceEvent *ev, bool state); |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 190 | |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 191 | |
| 192 | |
| 193 | /** |
Lluís Vilanova | 5b80827 | 2014-05-27 15:02:14 +0200 | [diff] [blame] | 194 | * trace_init_backends: |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 195 | * @file: Name of trace output file; may be NULL. |
Yaowei Bai | db817b8 | 2018-07-04 11:17:27 +0800 | [diff] [blame] | 196 | * Corresponds to commandline option "--trace file=...". |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 197 | * |
| 198 | * Initialize the tracing backend. |
| 199 | * |
Lluís Vilanova | 5b80827 | 2014-05-27 15:02:14 +0200 | [diff] [blame] | 200 | * Returns: Whether the backends could be successfully initialized. |
Lluís | e485897 | 2011-08-31 20:31:03 +0200 | [diff] [blame] | 201 | */ |
Paolo Bonzini | 41fc57e | 2016-01-07 16:55:24 +0300 | [diff] [blame] | 202 | bool trace_init_backends(void); |
Paolo Bonzini | 45bd0b4 | 2016-01-07 16:55:23 +0300 | [diff] [blame] | 203 | |
| 204 | /** |
Paolo Bonzini | 41fc57e | 2016-01-07 16:55:24 +0300 | [diff] [blame] | 205 | * trace_init_file: |
| 206 | * @file: Name of trace output file; may be NULL. |
Yaowei Bai | db817b8 | 2018-07-04 11:17:27 +0800 | [diff] [blame] | 207 | * Corresponds to commandline option "--trace file=...". |
Paolo Bonzini | 41fc57e | 2016-01-07 16:55:24 +0300 | [diff] [blame] | 208 | * |
| 209 | * Record the name of the output file for the tracing backend. |
| 210 | * Exits if no selected backend does not support specifying the |
| 211 | * output file, and a non-NULL file was passed. |
| 212 | */ |
| 213 | void trace_init_file(const char *file); |
| 214 | |
Paolo Bonzini | 10578a2 | 2016-01-07 16:55:26 +0300 | [diff] [blame] | 215 | /** |
Lluís Vilanova | 2bfe11c | 2016-09-19 14:55:07 +0200 | [diff] [blame] | 216 | * trace_init_vcpu: |
| 217 | * @vcpu: Added vCPU. |
| 218 | * |
| 219 | * Set initial dynamic event state for a hot-plugged vCPU. |
| 220 | */ |
| 221 | void trace_init_vcpu(CPUState *vcpu); |
| 222 | |
| 223 | /** |
Lluís Vilanova | 82e95ec | 2016-12-26 22:24:40 +0100 | [diff] [blame] | 224 | * trace_fini_vcpu: |
| 225 | * @vcpu: Removed vCPU. |
| 226 | * |
| 227 | * Disable dynamic event state for a hot-unplugged vCPU. |
| 228 | */ |
| 229 | void trace_fini_vcpu(CPUState *vcpu); |
| 230 | |
| 231 | /** |
Paolo Bonzini | e9527dd | 2016-01-07 16:55:27 +0300 | [diff] [blame] | 232 | * trace_list_events: |
| 233 | * |
| 234 | * List all available events. |
| 235 | */ |
| 236 | void trace_list_events(void); |
| 237 | |
| 238 | /** |
Paolo Bonzini | 10578a2 | 2016-01-07 16:55:26 +0300 | [diff] [blame] | 239 | * trace_enable_events: |
| 240 | * @line_buf: A string with a glob pattern of events to be enabled or, |
| 241 | * if the string starts with '-', disabled. |
| 242 | * |
| 243 | * Enable or disable matching events. |
| 244 | */ |
| 245 | void trace_enable_events(const char *line_buf); |
| 246 | |
Denis V. Lunev | e9e0bb2 | 2016-06-17 17:44:10 +0300 | [diff] [blame] | 247 | /** |
| 248 | * Definition of QEMU options describing trace subsystem configuration |
| 249 | */ |
| 250 | extern QemuOptsList qemu_trace_opts; |
| 251 | |
| 252 | /** |
| 253 | * trace_opt_parse: |
| 254 | * @optarg: A string argument of --trace command line argument |
| 255 | * |
| 256 | * Initialize tracing subsystem. |
| 257 | * |
| 258 | * Returns the filename to save trace to. It must be freed with g_free(). |
| 259 | */ |
| 260 | char *trace_opt_parse(const char *optarg); |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 261 | |
Daniel P. Berrange | b7d4895 | 2016-10-04 14:35:53 +0100 | [diff] [blame] | 262 | /** |
| 263 | * trace_get_vcpu_event_count: |
| 264 | * |
| 265 | * Return the number of known vcpu-specific events |
| 266 | */ |
| 267 | uint32_t trace_get_vcpu_event_count(void); |
| 268 | |
Lluís Vilanova | 4815185 | 2016-07-11 12:53:41 +0200 | [diff] [blame] | 269 | |
Michael S. Tsirkin | a322714 | 2018-05-03 22:50:28 +0300 | [diff] [blame] | 270 | #include "control-internal.h" |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 271 | |
Markus Armbruster | 175de52 | 2016-06-29 15:29:06 +0200 | [diff] [blame] | 272 | #endif /* TRACE__CONTROL_H */ |