blob: 4ea53e298683b51955a7a2b2bed00b027b44d04f [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
Lluísfc764102011-08-31 20:31:18 +020013#include "qemu-common.h"
Daniel P. Berrange34770182016-10-04 14:35:55 +010014#include "event-internal.h"
Lluísfc764102011-08-31 20:31:18 +020015
Daniel P. Berrange6a1b0f32016-10-04 14:35:42 +010016typedef struct TraceEventIter {
17 size_t event;
Daniel P. Berrangefe4db842016-10-04 14:35:52 +010018 size_t group;
Daniel P. Berrange6a1b0f32016-10-04 14:35:42 +010019 const char *pattern;
20} TraceEventIter;
Lluísfc764102011-08-31 20:31:18 +020021
Daniel P. Berrange6a1b0f32016-10-04 14:35:42 +010022
23/**
24 * trace_event_iter_init:
25 * @iter: the event iterator struct
26 * @pattern: optional pattern to filter events on name
27 *
28 * Initialize the event iterator struct @iter,
29 * optionally using @pattern to filter out events
30 * with non-matching names.
31 */
32void trace_event_iter_init(TraceEventIter *iter, const char *pattern);
33
34/**
35 * trace_event_iter_next:
36 * @iter: the event iterator struct
37 *
38 * Get the next event, if any. When this returns NULL,
39 * the iterator should no longer be used.
40 *
41 * Returns: the next event, or NULL if no more events exist
42 */
43TraceEvent *trace_event_iter_next(TraceEventIter *iter);
44
Lluís Vilanovab1bae812013-03-05 14:47:38 +010045
46/**
47 * trace_event_name:
48 * @id: Event name.
49 *
50 * Search an event by its name.
51 *
52 * Returns: pointer to #TraceEvent or NULL if not found.
53 */
54TraceEvent *trace_event_name(const char *name);
55
56/**
Lluís Vilanovab1bae812013-03-05 14:47:38 +010057 * trace_event_is_pattern:
58 *
59 * Whether the given string is an event name pattern.
60 */
61static bool trace_event_is_pattern(const char *str);
62
Lluís Vilanovab1bae812013-03-05 14:47:38 +010063
64/**
65 * trace_event_get_id:
66 *
67 * Get the identifier of an event.
68 */
Daniel P. Berrangeef4c9fc2016-10-04 14:35:49 +010069static uint32_t trace_event_get_id(TraceEvent *ev);
Lluís Vilanovab1bae812013-03-05 14:47:38 +010070
71/**
Lluís Vilanova17f7ac72016-07-11 12:53:24 +020072 * trace_event_get_vcpu_id:
73 *
74 * Get the per-vCPU identifier of an event.
75 *
Daniel P. Berrangeef4c9fc2016-10-04 14:35:49 +010076 * Special value #TRACE_VCPU_EVENT_NONE means the event is not vCPU-specific
Lluís Vilanova17f7ac72016-07-11 12:53:24 +020077 * (does not have the "vcpu" property).
78 */
Daniel P. Berrangeef4c9fc2016-10-04 14:35:49 +010079static uint32_t trace_event_get_vcpu_id(TraceEvent *ev);
Lluís Vilanova17f7ac72016-07-11 12:53:24 +020080
81/**
82 * trace_event_is_vcpu:
83 *
84 * Whether this is a per-vCPU event.
85 */
86static bool trace_event_is_vcpu(TraceEvent *ev);
87
88/**
Lluís Vilanovab1bae812013-03-05 14:47:38 +010089 * trace_event_get_name:
90 *
91 * Get the name of an event.
92 */
93static const char * trace_event_get_name(TraceEvent *ev);
94
95/**
96 * trace_event_get_state:
Daniel P. Berrangeef4c9fc2016-10-04 14:35:49 +010097 * @id: Event identifier name.
Lluís Vilanovab1bae812013-03-05 14:47:38 +010098 *
99 * Get the tracing state of an event (both static and dynamic).
100 *
101 * If the event has the disabled property, the check will have no performance
102 * impact.
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100103 */
104#define trace_event_get_state(id) \
Paolo Bonzini585ec722015-10-28 07:06:27 +0100105 ((id ##_ENABLED) && trace_event_get_state_dynamic_by_id(id))
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100106
107/**
Lluís Vilanova48151852016-07-11 12:53:41 +0200108 * trace_event_get_vcpu_state:
109 * @vcpu: Target vCPU.
Daniel P. Berrangeef4c9fc2016-10-04 14:35:49 +0100110 * @id: Event identifier name.
Lluís Vilanova48151852016-07-11 12:53:41 +0200111 *
112 * Get the tracing state of an event (both static and dynamic) for the given
113 * vCPU.
114 *
115 * If the event has the disabled property, the check will have no performance
116 * impact.
Lluís Vilanova48151852016-07-11 12:53:41 +0200117 */
Daniel P. Berrangeef4c9fc2016-10-04 14:35:49 +0100118#define trace_event_get_vcpu_state(vcpu, id) \
119 ((id ##_ENABLED) && \
120 trace_event_get_vcpu_state_dynamic_by_vcpu_id( \
121 vcpu, _ ## id ## _EVENT.vcpu_id))
Lluís Vilanova48151852016-07-11 12:53:41 +0200122
123/**
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100124 * trace_event_get_state_static:
125 * @id: Event identifier.
126 *
127 * Get the static tracing state of an event.
128 *
129 * Use the define 'TRACE_${EVENT_NAME}_ENABLED' for compile-time checks (it will
130 * be set to 1 or 0 according to the presence of the disabled property).
131 */
132static bool trace_event_get_state_static(TraceEvent *ev);
133
134/**
135 * trace_event_get_state_dynamic:
136 *
137 * Get the dynamic tracing state of an event.
Lluís Vilanova48151852016-07-11 12:53:41 +0200138 *
139 * If the event has the 'vcpu' property, gets the OR'ed state of all vCPUs.
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100140 */
141static bool trace_event_get_state_dynamic(TraceEvent *ev);
142
143/**
Lluís Vilanova48151852016-07-11 12:53:41 +0200144 * trace_event_get_vcpu_state_dynamic:
145 *
146 * Get the dynamic tracing state of an event for the given vCPU.
147 */
148static bool trace_event_get_vcpu_state_dynamic(CPUState *vcpu, TraceEvent *ev);
149
Lluís Vilanova48151852016-07-11 12:53:41 +0200150
151/**
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100152 * trace_event_set_state_dynamic:
153 *
154 * Set the dynamic tracing state of an event.
155 *
Lluís Vilanova48151852016-07-11 12:53:41 +0200156 * If the event has the 'vcpu' property, sets the state on all vCPUs.
157 *
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100158 * Pre-condition: trace_event_get_state_static(ev) == true
159 */
Lluís Vilanova48151852016-07-11 12:53:41 +0200160void trace_event_set_state_dynamic(TraceEvent *ev, bool state);
161
162/**
163 * trace_event_set_vcpu_state_dynamic:
164 *
165 * Set the dynamic tracing state of an event for the given vCPU.
166 *
167 * Pre-condition: trace_event_get_vcpu_state_static(ev) == true
168 */
169void trace_event_set_vcpu_state_dynamic(CPUState *vcpu,
170 TraceEvent *ev, bool state);
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100171
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100172
173
174/**
Lluís Vilanova5b808272014-05-27 15:02:14 +0200175 * trace_init_backends:
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100176 * @file: Name of trace output file; may be NULL.
177 * Corresponds to commandline option "-trace file=...".
178 *
179 * Initialize the tracing backend.
180 *
Lluís Vilanova5b808272014-05-27 15:02:14 +0200181 * Returns: Whether the backends could be successfully initialized.
Lluíse4858972011-08-31 20:31:03 +0200182 */
Paolo Bonzini41fc57e2016-01-07 16:55:24 +0300183bool trace_init_backends(void);
Paolo Bonzini45bd0b42016-01-07 16:55:23 +0300184
185/**
Paolo Bonzini41fc57e2016-01-07 16:55:24 +0300186 * trace_init_file:
187 * @file: Name of trace output file; may be NULL.
188 * Corresponds to commandline option "-trace file=...".
189 *
190 * Record the name of the output file for the tracing backend.
191 * Exits if no selected backend does not support specifying the
192 * output file, and a non-NULL file was passed.
193 */
194void trace_init_file(const char *file);
195
Paolo Bonzini10578a22016-01-07 16:55:26 +0300196/**
Lluís Vilanova2bfe11c2016-09-19 14:55:07 +0200197 * trace_init_vcpu:
198 * @vcpu: Added vCPU.
199 *
200 * Set initial dynamic event state for a hot-plugged vCPU.
201 */
202void trace_init_vcpu(CPUState *vcpu);
203
204/**
Lluís Vilanova82e95ec2016-12-26 22:24:40 +0100205 * trace_fini_vcpu:
206 * @vcpu: Removed vCPU.
207 *
208 * Disable dynamic event state for a hot-unplugged vCPU.
209 */
210void trace_fini_vcpu(CPUState *vcpu);
211
212/**
Paolo Bonzinie9527dd2016-01-07 16:55:27 +0300213 * trace_list_events:
214 *
215 * List all available events.
216 */
217void trace_list_events(void);
218
219/**
Paolo Bonzini10578a22016-01-07 16:55:26 +0300220 * trace_enable_events:
221 * @line_buf: A string with a glob pattern of events to be enabled or,
222 * if the string starts with '-', disabled.
223 *
224 * Enable or disable matching events.
225 */
226void trace_enable_events(const char *line_buf);
227
Denis V. Luneve9e0bb22016-06-17 17:44:10 +0300228/**
229 * Definition of QEMU options describing trace subsystem configuration
230 */
231extern QemuOptsList qemu_trace_opts;
232
233/**
234 * trace_opt_parse:
235 * @optarg: A string argument of --trace command line argument
236 *
237 * Initialize tracing subsystem.
238 *
239 * Returns the filename to save trace to. It must be freed with g_free().
240 */
241char *trace_opt_parse(const char *optarg);
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100242
Daniel P. Berrangeb7d48952016-10-04 14:35:53 +0100243/**
244 * trace_get_vcpu_event_count:
245 *
246 * Return the number of known vcpu-specific events
247 */
248uint32_t trace_get_vcpu_event_count(void);
249
Lluís Vilanova48151852016-07-11 12:53:41 +0200250
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100251#include "trace/control-internal.h"
252
Markus Armbruster175de522016-06-29 15:29:06 +0200253#endif /* TRACE__CONTROL_H */