2 * QMP commands for tracing events.
4 * Copyright (C) 2014-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 #include "qemu/osdep.h"
11 #include "qapi/error.h"
12 #include "qapi/qapi-commands-trace.h"
13 #include "control-vcpu.h"
16 static CPUState
*get_cpu(bool has_vcpu
, int vcpu
, Error
**errp
)
19 CPUState
*cpu
= qemu_get_cpu(vcpu
);
21 error_setg(errp
, "invalid vCPU index %u", vcpu
);
29 static bool check_events(bool has_vcpu
, bool ignore_unavailable
, bool is_pattern
,
30 const char *name
, Error
**errp
)
33 TraceEvent
*ev
= trace_event_name(name
);
35 /* error for non-existing event */
37 error_setg(errp
, "unknown event \"%s\"", name
);
41 /* error for non-vcpu event */
42 if (has_vcpu
&& !trace_event_is_vcpu(ev
)) {
43 error_setg(errp
, "event \"%s\" is not vCPU-specific", name
);
47 /* error for unavailable event */
48 if (!ignore_unavailable
&& !trace_event_get_state_static(ev
)) {
49 error_setg(errp
, "event \"%s\" is disabled", name
);
55 /* error for unavailable events */
58 trace_event_iter_init_pattern(&iter
, name
);
59 while ((ev
= trace_event_iter_next(&iter
)) != NULL
) {
60 if (!ignore_unavailable
&& !trace_event_get_state_static(ev
)) {
61 error_setg(errp
, "event \"%s\" is disabled", trace_event_get_name(ev
));
69 TraceEventInfoList
*qmp_trace_event_get_state(const char *name
,
70 bool has_vcpu
, int64_t vcpu
,
74 TraceEventInfoList
*events
= NULL
;
77 bool is_pattern
= trace_event_is_pattern(name
);
80 /* Check provided vcpu */
81 cpu
= get_cpu(has_vcpu
, vcpu
, &err
);
83 error_propagate(errp
, err
);
88 if (!check_events(has_vcpu
, true, is_pattern
, name
, errp
)) {
92 /* Get states (all errors checked above) */
93 trace_event_iter_init_pattern(&iter
, name
);
94 while ((ev
= trace_event_iter_next(&iter
)) != NULL
) {
95 TraceEventInfo
*value
;
96 bool is_vcpu
= trace_event_is_vcpu(ev
);
97 if (has_vcpu
&& !is_vcpu
) {
101 value
= g_new(TraceEventInfo
, 1);
102 value
->vcpu
= is_vcpu
;
103 value
->name
= g_strdup(trace_event_get_name(ev
));
105 if (!trace_event_get_state_static(ev
)) {
106 value
->state
= TRACE_EVENT_STATE_UNAVAILABLE
;
110 if (trace_event_get_vcpu_state_dynamic(cpu
, ev
)) {
111 value
->state
= TRACE_EVENT_STATE_ENABLED
;
113 value
->state
= TRACE_EVENT_STATE_DISABLED
;
116 /* else: already skipped above */
118 if (trace_event_get_state_dynamic(ev
)) {
119 value
->state
= TRACE_EVENT_STATE_ENABLED
;
121 value
->state
= TRACE_EVENT_STATE_DISABLED
;
125 QAPI_LIST_PREPEND(events
, value
);
131 void qmp_trace_event_set_state(const char *name
, bool enable
,
132 bool has_ignore_unavailable
, bool ignore_unavailable
,
133 bool has_vcpu
, int64_t vcpu
,
139 bool is_pattern
= trace_event_is_pattern(name
);
142 /* Check provided vcpu */
143 cpu
= get_cpu(has_vcpu
, vcpu
, &err
);
145 error_propagate(errp
, err
);
150 if (!check_events(has_vcpu
, has_ignore_unavailable
&& ignore_unavailable
,
151 is_pattern
, name
, errp
)) {
155 /* Apply changes (all errors checked above) */
156 trace_event_iter_init_pattern(&iter
, name
);
157 while ((ev
= trace_event_iter_next(&iter
)) != NULL
) {
158 if (!trace_event_get_state_static(ev
) ||
159 (has_vcpu
&& !trace_event_is_vcpu(ev
))) {
163 trace_event_set_vcpu_state_dynamic(cpu
, ev
, enable
);
165 trace_event_set_state_dynamic(ev
, enable
);