blob: 1f81c491b693d88f6268c22094304803b5e0c758 [file] [log] [blame]
Lluíse4858972011-08-31 20:31:03 +02001/*
2 * Interface for configuring and controlling the state of tracing events.
3 *
Lluís Vilanova3d211d92016-02-25 17:43:38 +01004 * Copyright (C) 2011-2016 Lluís Vilanova <vilanova@ac.upc.edu>
Lluíse4858972011-08-31 20:31:03 +02005 *
Lluís Vilanovab1bae812013-03-05 14:47:38 +01006 * 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.
Lluíse4858972011-08-31 20:31:03 +02008 */
9
Lluís Vilanovab1bae812013-03-05 14:47:38 +010010#ifndef TRACE__CONTROL_H
11#define TRACE__CONTROL_H
Lluíse4858972011-08-31 20:31:03 +020012
Daniel P. Berrange34770182016-10-04 14:35:55 +010013#include "event-internal.h"
Lluísfc764102011-08-31 20:31:18 +020014
Daniel P. Berrange6a1b0f32016-10-04 14:35:42 +010015typedef struct TraceEventIter {
16 size_t event;
Daniel P. Berrangefe4db842016-10-04 14:35:52 +010017 size_t group;
Daniel P. Berrange6a1b0f32016-10-04 14:35:42 +010018 const char *pattern;
19} TraceEventIter;
Lluísfc764102011-08-31 20:31:18 +020020
Daniel P. Berrange6a1b0f32016-10-04 14:35:42 +010021
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 */
31void 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 */
42TraceEvent *trace_event_iter_next(TraceEventIter *iter);
43
Lluís Vilanovab1bae812013-03-05 14:47:38 +010044
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 */
53TraceEvent *trace_event_name(const char *name);
54
55/**
Lluís Vilanovab1bae812013-03-05 14:47:38 +010056 * trace_event_is_pattern:
57 *
58 * Whether the given string is an event name pattern.
59 */
60static bool trace_event_is_pattern(const char *str);
61
Lluís Vilanovab1bae812013-03-05 14:47:38 +010062
63/**
64 * trace_event_get_id:
65 *
66 * Get the identifier of an event.
67 */
Daniel P. Berrangeef4c9fc2016-10-04 14:35:49 +010068static uint32_t trace_event_get_id(TraceEvent *ev);
Lluís Vilanovab1bae812013-03-05 14:47:38 +010069
70/**
Lluís Vilanova17f7ac72016-07-11 12:53:24 +020071 * trace_event_get_vcpu_id:
72 *
73 * Get the per-vCPU identifier of an event.
74 *
Daniel P. Berrangeef4c9fc2016-10-04 14:35:49 +010075 * Special value #TRACE_VCPU_EVENT_NONE means the event is not vCPU-specific
Lluís Vilanova17f7ac72016-07-11 12:53:24 +020076 * (does not have the "vcpu" property).
77 */
Daniel P. Berrangeef4c9fc2016-10-04 14:35:49 +010078static uint32_t trace_event_get_vcpu_id(TraceEvent *ev);
Lluís Vilanova17f7ac72016-07-11 12:53:24 +020079
80/**
81 * trace_event_is_vcpu:
82 *
83 * Whether this is a per-vCPU event.
84 */
85static bool trace_event_is_vcpu(TraceEvent *ev);
86
87/**
Lluís Vilanovab1bae812013-03-05 14:47:38 +010088 * trace_event_get_name:
89 *
90 * Get the name of an event.
91 */
92static const char * trace_event_get_name(TraceEvent *ev);
93
94/**
95 * trace_event_get_state:
Daniel P. Berrangeef4c9fc2016-10-04 14:35:49 +010096 * @id: Event identifier name.
Lluís Vilanovab1bae812013-03-05 14:47:38 +010097 *
Stefan Hajnoczid87aa132017-07-31 15:07:18 +010098 * Get the tracing state of an event, both static and the QEMU dynamic state.
Lluís Vilanovab1bae812013-03-05 14:47:38 +010099 *
100 * If the event has the disabled property, the check will have no performance
101 * impact.
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100102 */
103#define trace_event_get_state(id) \
Paolo Bonzini585ec722015-10-28 07:06:27 +0100104 ((id ##_ENABLED) && trace_event_get_state_dynamic_by_id(id))
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100105
106/**
Stefan Hajnoczid87aa132017-07-31 15:07:18 +0100107 * trace_event_get_state_backends:
108 * @id: Event identifier name.
109 *
110 * Get the tracing state of an event, both static and dynamic state from all
111 * compiled-in backends.
112 *
113 * If the event has the disabled property, the check will have no performance
114 * impact.
115 *
116 * Returns: true if at least one backend has the event enabled and the event
117 * does not have the disabled property.
118 */
119#define trace_event_get_state_backends(id) \
120 ((id ##_ENABLED) && id ##_BACKEND_DSTATE())
121
122/**
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100123 * 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 */
131static 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.
Lluís Vilanova48151852016-07-11 12:53:41 +0200137 *
138 * If the event has the 'vcpu' property, gets the OR'ed state of all vCPUs.
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100139 */
140static bool trace_event_get_state_dynamic(TraceEvent *ev);
141
142/**
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100143 * trace_event_set_state_dynamic:
144 *
145 * Set the dynamic tracing state of an event.
146 *
Lluís Vilanova48151852016-07-11 12:53:41 +0200147 * If the event has the 'vcpu' property, sets the state on all vCPUs.
148 *
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100149 * Pre-condition: trace_event_get_state_static(ev) == true
150 */
Lluís Vilanova48151852016-07-11 12:53:41 +0200151void trace_event_set_state_dynamic(TraceEvent *ev, bool state);
152
153/**
154 * trace_event_set_vcpu_state_dynamic:
155 *
156 * Set the dynamic tracing state of an event for the given vCPU.
157 *
158 * Pre-condition: trace_event_get_vcpu_state_static(ev) == true
Lluís Vilanova61a67f72017-07-04 10:42:32 +0200159 *
160 * Note: Changes for execution-time events with the 'tcg' property will not be
161 * propagated until the next TB is executed (iff executing in TCG mode).
Lluís Vilanova48151852016-07-11 12:53:41 +0200162 */
163void trace_event_set_vcpu_state_dynamic(CPUState *vcpu,
164 TraceEvent *ev, bool state);
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100165
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100166
167
168/**
Lluís Vilanova5b808272014-05-27 15:02:14 +0200169 * trace_init_backends:
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100170 * @file: Name of trace output file; may be NULL.
Yaowei Baidb817b82018-07-04 11:17:27 +0800171 * Corresponds to commandline option "--trace file=...".
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100172 *
173 * Initialize the tracing backend.
174 *
Lluís Vilanova5b808272014-05-27 15:02:14 +0200175 * Returns: Whether the backends could be successfully initialized.
Lluíse4858972011-08-31 20:31:03 +0200176 */
Paolo Bonzini41fc57e2016-01-07 16:55:24 +0300177bool trace_init_backends(void);
Paolo Bonzini45bd0b42016-01-07 16:55:23 +0300178
179/**
Paolo Bonzini41fc57e2016-01-07 16:55:24 +0300180 * trace_init_file:
181 * @file: Name of trace output file; may be NULL.
Yaowei Baidb817b82018-07-04 11:17:27 +0800182 * Corresponds to commandline option "--trace file=...".
Paolo Bonzini41fc57e2016-01-07 16:55:24 +0300183 *
184 * Record the name of the output file for the tracing backend.
185 * Exits if no selected backend does not support specifying the
186 * output file, and a non-NULL file was passed.
187 */
188void trace_init_file(const char *file);
189
Paolo Bonzini10578a22016-01-07 16:55:26 +0300190/**
Lluís Vilanova2bfe11c2016-09-19 14:55:07 +0200191 * trace_init_vcpu:
192 * @vcpu: Added vCPU.
193 *
194 * Set initial dynamic event state for a hot-plugged vCPU.
195 */
196void trace_init_vcpu(CPUState *vcpu);
197
198/**
Lluís Vilanova82e95ec2016-12-26 22:24:40 +0100199 * trace_fini_vcpu:
200 * @vcpu: Removed vCPU.
201 *
202 * Disable dynamic event state for a hot-unplugged vCPU.
203 */
204void trace_fini_vcpu(CPUState *vcpu);
205
206/**
Paolo Bonzinie9527dd2016-01-07 16:55:27 +0300207 * trace_list_events:
208 *
209 * List all available events.
210 */
211void trace_list_events(void);
212
213/**
Paolo Bonzini10578a22016-01-07 16:55:26 +0300214 * trace_enable_events:
215 * @line_buf: A string with a glob pattern of events to be enabled or,
216 * if the string starts with '-', disabled.
217 *
218 * Enable or disable matching events.
219 */
220void trace_enable_events(const char *line_buf);
221
Denis V. Luneve9e0bb22016-06-17 17:44:10 +0300222/**
223 * Definition of QEMU options describing trace subsystem configuration
224 */
225extern QemuOptsList qemu_trace_opts;
226
227/**
228 * trace_opt_parse:
229 * @optarg: A string argument of --trace command line argument
230 *
231 * Initialize tracing subsystem.
232 *
233 * Returns the filename to save trace to. It must be freed with g_free().
234 */
235char *trace_opt_parse(const char *optarg);
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100236
Daniel P. Berrangeb7d48952016-10-04 14:35:53 +0100237/**
238 * trace_get_vcpu_event_count:
239 *
240 * Return the number of known vcpu-specific events
241 */
242uint32_t trace_get_vcpu_event_count(void);
243
Lluís Vilanova48151852016-07-11 12:53:41 +0200244
Michael S. Tsirkina3227142018-05-03 22:50:28 +0300245#include "control-internal.h"
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100246
Markus Armbruster175de522016-06-29 15:29:06 +0200247#endif /* TRACE__CONTROL_H */