2 * Interface for configuring and controlling the state of tracing events.
4 * Copyright (C) 2011-2016 LluĂs Vilanova <vilanova@ac.upc.edu>
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.
10 #ifndef TRACE__CONTROL_H
11 #define TRACE__CONTROL_H
13 #include "qemu-common.h"
14 #include "qemu/typedefs.h"
15 #include "trace/generated-events.h"
21 * Unique tracing event identifier.
23 * These are named as 'TRACE_${EVENT_NAME}'.
25 * See also: "trace/generated-events.h"
31 * @id: Event identifier.
33 * Get an event by its identifier.
35 * This routine has a constant cost, as opposed to trace_event_name and
36 * trace_event_pattern.
38 * Pre-conditions: The identifier is valid.
40 * Returns: pointer to #TraceEvent.
43 static TraceEvent
*trace_event_id(TraceEventID id
);
49 * Search an event by its name.
51 * Returns: pointer to #TraceEvent or NULL if not found.
53 TraceEvent
*trace_event_name(const char *name
);
56 * trace_event_pattern:
57 * @pat: Event name pattern.
58 * @ev: Event to start searching from (not included).
60 * Get all events with a given name pattern.
62 * Returns: pointer to #TraceEvent or NULL if not found.
64 TraceEvent
*trace_event_pattern(const char *pat
, TraceEvent
*ev
);
67 * trace_event_is_pattern:
69 * Whether the given string is an event name pattern.
71 static bool trace_event_is_pattern(const char *str
);
76 * Return the number of events.
78 static TraceEventID
trace_event_count(void);
85 * Get the identifier of an event.
87 static TraceEventID
trace_event_get_id(TraceEvent
*ev
);
90 * trace_event_get_name:
92 * Get the name of an event.
94 static const char * trace_event_get_name(TraceEvent
*ev
);
97 * trace_event_get_state:
98 * @id: Event identifier.
100 * Get the tracing state of an event (both static and dynamic).
102 * If the event has the disabled property, the check will have no performance
105 * As a down side, you must always use an immediate #TraceEventID value.
107 #define trace_event_get_state(id) \
108 ((id ##_ENABLED) && trace_event_get_state_dynamic_by_id(id))
111 * trace_event_get_state_static:
112 * @id: Event identifier.
114 * Get the static tracing state of an event.
116 * Use the define 'TRACE_${EVENT_NAME}_ENABLED' for compile-time checks (it will
117 * be set to 1 or 0 according to the presence of the disabled property).
119 static bool trace_event_get_state_static(TraceEvent
*ev
);
122 * trace_event_get_state_dynamic:
124 * Get the dynamic tracing state of an event.
126 static bool trace_event_get_state_dynamic(TraceEvent
*ev
);
129 * trace_event_set_state:
131 * Set the tracing state of an event (only if possible).
133 #define trace_event_set_state(id, state) \
135 if ((id ##_ENABLED)) { \
136 TraceEvent *_e = trace_event_id(id); \
137 trace_event_set_state_dynamic(_e, state); \
142 * trace_event_set_state_dynamic:
144 * Set the dynamic tracing state of an event.
146 * Pre-condition: trace_event_get_state_static(ev) == true
148 static void trace_event_set_state_dynamic(TraceEvent
*ev
, bool state
);
153 * trace_init_backends:
154 * @file: Name of trace output file; may be NULL.
155 * Corresponds to commandline option "-trace file=...".
157 * Initialize the tracing backend.
159 * Returns: Whether the backends could be successfully initialized.
161 bool trace_init_backends(void);
165 * @events: Name of file with events to be enabled at startup; may be NULL.
166 * Corresponds to commandline option "-trace events=...".
168 * Read the list of enabled tracing events.
170 * Returns: Whether the backends could be successfully initialized.
172 void trace_init_events(const char *file
);
176 * @file: Name of trace output file; may be NULL.
177 * Corresponds to commandline option "-trace file=...".
179 * Record the name of the output file for the tracing backend.
180 * Exits if no selected backend does not support specifying the
181 * output file, and a non-NULL file was passed.
183 void trace_init_file(const char *file
);
188 * List all available events.
190 void trace_list_events(void);
193 * trace_enable_events:
194 * @line_buf: A string with a glob pattern of events to be enabled or,
195 * if the string starts with '-', disabled.
197 * Enable or disable matching events.
199 void trace_enable_events(const char *line_buf
);
202 #include "trace/control-internal.h"
204 #endif /* TRACE__CONTROL_H */