char/serial: cosmetic fixes.
[qemu.git] / trace / control.h
blobcde8260a8a95c32b6d5c84fd8e941f79e1c89f82
1 /*
2 * Interface for configuring and controlling the state of tracing events.
4 * Copyright (C) 2011-2012 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.
8 */
10 #ifndef TRACE__CONTROL_H
11 #define TRACE__CONTROL_H
13 #include "qemu-common.h"
14 #include "trace/generated-events.h"
17 /**
18 * TraceEventID:
20 * Unique tracing event identifier.
22 * These are named as 'TRACE_${EVENT_NAME}'.
24 * See also: "trace/generated-events.h"
26 enum TraceEventID;
28 /**
29 * trace_event_id:
30 * @id: Event identifier.
32 * Get an event by its identifier.
34 * This routine has a constant cost, as opposed to trace_event_name and
35 * trace_event_pattern.
37 * Pre-conditions: The identifier is valid.
39 * Returns: pointer to #TraceEvent.
42 static TraceEvent *trace_event_id(TraceEventID id);
44 /**
45 * trace_event_name:
46 * @id: Event name.
48 * Search an event by its name.
50 * Returns: pointer to #TraceEvent or NULL if not found.
52 TraceEvent *trace_event_name(const char *name);
54 /**
55 * trace_event_pattern:
56 * @pat: Event name pattern.
57 * @ev: Event to start searching from (not included).
59 * Get all events with a given name pattern.
61 * Returns: pointer to #TraceEvent or NULL if not found.
63 TraceEvent *trace_event_pattern(const char *pat, TraceEvent *ev);
65 /**
66 * trace_event_is_pattern:
68 * Whether the given string is an event name pattern.
70 static bool trace_event_is_pattern(const char *str);
72 /**
73 * trace_event_count:
75 * Return the number of events.
77 static TraceEventID trace_event_count(void);
81 /**
82 * trace_event_get_id:
84 * Get the identifier of an event.
86 static TraceEventID trace_event_get_id(TraceEvent *ev);
88 /**
89 * trace_event_get_name:
91 * Get the name of an event.
93 static const char * trace_event_get_name(TraceEvent *ev);
95 /**
96 * trace_event_get_state:
97 * @id: Event identifier.
99 * Get the tracing state of an event (both static and dynamic).
101 * If the event has the disabled property, the check will have no performance
102 * impact.
104 * As a down side, you must always use an immediate #TraceEventID value.
106 #define trace_event_get_state(id) \
107 ((id ##_ENABLED) && trace_event_get_state_dynamic(trace_event_id(id)))
110 * trace_event_get_state_static:
111 * @id: Event identifier.
113 * Get the static tracing state of an event.
115 * Use the define 'TRACE_${EVENT_NAME}_ENABLED' for compile-time checks (it will
116 * be set to 1 or 0 according to the presence of the disabled property).
118 static bool trace_event_get_state_static(TraceEvent *ev);
121 * trace_event_get_state_dynamic:
123 * Get the dynamic tracing state of an event.
125 static bool trace_event_get_state_dynamic(TraceEvent *ev);
128 * trace_event_set_state:
130 * Set the tracing state of an event (only if possible).
132 #define trace_event_set_state(id, state) \
133 do { \
134 if ((id ##_ENABLED)) { \
135 TraceEvent *_e = trace_event_id(id); \
136 trace_event_set_state_dynamic(_e, state); \
138 } while (0)
141 * trace_event_set_state_dynamic:
143 * Set the dynamic tracing state of an event.
145 * Pre-condition: trace_event_get_state_static(ev) == true
147 static void trace_event_set_state_dynamic(TraceEvent *ev, bool state);
150 * trace_event_set_state_dynamic_backend:
152 * Warning: This function must be implemented by each tracing backend.
154 void trace_event_set_state_dynamic_backend(TraceEvent *ev, bool state);
159 * trace_print_events:
161 * Print the state of all events.
163 * Warning: This function must be implemented by each tracing backend.
165 void trace_print_events(FILE *stream, fprintf_function stream_printf);
168 * trace_backend_init:
169 * @events: Name of file with events to be enabled at startup; may be NULL.
170 * Corresponds to commandline option "-trace events=...".
171 * @file: Name of trace output file; may be NULL.
172 * Corresponds to commandline option "-trace file=...".
174 * Initialize the tracing backend.
176 * Warning: This function must be implemented by each tracing backend.
178 * Returns: Whether the backend could be successfully initialized.
180 bool trace_backend_init(const char *events, const char *file);
183 * trace_backend_init_events:
184 * @fname: Name of file with events to enable; may be NULL.
186 * Generic function to initialize the state of events.
188 void trace_backend_init_events(const char *fname);
191 #include "trace/control-internal.h"
193 #endif /* TRACE__CONTROL_H */