control.h 6.71 KB
Newer Older
1 2 3
/*
 * Interface for configuring and controlling the state of tracing events.
 *
4
 * Copyright (C) 2011-2016 Lluís Vilanova <vilanova@ac.upc.edu>
5
 *
6 7
 * This work is licensed under the terms of the GNU GPL, version 2 or later.
 * See the COPYING file in the top-level directory.
8 9
 */

10 11
#ifndef TRACE__CONTROL_H
#define TRACE__CONTROL_H
12

13
#include "qemu-common.h"
14
#include "event-internal.h"
15

16 17
typedef struct TraceEventIter {
    size_t event;
18
    size_t group;
19 20
    const char *pattern;
} TraceEventIter;
21

22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

/**
 * trace_event_iter_init:
 * @iter: the event iterator struct
 * @pattern: optional pattern to filter events on name
 *
 * Initialize the event iterator struct @iter,
 * optionally using @pattern to filter out events
 * with non-matching names.
 */
void trace_event_iter_init(TraceEventIter *iter, const char *pattern);

/**
 * trace_event_iter_next:
 * @iter: the event iterator struct
 *
 * Get the next event, if any. When this returns NULL,
 * the iterator should no longer be used.
 *
 * Returns: the next event, or NULL if no more events exist
 */
TraceEvent *trace_event_iter_next(TraceEventIter *iter);

45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68

/**
 * trace_event_name:
 * @id: Event name.
 *
 * Search an event by its name.
 *
 * Returns: pointer to #TraceEvent or NULL if not found.
 */
TraceEvent *trace_event_name(const char *name);

/**
 * trace_event_is_pattern:
 *
 * Whether the given string is an event name pattern.
 */
static bool trace_event_is_pattern(const char *str);


/**
 * trace_event_get_id:
 *
 * Get the identifier of an event.
 */
69
static uint32_t trace_event_get_id(TraceEvent *ev);
70

71 72 73 74 75
/**
 * trace_event_get_vcpu_id:
 *
 * Get the per-vCPU identifier of an event.
 *
76
 * Special value #TRACE_VCPU_EVENT_NONE means the event is not vCPU-specific
77 78
 * (does not have the "vcpu" property).
 */
79
static uint32_t trace_event_get_vcpu_id(TraceEvent *ev);
80 81 82 83 84 85 86 87

/**
 * trace_event_is_vcpu:
 *
 * Whether this is a per-vCPU event.
 */
static bool trace_event_is_vcpu(TraceEvent *ev);

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 name.
98
 *
99
 * Get the tracing state of an event, both static and the QEMU dynamic state.
100 101 102 103 104
 *
 * If the event has the disabled property, the check will have no performance
 * impact.
 */
