control.h 3.9 KB
Newer Older
1 2 3
/*
 * Interface for configuring and controlling the state of tracing events.
 *
L
Lluís Vilanova 已提交
4
 * Copyright (C) 2011-2014 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 "trace/generated-events.h"
15 16


17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
/**
 * TraceEventID:
 *
 * Unique tracing event identifier.
 *
 * These are named as 'TRACE_${EVENT_NAME}'.
 *
 * See also: "trace/generated-events.h"
 */
enum TraceEventID;

/**
 * trace_event_id:
 * @id: Event identifier.
 *
 * Get an event by its identifier.
 *
 * This routine has a constant cost, as opposed to trace_event_name and
 * trace_event_pattern.
 *
 * Pre-conditions: The identifier is valid.
 *
 * Returns: pointer to #TraceEvent.
 *
 */
static TraceEvent *trace_event_id(TraceEventID id);

/**
 * 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_pattern:
 * @pat: Event name pattern.
 * @ev: Event to start searching from (not included).
 *
 * Get all events with a given name pattern.
 *
 * Returns: pointer to #TraceEvent or NULL if not found.
 */
TraceEvent *trace_event_pattern(const char *pat, TraceEvent *ev);

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

/**
 * trace_event_count:
 *
 * Return the number of events.
 */
static TraceEventID trace_event_count(void);



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

/**
 * 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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
/**
 * trace_event_get_state:
 * @id: Event identifier.
 *
 * Get the tracing state of an event (both static and dynamic).
 *
 * If the event has the disabled property, the check will have no performance
 * impact.
 *
 * As a down side, you must always use an immediate #TraceEventID value.
 */
#define trace_event_get_state(id)                       \
    ((id ##_ENABLED) && trace_event_get_state_dynamic(trace_event_id(id)))

/**
 * 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.
 */
static bool trace_event_get_state_dynamic(TraceEvent *ev);

/**
 * trace_event_set_state:
 *
 * Set the tracing state of an event (only if possible).
 */
#define trace_event_set_state(id, state)                \
    do {                                                \
        if ((id ##_ENABLED)) {                          \
            TraceEvent *_e = trace_event_id(id);        \
            trace_event_set_state_dynamic(_e, state);   \
        }                                               \
    } while (0)

/**
 * trace_event_set_state_dynamic:
 *
 * Set the dynamic tracing state of an event.
 *
 * Pre-condition: trace_event_get_state_static(ev) == true
 */
static void trace_event_set_state_dynamic(TraceEvent *ev, bool state);



/**
L
Lluís Vilanova 已提交
152
 * trace_init_backends:
153 154 155 156
 * @events: Name of file with events to be enabled at startup; may be NULL.
 *          Corresponds to commandline option "-trace events=...".
 * @file:   Name of trace output file; may be NULL.
 *          Corresponds to commandline option "-trace file=...".
157
 *
158 159
 * Initialize the tracing backend.
 *
L
Lluís Vilanova 已提交
160
 * Returns: Whether the backends could be successfully initialized.
161
 */
L
Lluís Vilanova 已提交
162
bool trace_init_backends(const char *events, const char *file);
163

164 165 166 167

#include "trace/control-internal.h"

#endif  /* TRACE__CONTROL_H */