xref: /openbmc/qemu/trace/qmp.c (revision 7ef295ea)
1 /*
2  * QMP commands for tracing events.
3  *
4  * Copyright (C) 2014 Lluís Vilanova <vilanova@ac.upc.edu>
5  *
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.
8  */
9 
10 #include "qemu/osdep.h"
11 #include "qemu/typedefs.h"
12 #include "qmp-commands.h"
13 #include "trace/control.h"
14 
15 
16 TraceEventInfoList *qmp_trace_event_get_state(const char *name, Error **errp)
17 {
18     TraceEventInfoList *events = NULL;
19     bool found = false;
20     TraceEvent *ev;
21 
22     ev = NULL;
23     while ((ev = trace_event_pattern(name, ev)) != NULL) {
24         TraceEventInfoList *elem = g_new(TraceEventInfoList, 1);
25         elem->value = g_new(TraceEventInfo, 1);
26         elem->value->name = g_strdup(trace_event_get_name(ev));
27         if (!trace_event_get_state_static(ev)) {
28             elem->value->state = TRACE_EVENT_STATE_UNAVAILABLE;
29         } else if (!trace_event_get_state_dynamic(ev)) {
30             elem->value->state = TRACE_EVENT_STATE_DISABLED;
31         } else {
32             elem->value->state = TRACE_EVENT_STATE_ENABLED;
33         }
34         elem->next = events;
35         events = elem;
36         found = true;
37     }
38 
39     if (!found && !trace_event_is_pattern(name)) {
40         error_setg(errp, "unknown event \"%s\"", name);
41     }
42 
43     return events;
44 }
45 
46 void qmp_trace_event_set_state(const char *name, bool enable,
47                                bool has_ignore_unavailable,
48                                bool ignore_unavailable, Error **errp)
49 {
50     bool found = false;
51     TraceEvent *ev;
52 
53     /* Check all selected events are dynamic */
54     ev = NULL;
55     while ((ev = trace_event_pattern(name, ev)) != NULL) {
56         found = true;
57         if (!(has_ignore_unavailable && ignore_unavailable) &&
58             !trace_event_get_state_static(ev)) {
59             error_setg(errp, "cannot set dynamic tracing state for \"%s\"",
60                        trace_event_get_name(ev));
61             return;
62         }
63     }
64     if (!found && !trace_event_is_pattern(name)) {
65         error_setg(errp, "unknown event \"%s\"", name);
66         return;
67     }
68 
69     /* Apply changes */
70     ev = NULL;
71     while ((ev = trace_event_pattern(name, ev)) != NULL) {
72         if (trace_event_get_state_static(ev)) {
73             trace_event_set_state_dynamic(ev, enable);
74         }
75     }
76 }
77