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 "event-internal.h"
16 typedef struct TraceEventIter
{
24 * trace_event_iter_init:
25 * @iter: the event iterator struct
26 * @pattern: optional pattern to filter events on name
28 * Initialize the event iterator struct @iter,
29 * optionally using @pattern to filter out events
30 * with non-matching names.
32 void trace_event_iter_init(TraceEventIter
*iter
, const char *pattern
);
35 * trace_event_iter_next:
36 * @iter: the event iterator struct
38 * Get the next event, if any. When this returns NULL,
39 * the iterator should no longer be used.
41 * Returns: the next event, or NULL if no more events exist
43 TraceEvent
*trace_event_iter_next(TraceEventIter
*iter
);
50 * Search an event by its name.
52 * Returns: pointer to #TraceEvent or NULL if not found.
54 TraceEvent
*trace_event_name(const char *name
);
57 * trace_event_is_pattern:
59 * Whether the given string is an event name pattern.
61 static bool trace_event_is_pattern(const char *str
);
67 * Get the identifier of an event.
69 static uint32_t trace_event_get_id(TraceEvent
*ev
);
72 * trace_event_get_vcpu_id:
74 * Get the per-vCPU identifier of an event.
76 * Special value #TRACE_VCPU_EVENT_NONE means the event is not vCPU-specific
77 * (does not have the "vcpu" property).
79 static uint32_t trace_event_get_vcpu_id(TraceEvent
*ev
);
82 * trace_event_is_vcpu:
84 * Whether this is a per-vCPU event.
86 static bool trace_event_is_vcpu(TraceEvent
*ev
);
89 * trace_event_get_name:
91 * Get the name of an event.
93 static const char * trace_event_get_name(TraceEvent
*ev
);
96 * trace_event_get_state:
97 * @id: Event identifier name.
99 * Get the tracing state of an event, both static and the QEMU dynamic state.
101 * If the event has the disabled property, the check will have no performance
104 #define trace_event_get_state(id) \
105 ((id ##_ENABLED) && trace_event_get_state_dynamic_by_id(id))
108 * trace_event_get_state_backends:
109 * @id: Event identifier name.
111 * Get the tracing state of an event, both static and dynamic state from all
112 * compiled-in backends.
114 * If the event has the disabled property, the check will have no performance
117 * Returns: true if at least one backend has the event enabled and the event
118 * does not have the disabled property.
120 #define trace_event_get_state_backends(id) \
121 ((id ##_ENABLED) && id ##_BACKEND_DSTATE())
124 * trace_event_get_vcpu_state:
125 * @vcpu: Target vCPU.
126 * @id: Event identifier name.
128 * Get the tracing state of an event (both static and dynamic) for the given
131 * If the event has the disabled property, the check will have no performance
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))
140 * trace_event_get_state_static:
141 * @id: Event identifier.
143 * Get the static tracing state of an event.
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).
148 static bool trace_event_get_state_static(TraceEvent
*ev
);
151 * trace_event_get_state_dynamic:
153 * Get the dynamic tracing state of an event.
155 * If the event has the 'vcpu' property, gets the OR'ed state of all vCPUs.
157 static bool trace_event_get_state_dynamic(TraceEvent
*ev
);
160 * trace_event_get_vcpu_state_dynamic:
162 * Get the dynamic tracing state of an event for the given vCPU.
164 static bool trace_event_get_vcpu_state_dynamic(CPUState
*vcpu
, TraceEvent
*ev
);
168 * trace_event_set_state_dynamic:
170 * Set the dynamic tracing state of an event.
172 * If the event has the 'vcpu' property, sets the state on all vCPUs.
174 * Pre-condition: trace_event_get_state_static(ev) == true
176 void trace_event_set_state_dynamic(TraceEvent
*ev
, bool state
);
179 * trace_event_set_vcpu_state_dynamic:
181 * Set the dynamic tracing state of an event for the given vCPU.
183 * Pre-condition: trace_event_get_vcpu_state_static(ev) == true
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).
188 void trace_event_set_vcpu_state_dynamic(CPUState
*vcpu
,
189 TraceEvent
*ev
, bool state
);
194 * trace_init_backends:
195 * @file: Name of trace output file; may be NULL.
196 * Corresponds to commandline option "-trace file=...".
198 * Initialize the tracing backend.
200 * Returns: Whether the backends could be successfully initialized.
202 bool trace_init_backends(void);
206 * @file: Name of trace output file; may be NULL.
207 * Corresponds to commandline option "-trace file=...".
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.
213 void trace_init_file(const char *file
);
219 * Set initial dynamic event state for a hot-plugged vCPU.
221 void trace_init_vcpu(CPUState
*vcpu
);
225 * @vcpu: Removed vCPU.
227 * Disable dynamic event state for a hot-unplugged vCPU.
229 void trace_fini_vcpu(CPUState
*vcpu
);
234 * List all available events.
236 void trace_list_events(void);
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.
243 * Enable or disable matching events.
245 void trace_enable_events(const char *line_buf
);
248 * Definition of QEMU options describing trace subsystem configuration
250 extern QemuOptsList qemu_trace_opts
;
254 * @optarg: A string argument of --trace command line argument
256 * Initialize tracing subsystem.
258 * Returns the filename to save trace to. It must be freed with g_free().
260 char *trace_opt_parse(const char *optarg
);
263 * trace_get_vcpu_event_count:
265 * Return the number of known vcpu-specific events
267 uint32_t trace_get_vcpu_event_count(void);
270 #include "control-internal.h"
272 #endif /* TRACE__CONTROL_H */