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 "qmp-commands.h"
12 #include "trace/control.h"
15 static CPUState
*get_cpu(bool has_vcpu
, int vcpu
, Error
**errp
)
18 CPUState
*cpu
= qemu_get_cpu(vcpu
);
20 error_setg(errp
, "invalid vCPU index %u", vcpu
);
28 static bool check_events(bool has_vcpu
, bool ignore_unavailable
, bool is_pattern
,
29 const char *name
, Error
**errp
)
32 TraceEvent
*ev
= trace_event_name(name
);
34 /* error for non-existing event */
36 error_setg(errp
, "unknown event \"%s\"", name
);
40 /* error for non-vcpu event */
41 if (has_vcpu
&& !trace_event_is_vcpu(ev
)) {
42 error_setg(errp
, "event \"%s\" is not vCPU-specific", name
);
46 /* error for unavailable event */
47 if (!ignore_unavailable
&& !trace_event_get_state_static(ev
)) {
48 error_setg(errp
, "event \"%s\" is disabled", name
);
54 /* error for unavailable events */
57 trace_event_iter_init(&iter
, name
);
58 while ((ev
= trace_event_iter_next(&iter
)) != NULL
) {
59 if (!ignore_unavailable
&& !trace_event_get_state_static(ev
)) {
60 error_setg(errp
, "event \"%s\" is disabled", trace_event_get_name(ev
));
68 TraceEventInfoList
*qmp_trace_event_get_state(const char *name
,
69 bool has_vcpu
, int64_t vcpu
,
73 TraceEventInfoList
*events
= NULL
;
76 bool is_pattern
= trace_event_is_pattern(name
);
79 /* Check provided vcpu */
80 cpu
= get_cpu(has_vcpu
, vcpu
, &err
);
82 error_propagate(errp
, err
);
87 if (!check_events(has_vcpu
, true, is_pattern
, name
, errp
)) {
91 /* Get states (all errors checked above) */
92 trace_event_iter_init(&iter
, name
);
93 while ((ev
= trace_event_iter_next(&iter
)) != NULL
) {
94 TraceEventInfoList
*elem
;
95 bool is_vcpu
= trace_event_is_vcpu(ev
);
96 if (has_vcpu
&& !is_vcpu
) {
100 elem
= g_new(TraceEventInfoList
, 1);
101 elem
->value
= g_new(TraceEventInfo
, 1);
102 elem
->value
->vcpu
= is_vcpu
;
103 elem
->value
->name
= g_strdup(trace_event_get_name(ev
));
105 if (!trace_event_get_state_static(ev
)) {
106 elem
->value
->state
= TRACE_EVENT_STATE_UNAVAILABLE
;
110 if (trace_event_get_vcpu_state_dynamic(cpu
, ev
)) {
111 elem
->value
->state
= TRACE_EVENT_STATE_ENABLED
;
113 elem
->value
->state
= TRACE_EVENT_STATE_DISABLED
;
116 /* else: already skipped above */
118 if (trace_event_get_state_dynamic(ev
)) {
119 elem
->value
->state
= TRACE_EVENT_STATE_ENABLED
;
121 elem
->value
->state
= TRACE_EVENT_STATE_DISABLED
;
132 void qmp_trace_event_set_state(const char *name
, bool enable
,
133 bool has_ignore_unavailable
, bool ignore_unavailable
,
134 bool has_vcpu
, int64_t vcpu
,
140 bool is_pattern
= trace_event_is_pattern(name
);
143 /* Check provided vcpu */
144 cpu
= get_cpu(has_vcpu
, vcpu
, &err
);
146 error_propagate(errp
, err
);
151 if (!check_events(has_vcpu
, has_ignore_unavailable
&& ignore_unavailable
,
152 is_pattern
, name
, errp
)) {
156 /* Apply changes (all errors checked above) */
157 trace_event_iter_init(&iter
, name
);
158 while ((ev
= trace_event_iter_next(&iter
)) != NULL
) {
159 if (!trace_event_get_state_static(ev
) ||
160 (has_vcpu
&& !trace_event_is_vcpu(ev
))) {
164 trace_event_set_vcpu_state_dynamic(cpu
, ev
, enable
);
166 trace_event_set_state_dynamic(ev
, enable
);