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