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"
16 typedef struct TraceEventIter
{
24 * Unique tracing event identifier.
26 * These are named as 'TRACE_${EVENT_NAME}'.
28 * See also: "trace/generated-events.h"
34 * trace_event_iter_init:
35 * @iter: the event iterator struct
36 * @pattern: optional pattern to filter events on name
38 * Initialize the event iterator struct @iter,
39 * optionally using @pattern to filter out events
40 * with non-matching names.
42 void trace_event_iter_init(TraceEventIter
*iter
, const char *pattern
);
45 * trace_event_iter_next:
46 * @iter: the event iterator struct
48 * Get the next event, if any. When this returns NULL,
49 * the iterator should no longer be used.
51 * Returns: the next event, or NULL if no more events exist
53 TraceEvent
*trace_event_iter_next(TraceEventIter
*iter
);
60 * Search an event by its name.
62 * Returns: pointer to #TraceEvent or NULL if not found.
64 TraceEvent
*trace_event_name(const char *name
);
67 * trace_event_is_pattern:
69 * Whether the given string is an event name pattern.
71 static bool trace_event_is_pattern(const char *str
);
77 * Get the identifier of an event.
79 static TraceEventID
trace_event_get_id(TraceEvent
*ev
);
82 * trace_event_get_vcpu_id:
84 * Get the per-vCPU identifier of an event.
86 * Special value #TRACE_VCPU_EVENT_COUNT means the event is not vCPU-specific
87 * (does not have the "vcpu" property).
89 static TraceEventVCPUID
trace_event_get_vcpu_id(TraceEvent
*ev
);
92 * trace_event_is_vcpu:
94 * Whether this is a per-vCPU event.
96 static bool trace_event_is_vcpu(TraceEvent
*ev
);
99 * trace_event_get_name:
101 * Get the name of an event.
103 static const char * trace_event_get_name(TraceEvent
*ev
);
106 * trace_event_get_state:
107 * @id: Event identifier.
109 * Get the tracing state of an event (both static and dynamic).
111 * If the event has the disabled property, the check will have no performance
114 * As a down side, you must always use an immediate #TraceEventID value.
116 #define trace_event_get_state(id) \
117 ((id ##_ENABLED) && trace_event_get_state_dynamic_by_id(id))
120 * trace_event_get_vcpu_state:
121 * @vcpu: Target vCPU.
122 * @id: Event identifier (TraceEventID).
123 * @vcpu_id: Per-vCPU event identifier (TraceEventVCPUID).
125 * Get the tracing state of an event (both static and dynamic) for the given
128 * If the event has the disabled property, the check will have no performance
131 * As a down side, you must always use an immediate #TraceEventID value.
133 #define trace_event_get_vcpu_state(vcpu, id, vcpu_id) \
134 ((id ##_ENABLED) && trace_event_get_vcpu_state_dynamic_by_vcpu_id(vcpu, vcpu_id))
137 * trace_event_get_state_static:
138 * @id: Event identifier.
140 * Get the static tracing state of an event.
142 * Use the define 'TRACE_${EVENT_NAME}_ENABLED' for compile-time checks (it will
143 * be set to 1 or 0 according to the presence of the disabled property).
145 static bool trace_event_get_state_static(TraceEvent
*ev
);
148 * trace_event_get_state_dynamic:
150 * Get the dynamic tracing state of an event.
152 * If the event has the 'vcpu' property, gets the OR'ed state of all vCPUs.
154 static bool trace_event_get_state_dynamic(TraceEvent
*ev
);
157 * trace_event_get_vcpu_state_dynamic:
159 * Get the dynamic tracing state of an event for the given vCPU.
161 static bool trace_event_get_vcpu_state_dynamic(CPUState
*vcpu
, TraceEvent
*ev
);
165 * trace_event_set_state_dynamic:
167 * Set the dynamic tracing state of an event.
169 * If the event has the 'vcpu' property, sets the state on all vCPUs.
171 * Pre-condition: trace_event_get_state_static(ev) == true
173 void trace_event_set_state_dynamic(TraceEvent
*ev
, bool state
);
176 * trace_event_set_vcpu_state_dynamic:
178 * Set the dynamic tracing state of an event for the given vCPU.
180 * Pre-condition: trace_event_get_vcpu_state_static(ev) == true
182 void trace_event_set_vcpu_state_dynamic(CPUState
*vcpu
,
183 TraceEvent
*ev
, bool state
);
188 * trace_init_backends:
189 * @file: Name of trace output file; may be NULL.
190 * Corresponds to commandline option "-trace file=...".
192 * Initialize the tracing backend.
194 * Returns: Whether the backends could be successfully initialized.
196 bool trace_init_backends(void);
200 * @file: Name of trace output file; may be NULL.
201 * Corresponds to commandline option "-trace file=...".
203 * Record the name of the output file for the tracing backend.
204 * Exits if no selected backend does not support specifying the
205 * output file, and a non-NULL file was passed.
207 void trace_init_file(const char *file
);
213 * Set initial dynamic event state for a hot-plugged vCPU.
215 void trace_init_vcpu(CPUState
*vcpu
);
220 * List all available events.
222 void trace_list_events(void);
225 * trace_enable_events:
226 * @line_buf: A string with a glob pattern of events to be enabled or,
227 * if the string starts with '-', disabled.
229 * Enable or disable matching events.
231 void trace_enable_events(const char *line_buf
);
234 * Definition of QEMU options describing trace subsystem configuration
236 extern QemuOptsList qemu_trace_opts
;
240 * @optarg: A string argument of --trace command line argument
242 * Initialize tracing subsystem.
244 * Returns the filename to save trace to. It must be freed with g_free().
246 char *trace_opt_parse(const char *optarg
);
249 #include "trace/control-internal.h"
251 #endif /* TRACE__CONTROL_H */