Lluís | e485897 | 2011-08-31 20:31:03 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Interface for configuring and controlling the state of tracing events. |
| 3 | * |
Lluís Vilanova | 3d211d9 | 2016-02-25 17:43:38 +0100 | [diff] [blame] | 4 | * Copyright (C) 2011-2016 Lluís Vilanova <vilanova@ac.upc.edu> |
Lluís | e485897 | 2011-08-31 20:31:03 +0200 | [diff] [blame] | 5 | * |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 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. |
Lluís | e485897 | 2011-08-31 20:31:03 +0200 | [diff] [blame] | 8 | */ |
| 9 | |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 10 | #ifndef TRACE__CONTROL_H |
| 11 | #define TRACE__CONTROL_H |
Lluís | e485897 | 2011-08-31 20:31:03 +0200 | [diff] [blame] | 12 | |
Lluís | fc76410 | 2011-08-31 20:31:18 +0200 | [diff] [blame] | 13 | #include "qemu-common.h" |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 14 | #include "trace/generated-events.h" |
Lluís | fc76410 | 2011-08-31 20:31:18 +0200 | [diff] [blame] | 15 | |
| 16 | |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 17 | /** |
| 18 | * TraceEventID: |
Lluís | fc76410 | 2011-08-31 20:31:18 +0200 | [diff] [blame] | 19 | * |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 20 | * Unique tracing event identifier. |
| 21 | * |
| 22 | * These are named as 'TRACE_${EVENT_NAME}'. |
| 23 | * |
| 24 | * See also: "trace/generated-events.h" |
Lluís | fc76410 | 2011-08-31 20:31:18 +0200 | [diff] [blame] | 25 | */ |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 26 | enum TraceEventID; |
Lluís | e485897 | 2011-08-31 20:31:03 +0200 | [diff] [blame] | 27 | |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 28 | /** |
| 29 | * trace_event_id: |
| 30 | * @id: Event identifier. |
Lluís | e485897 | 2011-08-31 20:31:03 +0200 | [diff] [blame] | 31 | * |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 32 | * Get an event by its identifier. |
| 33 | * |
| 34 | * This routine has a constant cost, as opposed to trace_event_name and |
| 35 | * trace_event_pattern. |
| 36 | * |
| 37 | * Pre-conditions: The identifier is valid. |
| 38 | * |
| 39 | * Returns: pointer to #TraceEvent. |
| 40 | * |
| 41 | */ |
| 42 | static TraceEvent *trace_event_id(TraceEventID id); |
| 43 | |
| 44 | /** |
| 45 | * trace_event_name: |
| 46 | * @id: Event name. |
| 47 | * |
| 48 | * Search an event by its name. |
| 49 | * |
| 50 | * Returns: pointer to #TraceEvent or NULL if not found. |
| 51 | */ |
| 52 | TraceEvent *trace_event_name(const char *name); |
| 53 | |
| 54 | /** |
| 55 | * trace_event_pattern: |
| 56 | * @pat: Event name pattern. |
| 57 | * @ev: Event to start searching from (not included). |
| 58 | * |
| 59 | * Get all events with a given name pattern. |
| 60 | * |
| 61 | * Returns: pointer to #TraceEvent or NULL if not found. |
| 62 | */ |
| 63 | TraceEvent *trace_event_pattern(const char *pat, TraceEvent *ev); |
| 64 | |
| 65 | /** |
| 66 | * trace_event_is_pattern: |
| 67 | * |
| 68 | * Whether the given string is an event name pattern. |
| 69 | */ |
| 70 | static bool trace_event_is_pattern(const char *str); |
| 71 | |
| 72 | /** |
| 73 | * trace_event_count: |
| 74 | * |
| 75 | * Return the number of events. |
| 76 | */ |
| 77 | static TraceEventID trace_event_count(void); |
| 78 | |
| 79 | |
| 80 | |
| 81 | /** |
| 82 | * trace_event_get_id: |
| 83 | * |
| 84 | * Get the identifier of an event. |
| 85 | */ |
| 86 | static TraceEventID trace_event_get_id(TraceEvent *ev); |
| 87 | |
| 88 | /** |
| 89 | * trace_event_get_name: |
| 90 | * |
| 91 | * Get the name of an event. |
| 92 | */ |
| 93 | static const char * trace_event_get_name(TraceEvent *ev); |
| 94 | |
| 95 | /** |
| 96 | * trace_event_get_state: |
| 97 | * @id: Event identifier. |
| 98 | * |
| 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. |
| 103 | * |
| 104 | * As a down side, you must always use an immediate #TraceEventID value. |
| 105 | */ |
| 106 | #define trace_event_get_state(id) \ |
Paolo Bonzini | 585ec72 | 2015-10-28 07:06:27 +0100 | [diff] [blame] | 107 | ((id ##_ENABLED) && trace_event_get_state_dynamic_by_id(id)) |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 108 | |
| 109 | /** |
| 110 | * trace_event_get_state_static: |
| 111 | * @id: Event identifier. |
| 112 | * |
| 113 | * Get the static tracing state of an event. |
| 114 | * |
| 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). |
| 117 | */ |
| 118 | static bool trace_event_get_state_static(TraceEvent *ev); |
| 119 | |
| 120 | /** |
| 121 | * trace_event_get_state_dynamic: |
| 122 | * |
| 123 | * Get the dynamic tracing state of an event. |
| 124 | */ |
| 125 | static bool trace_event_get_state_dynamic(TraceEvent *ev); |
| 126 | |
| 127 | /** |
| 128 | * trace_event_set_state: |
| 129 | * |
| 130 | * Set the tracing state of an event (only if possible). |
| 131 | */ |
| 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); \ |
| 137 | } \ |
| 138 | } while (0) |
| 139 | |
| 140 | /** |
| 141 | * trace_event_set_state_dynamic: |
| 142 | * |
| 143 | * Set the dynamic tracing state of an event. |
| 144 | * |
| 145 | * Pre-condition: trace_event_get_state_static(ev) == true |
| 146 | */ |
| 147 | static void trace_event_set_state_dynamic(TraceEvent *ev, bool state); |
| 148 | |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 149 | |
| 150 | |
| 151 | /** |
Lluís Vilanova | 5b80827 | 2014-05-27 15:02:14 +0200 | [diff] [blame] | 152 | * trace_init_backends: |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 153 | * @file: Name of trace output file; may be NULL. |
| 154 | * Corresponds to commandline option "-trace file=...". |
| 155 | * |
| 156 | * Initialize the tracing backend. |
| 157 | * |
Lluís Vilanova | 5b80827 | 2014-05-27 15:02:14 +0200 | [diff] [blame] | 158 | * Returns: Whether the backends could be successfully initialized. |
Lluís | e485897 | 2011-08-31 20:31:03 +0200 | [diff] [blame] | 159 | */ |
Paolo Bonzini | 41fc57e | 2016-01-07 16:55:24 +0300 | [diff] [blame] | 160 | bool trace_init_backends(void); |
Paolo Bonzini | 45bd0b4 | 2016-01-07 16:55:23 +0300 | [diff] [blame] | 161 | |
| 162 | /** |
| 163 | * trace_init_events: |
| 164 | * @events: Name of file with events to be enabled at startup; may be NULL. |
| 165 | * Corresponds to commandline option "-trace events=...". |
| 166 | * |
| 167 | * Read the list of enabled tracing events. |
| 168 | * |
| 169 | * Returns: Whether the backends could be successfully initialized. |
| 170 | */ |
| 171 | void trace_init_events(const char *file); |
Lluís | e485897 | 2011-08-31 20:31:03 +0200 | [diff] [blame] | 172 | |
Paolo Bonzini | 41fc57e | 2016-01-07 16:55:24 +0300 | [diff] [blame] | 173 | /** |
| 174 | * trace_init_file: |
| 175 | * @file: Name of trace output file; may be NULL. |
| 176 | * Corresponds to commandline option "-trace file=...". |
| 177 | * |
| 178 | * Record the name of the output file for the tracing backend. |
| 179 | * Exits if no selected backend does not support specifying the |
| 180 | * output file, and a non-NULL file was passed. |
| 181 | */ |
| 182 | void trace_init_file(const char *file); |
| 183 | |
Paolo Bonzini | 10578a2 | 2016-01-07 16:55:26 +0300 | [diff] [blame] | 184 | /** |
Paolo Bonzini | e9527dd | 2016-01-07 16:55:27 +0300 | [diff] [blame] | 185 | * trace_list_events: |
| 186 | * |
| 187 | * List all available events. |
| 188 | */ |
| 189 | void trace_list_events(void); |
| 190 | |
| 191 | /** |
Paolo Bonzini | 10578a2 | 2016-01-07 16:55:26 +0300 | [diff] [blame] | 192 | * trace_enable_events: |
| 193 | * @line_buf: A string with a glob pattern of events to be enabled or, |
| 194 | * if the string starts with '-', disabled. |
| 195 | * |
| 196 | * Enable or disable matching events. |
| 197 | */ |
| 198 | void trace_enable_events(const char *line_buf); |
| 199 | |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 200 | |
| 201 | #include "trace/control-internal.h" |
| 202 | |
| 203 | #endif /* TRACE__CONTROL_H */ |