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"
16 static bool check_events(bool ignore_unavailable
, bool is_pattern
,
17 const char *name
, Error
**errp
)
20 TraceEvent
*ev
= trace_event_name(name
);
22 /* error for non-existing event */
24 error_setg(errp
, "unknown event \"%s\"", name
);
28 /* error for unavailable event */
29 if (!ignore_unavailable
&& !trace_event_get_state_static(ev
)) {
30 error_setg(errp
, "event \"%s\" is disabled", name
);
36 /* error for unavailable events */
39 trace_event_iter_init_pattern(&iter
, name
);
40 while ((ev
= trace_event_iter_next(&iter
)) != NULL
) {
41 if (!ignore_unavailable
&& !trace_event_get_state_static(ev
)) {
42 error_setg(errp
, "event \"%s\" is disabled", trace_event_get_name(ev
));
50 TraceEventInfoList
*qmp_trace_event_get_state(const char *name
,
51 bool has_vcpu
, int64_t vcpu
,
54 TraceEventInfoList
*events
= NULL
;
57 bool is_pattern
= trace_event_is_pattern(name
);
60 if (!check_events(true, is_pattern
, name
, errp
)) {
64 /* Get states (all errors checked above) */
65 trace_event_iter_init_pattern(&iter
, name
);
66 while ((ev
= trace_event_iter_next(&iter
)) != NULL
) {
67 TraceEventInfo
*value
;
69 value
= g_new(TraceEventInfo
, 1);
70 value
->name
= g_strdup(trace_event_get_name(ev
));
72 if (!trace_event_get_state_static(ev
)) {
73 value
->state
= TRACE_EVENT_STATE_UNAVAILABLE
;
75 if (trace_event_get_state_dynamic(ev
)) {
76 value
->state
= TRACE_EVENT_STATE_ENABLED
;
78 value
->state
= TRACE_EVENT_STATE_DISABLED
;
81 QAPI_LIST_PREPEND(events
, value
);
87 void qmp_trace_event_set_state(const char *name
, bool enable
,
88 bool has_ignore_unavailable
, bool ignore_unavailable
,
89 bool has_vcpu
, int64_t vcpu
,
94 bool is_pattern
= trace_event_is_pattern(name
);
97 if (!check_events(has_ignore_unavailable
&& ignore_unavailable
,
98 is_pattern
, name
, errp
)) {
102 /* Apply changes (all errors checked above) */
103 trace_event_iter_init_pattern(&iter
, name
);
104 while ((ev
= trace_event_iter_next(&iter
)) != NULL
) {
105 if (!trace_event_get_state_static(ev
)) {
108 trace_event_set_state_dynamic(ev
, enable
);