blob: 6754bfe052b8a7eb2f93ebc4f7cc556990ac0d51 [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 {
Gerd Hoffmannc5cc58b2021-06-01 15:24:04 +020016 /* iter state */
Daniel P. Berrange6a1b0f32016-10-04 14:35:42 +010017 size_t event;
Daniel P. Berrangefe4db842016-10-04 14:35:52 +010018 size_t group;
Gerd Hoffmannc5cc58b2021-06-01 15:24:04 +020019 /* filter conditions */
20 size_t group_id;
Daniel P. Berrange6a1b0f32016-10-04 14:35:42 +010021 const char *pattern;
22} TraceEventIter;
Lluísfc764102011-08-31 20:31:18 +020023
Daniel P. Berrange6a1b0f32016-10-04 14:35:42 +010024
25/**
Gerd Hoffmann117856c2021-06-01 15:24:03 +020026 * trace_event_iter_init_all:
Daniel P. Berrange6a1b0f32016-10-04 14:35:42 +010027 * @iter: the event iterator struct
Daniel P. Berrange6a1b0f32016-10-04 14:35:42 +010028 *
29 * Initialize the event iterator struct @iter,
Gerd Hoffmann117856c2021-06-01 15:24:03 +020030 * for all events.
31 */
32void 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
Daniel P. Berrange6a1b0f32016-10-04 14:35:42 +010041 * with non-matching names.
42 */
Gerd Hoffmann117856c2021-06-01 15:24:03 +020043void trace_event_iter_init_pattern(TraceEventIter *iter, const char *pattern);
Daniel P. Berrange6a1b0f32016-10-04 14:35:42 +010044
45/**
Gerd Hoffmannc5cc58b2021-06-01 15:24:04 +020046 * 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 */
53void trace_event_iter_init_group(TraceEventIter *iter, size_t group_id);
54
55/**
Daniel P. Berrange6a1b0f32016-10-04 14:35:42 +010056 * 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 */
64TraceEvent *trace_event_iter_next(TraceEventIter *iter);
65
Lluís Vilanovab1bae812013-03-05 14:47:38 +010066
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 */
75TraceEvent *trace_event_name(const char *name);
76
77/**
Lluís Vilanovab1bae812013-03-05 14:47:38 +010078 * trace_event_is_pattern:
79 *
80 * Whether the given string is an event name pattern.
81 */
82static bool trace_event_is_pattern(const char *str);
83
Lluís Vilanovab1bae812013-03-05 14:47:38 +010084
85/**
86 * trace_event_get_id:
87 *
88 * Get the identifier of an event.
89 */
Daniel P. Berrangeef4c9fc2016-10-04 14:35:49 +010090static uint32_t trace_event_get_id(TraceEvent *ev);
Lluís Vilanovab1bae812013-03-05 14:47:38 +010091
92/**
93 * trace_event_get_name:
94 *
95 * Get the name of an event.
96 */
97static const char * trace_event_get_name(TraceEvent *ev);
98
99/**
100 * trace_event_get_state:
Daniel P. Berrangeef4c9fc2016-10-04 14:35:49 +0100101 * @id: Event identifier name.
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100102 *
Stefan Hajnoczid87aa132017-07-31 15:07:18 +0100103 * Get the tracing state of an event, both static and the QEMU dynamic state.
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100104 *
105 * If the event has the disabled property, the check will have no performance
106 * impact.
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100107 */
108#define trace_event_get_state(id) \
Paolo Bonzini585ec722015-10-28 07:06:27 +0100109 ((id ##_ENABLED) && trace_event_get_state_dynamic_by_id(id))
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100110
111/**
Stefan Hajnoczid87aa132017-07-31 15:07:18 +0100112 * trace_event_get_state_backends:
113 * @id: Event identifier name.
114 *
115 * Get the tracing state of an event, both static and dynamic state from all
116 * compiled-in backends.
117 *
118 * If the event has the disabled property, the check will have no performance
119 * impact.
120 *
121 * Returns: true if at least one backend has the event enabled and the event
122 * does not have the disabled property.
123 */
124#define trace_event_get_state_backends(id) \
125 ((id ##_ENABLED) && id ##_BACKEND_DSTATE())
126
127/**
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100128 * trace_event_get_state_static:
129 * @id: Event identifier.
130 *
131 * Get the static tracing state of an event.
132 *
133 * Use the define 'TRACE_${EVENT_NAME}_ENABLED' for compile-time checks (it will
134 * be set to 1 or 0 according to the presence of the disabled property).
135 */
136static bool trace_event_get_state_static(TraceEvent *ev);
137
138/**
139 * trace_event_get_state_dynamic:
140 *
141 * Get the dynamic tracing state of an event.
Lluís Vilanova48151852016-07-11 12:53:41 +0200142 *
143 * If the event has the 'vcpu' property, gets the OR'ed state of all vCPUs.
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100144 */
145static bool trace_event_get_state_dynamic(TraceEvent *ev);
146
147/**
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100148 * trace_event_set_state_dynamic:
149 *
150 * Set the dynamic tracing state of an event.
151 *
Lluís Vilanova48151852016-07-11 12:53:41 +0200152 * If the event has the 'vcpu' property, sets the state on all vCPUs.
153 *
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100154 * Pre-condition: trace_event_get_state_static(ev) == true
155 */
Lluís Vilanova48151852016-07-11 12:53:41 +0200156void trace_event_set_state_dynamic(TraceEvent *ev, bool state);
157
158/**
Lluís Vilanova5b808272014-05-27 15:02:14 +0200159 * trace_init_backends:
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100160 *
161 * Initialize the tracing backend.
162 *
Lluís Vilanova5b808272014-05-27 15:02:14 +0200163 * Returns: Whether the backends could be successfully initialized.
Lluíse4858972011-08-31 20:31:03 +0200164 */
Paolo Bonzini41fc57e2016-01-07 16:55:24 +0300165bool trace_init_backends(void);
Paolo Bonzini45bd0b42016-01-07 16:55:23 +0300166
167/**
Paolo Bonzini41fc57e2016-01-07 16:55:24 +0300168 * trace_init_file:
Paolo Bonzini41fc57e2016-01-07 16:55:24 +0300169 *
170 * Record the name of the output file for the tracing backend.
171 * Exits if no selected backend does not support specifying the
Paolo Bonzini92eecff2020-11-02 06:58:41 -0500172 * output file, and a file was specified with "-trace file=...".
Paolo Bonzini41fc57e2016-01-07 16:55:24 +0300173 */
Paolo Bonzini92eecff2020-11-02 06:58:41 -0500174void trace_init_file(void);
Paolo Bonzini41fc57e2016-01-07 16:55:24 +0300175
Paolo Bonzini10578a22016-01-07 16:55:26 +0300176/**
Paolo Bonzinie9527dd2016-01-07 16:55:27 +0300177 * trace_list_events:
Doug Evans6745c8a2020-11-25 13:52:45 -0800178 * @f: Where to send output.
Paolo Bonzinie9527dd2016-01-07 16:55:27 +0300179 *
180 * List all available events.
181 */
Doug Evans6745c8a2020-11-25 13:52:45 -0800182void trace_list_events(FILE *f);
Paolo Bonzinie9527dd2016-01-07 16:55:27 +0300183
184/**
Paolo Bonzini10578a22016-01-07 16:55:26 +0300185 * trace_enable_events:
186 * @line_buf: A string with a glob pattern of events to be enabled or,
187 * if the string starts with '-', disabled.
188 *
189 * Enable or disable matching events.
190 */
191void trace_enable_events(const char *line_buf);
192
Denis V. Luneve9e0bb22016-06-17 17:44:10 +0300193/**
194 * Definition of QEMU options describing trace subsystem configuration
195 */
196extern QemuOptsList qemu_trace_opts;
197
198/**
199 * trace_opt_parse:
Philippe Mathieu-Daudé8b7b9c52023-10-04 14:00:19 +0200200 * @optstr: A string argument of --trace command line argument
Denis V. Luneve9e0bb22016-06-17 17:44:10 +0300201 *
202 * Initialize tracing subsystem.
Denis V. Luneve9e0bb22016-06-17 17:44:10 +0300203 */
Philippe Mathieu-Daudé8b7b9c52023-10-04 14:00:19 +0200204void trace_opt_parse(const char *optstr);
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100205
Daniel P. Berrangeb7d48952016-10-04 14:35:53 +0100206/**
207 * trace_get_vcpu_event_count:
208 *
209 * Return the number of known vcpu-specific events
210 */
211uint32_t trace_get_vcpu_event_count(void);
212
Lluís Vilanova48151852016-07-11 12:53:41 +0200213
Michael S. Tsirkina3227142018-05-03 22:50:28 +0300214#include "control-internal.h"
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100215
Markus Armbruster175de522016-06-29 15:29:06 +0200216#endif /* TRACE__CONTROL_H */