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