#define trace_event_get_state(id)                       \
105
    ((id ##_ENABLED) && trace_event_get_state_dynamic_by_id(id))
106

107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
/**
 * trace_event_get_state_backends:
 * @id: Event identifier name.
 *
 * Get the tracing state of an event, both static and dynamic state from all
 * compiled-in backends.
 *
 * If the event has the disabled property, the check will have no performance
 * impact.
 *
 * Returns: true if at least one backend has the event enabled and the event
 * does not have the disabled property.
 */
#define trace_event_get_state_backends(id)              \
    ((id ##_ENABLED) && id ##_BACKEND_DSTATE())

123 124 125
/**
 * trace_event_get_vcpu_state:
 * @vcpu: Target vCPU.
126
 * @id: Event identifier name.
127 128 129 130 131 132 133
 *
 * Get the tracing state of an event (both static and dynamic) for the given
 * vCPU.
 *
 * If the event has the disabled property, the check will have no performance
 * impact.
 */
134 135 136 137
#define trace_event_get_vcpu_state(vcpu, id)                            \
    ((id ##_ENABLED) &&                                                 \
     trace_event_get_vcpu_state_dynamic_by_vcpu_id(                     \
         vcpu, _ ## id ## _EVENT.vcpu_id))
138

139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
/**
 * trace_event_get_state_static:
 * @id: Event identifier.
 *
 * Get the static tracing state of an event.
 *
 * Use the define 'TRACE_${EVENT_NAME}_ENABLED' for compile-time checks (it will
 * be set to 1 or 0 according to the presence of the disabled property).
 */
static bool trace_event_get_state_static(TraceEvent *ev);

/**
 * trace_event_get_state_dynamic:
 *
 * Get the dynamic tracing state of an event.
154 155
 *
 * If the event has the 'vcpu' property, gets the OR'ed state of all vCPUs.
156 157 158
 */
static bool trace_event_get_state_dynamic(TraceEvent *ev);

159 160 161 162 163 164 165 166
/**
 * trace_event_get_vcpu_state_dynamic:
 *
 * Get the dynamic tracing state of an event for the given vCPU.
 */
static bool trace_event_get_vcpu_state_dynamic(CPUState *vcpu, TraceEvent *ev);


167 168 169 170 171
/**
 * trace_event_set_state_dynamic:
 *
 * Set the dynamic tracing state of an event.
 *
172 173
 * If the event has the 'vcpu' property, sets the state on all vCPUs.
 *
174 175
 * Pre-condition: trace_event_get_state_static(ev) == true
 */
176 177 178 179 180 181 182 183
void trace_event_set_state_dynamic(TraceEvent *ev, bool state);

/**
 * trace_event_set_vcpu_state_dynamic:
 *
 * Set the dynamic tracing state of an event for the given vCPU.
 *
 * Pre-condition: trace_event_get_vcpu_state_static(ev) == true
184 185 186
 *
 * Note: Changes for execution-time events with the 'tcg' property will not be
 *       propagated until the next TB is executed (iff executing in TCG mode).
187 188 189
 */
void trace_event_set_vcpu_state_dynamic(CPUState *vcpu,
                                        TraceEvent *ev, bool state);
190 191 192 193



/**
194
 * trace_init_backends:
195
 * @file:   Name of trace output file; may be NULL.
196
 *          Corresponds to commandline option "--trace file=...".
197
 *
198 199
 * Initialize the tracing backend.
 *
200
 * Returns: Whether the backends could be successfully initialized.
201
 */
202
bool trace_init_backends(void);
203

204 205 206
/**
 * trace_init_file:
 * @file:   Name of trace output file; may be NULL.
207
 *          Corresponds to commandline option "--trace file=...".
208 209 210 211 212 213 214
 *
 * Record the name of the output file for the tracing backend.
 * Exits if no selected backend does not support specifying the
 * output file, and a non-NULL file was passed.
 */
void trace_init_file(const char *file);

215 216 217 218 219 220 221 222
/**
 * trace_init_vcpu:
 * @vcpu: Added vCPU.
 *
 * Set initial dynamic event state for a hot-plugged vCPU.
 */
void trace_init_vcpu(CPUState *vcpu);

223 224 225 226 227 228 229 230
/**
 * trace_fini_vcpu:
 * @vcpu: Removed vCPU.
 *
 * Disable dynamic event state for a hot-unplugged vCPU.
 */
void trace_fini_vcpu(CPUState *vcpu);

Paolo Bonzini's avatar
Paolo Bonzini committed
231 232 233 234 235 236 237
/**
 * trace_list_events:
 *
 * List all available events.
 */
void trace_list_events(void);

238 239 240 241 242 243 244 245 246
/**
 * trace_enable_events:
 * @line_buf: A string with a glob pattern of events to be enabled or,
 *            if the string starts with '-', disabled.
 *
 * Enable or disable matching events.
 */
void trace_enable_events(const char *line_buf);

247 248 249 250 251 252 253 254 255 256 257 258 259 260
/**
 * Definition of QEMU options describing trace subsystem configuration
 */
extern QemuOptsList qemu_trace_opts;

/**
 * trace_opt_parse:
 * @optarg: A string argument of --trace command line argument
 *
 * Initialize tracing subsystem.
 *
 * Returns the filename to save trace to.  It must be freed with g_free().
 */
char *trace_opt_parse(const char *optarg);
261

262 263 264 265 266 267 268
/**
 * trace_get_vcpu_event_count:
 *
 * Return the number of known vcpu-specific events
 */
uint32_t trace_get_vcpu_event_count(void);

269

270
#include "control-internal.h"
271

272
#endif /* TRACE__CONTROL_H */