2 * Interface for configuring and controlling the state of tracing events.
4 * Copyright (C) 2011-2016 LluĂs Vilanova <vilanova@ac.upc.edu>
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.
10 #ifndef TRACE__CONTROL_H
11 #define TRACE__CONTROL_H
13 #include "qemu-common.h"
14 #include "trace/generated-events.h"
20 * Unique tracing event identifier.
22 * These are named as 'TRACE_${EVENT_NAME}'.
24 * See also: "trace/generated-events.h"
30 * @id: Event identifier.
32 * Get an event by its identifier.
34 * This routine has a constant cost, as opposed to trace_event_name and
35 * trace_event_pattern.
37 * Pre-conditions: The identifier is valid.
39 * Returns: pointer to #TraceEvent.
42 static TraceEvent
*trace_event_id(TraceEventID id
);
48 * Search an event by its name.
50 * Returns: pointer to #TraceEvent or NULL if not found.
52 TraceEvent
*trace_event_name(const char *name
);
55 * trace_event_pattern:
56 * @pat: Event name pattern.
57 * @ev: Event to start searching from (not included).
59 * Get all events with a given name pattern.
61 * Returns: pointer to #TraceEvent or NULL if not found.
63 TraceEvent
*trace_event_pattern(const char *pat
, TraceEvent
*ev
);
66 * trace_event_is_pattern:
68 * Whether the given string is an event name pattern.
70 static bool trace_event_is_pattern(const char *str
);
75 * Return the number of events.
77 static TraceEventID
trace_event_count(void);
84 * Get the identifier of an event.
86 static TraceEventID
trace_event_get_id(TraceEvent
*ev
);
89 * trace_event_get_vcpu_id:
91 * Get the per-vCPU identifier of an event.
93 * Special value #TRACE_VCPU_EVENT_COUNT means the event is not vCPU-specific
94 * (does not have the "vcpu" property).
96 static TraceEventVCPUID
trace_event_get_vcpu_id(TraceEvent
*ev
);
99 * trace_event_is_vcpu:
101 * Whether this is a per-vCPU event.
103 static bool trace_event_is_vcpu(TraceEvent
*ev
);
106 * trace_event_get_name:
108 * Get the name of an event.
110 static const char * trace_event_get_name(TraceEvent
*ev
);
113 * trace_event_get_state:
114 * @id: Event identifier.
116 * Get the tracing state of an event (both static and dynamic).
118 * If the event has the disabled property, the check will have no performance
121 * As a down side, you must always use an immediate #TraceEventID value.
123 #define trace_event_get_state(id) \
124 ((id ##_ENABLED) && trace_event_get_state_dynamic_by_id(id))
127 * trace_event_get_vcpu_state:
128 * @vcpu: Target vCPU.
129 * @id: Event identifier (TraceEventID).
130 * @vcpu_id: Per-vCPU event identifier (TraceEventVCPUID).
132 * Get the tracing state of an event (both static and dynamic) for the given
135 * If the event has the disabled property, the check will have no performance
138 * As a down side, you must always use an immediate #TraceEventID value.
140 #define trace_event_get_vcpu_state(vcpu, id, vcpu_id) \
141 ((id ##_ENABLED) && trace_event_get_vcpu_state_dynamic_by_vcpu_id(vcpu, vcpu_id))
144 * trace_event_get_state_static:
145 * @id: Event identifier.
147 * Get the static tracing state of an event.
149 * Use the define 'TRACE_${EVENT_NAME}_ENABLED' for compile-time checks (it will
150 * be set to 1 or 0 according to the presence of the disabled property).
152 static bool trace_event_get_state_static(TraceEvent
*ev
);
155 * trace_event_get_state_dynamic:
157 * Get the dynamic tracing state of an event.
159 * If the event has the 'vcpu' property, gets the OR'ed state of all vCPUs.
161 static bool trace_event_get_state_dynamic(TraceEvent
*ev
);
164 * trace_event_get_vcpu_state_dynamic:
166 * Get the dynamic tracing state of an event for the given vCPU.
168 static bool trace_event_get_vcpu_state_dynamic(CPUState
*vcpu
, TraceEvent
*ev
);
171 * trace_event_set_state:
173 * Set the tracing state of an event (only if possible).
175 #define trace_event_set_state(id, state) \
177 if ((id ##_ENABLED)) { \
178 TraceEvent *_e = trace_event_id(id); \
179 trace_event_set_state_dynamic(_e, state); \
184 * trace_event_set_vcpu_state:
186 * Set the tracing state of an event for the given vCPU (only if not disabled).
188 #define trace_event_set_vcpu_state(vcpu, id, state) \
190 if ((id ##_ENABLED)) { \
191 TraceEvent *_e = trace_event_id(id); \
192 trace_event_set_vcpu_state_dynamic(vcpu, _e, state); \
197 * trace_event_set_state_dynamic:
199 * Set the dynamic tracing state of an event.
201 * If the event has the 'vcpu' property, sets the state on all vCPUs.
203 * Pre-condition: trace_event_get_state_static(ev) == true
205 void trace_event_set_state_dynamic(TraceEvent
*ev
, bool state
);
208 * trace_event_set_vcpu_state_dynamic:
210 * Set the dynamic tracing state of an event for the given vCPU.
212 * Pre-condition: trace_event_get_vcpu_state_static(ev) == true
214 void trace_event_set_vcpu_state_dynamic(CPUState
*vcpu
,
215 TraceEvent
*ev
, bool state
);
220 * trace_init_backends:
221 * @file: Name of trace output file; may be NULL.
222 * Corresponds to commandline option "-trace file=...".
224 * Initialize the tracing backend.
226 * Returns: Whether the backends could be successfully initialized.
228 bool trace_init_backends(void);
232 * @file: Name of trace output file; may be NULL.
233 * Corresponds to commandline option "-trace file=...".
235 * Record the name of the output file for the tracing backend.
236 * Exits if no selected backend does not support specifying the
237 * output file, and a non-NULL file was passed.
239 void trace_init_file(const char *file
);
244 * List all available events.
246 void trace_list_events(void);
249 * trace_enable_events:
250 * @line_buf: A string with a glob pattern of events to be enabled or,
251 * if the string starts with '-', disabled.
253 * Enable or disable matching events.
255 void trace_enable_events(const char *line_buf
);
258 * Definition of QEMU options describing trace subsystem configuration
260 extern QemuOptsList qemu_trace_opts
;
264 * @optarg: A string argument of --trace command line argument
266 * Initialize tracing subsystem.
268 * Returns the filename to save trace to. It must be freed with g_free().
270 char *trace_opt_parse(const char *optarg
);
273 * trace_init_vcpu_events:
275 * Re-synchronize initial event state with vCPUs (which can be created after
276 * trace_init_events()).
278 void trace_init_vcpu_events(void);
281 #include "trace/control-internal.h"
283 #endif /* TRACE__CONTROL_H */