]>
Commit | Line | Data |
---|---|---|
1dde0f48 LV |
1 | /* |
2 | * QMP commands for tracing events. | |
3 | * | |
77e2b172 | 4 | * Copyright (C) 2014-2016 Lluís Vilanova <[email protected]> |
1dde0f48 LV |
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 | ||
d38ea87a | 10 | #include "qemu/osdep.h" |
e688df6b | 11 | #include "qapi/error.h" |
9af23989 | 12 | #include "qapi/qapi-commands-trace.h" |
a3227142 | 13 | #include "control.h" |
1dde0f48 LV |
14 | |
15 | ||
77e2b172 | 16 | static CPUState *get_cpu(bool has_vcpu, int vcpu, Error **errp) |
1dde0f48 | 17 | { |
77e2b172 LV |
18 | if (has_vcpu) { |
19 | CPUState *cpu = qemu_get_cpu(vcpu); | |
20 | if (cpu == NULL) { | |
21 | error_setg(errp, "invalid vCPU index %u", vcpu); | |
22 | } | |
23 | return cpu; | |
24 | } else { | |
25 | return NULL; | |
26 | } | |
27 | } | |
28 | ||
29 | static bool check_events(bool has_vcpu, bool ignore_unavailable, bool is_pattern, | |
30 | const char *name, Error **errp) | |
31 | { | |
32 | if (!is_pattern) { | |
33 | TraceEvent *ev = trace_event_name(name); | |
34 | ||
35 | /* error for non-existing event */ | |
36 | if (ev == NULL) { | |
37 | error_setg(errp, "unknown event \"%s\"", name); | |
38 | return false; | |
39 | } | |
40 | ||
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); | |
44 | return false; | |
45 | } | |
46 | ||
47 | /* error for unavailable event */ | |
48 | if (!ignore_unavailable && !trace_event_get_state_static(ev)) { | |
49 | error_setg(errp, "event \"%s\" is disabled", name); | |
50 | return false; | |
51 | } | |
52 | ||
53 | return true; | |
54 | } else { | |
55 | /* error for unavailable events */ | |
0d4e995c DB |
56 | TraceEventIter iter; |
57 | TraceEvent *ev; | |
58 | trace_event_iter_init(&iter, name); | |
59 | while ((ev = trace_event_iter_next(&iter)) != NULL) { | |
77e2b172 LV |
60 | if (!ignore_unavailable && !trace_event_get_state_static(ev)) { |
61 | error_setg(errp, "event \"%s\" is disabled", trace_event_get_name(ev)); | |
62 | return false; | |
63 | } | |
64 | } | |
65 | return true; | |
66 | } | |
67 | } | |
68 | ||
69 | TraceEventInfoList *qmp_trace_event_get_state(const char *name, | |
70 | bool has_vcpu, int64_t vcpu, | |
71 | Error **errp) | |
72 | { | |
73 | Error *err = NULL; | |
1dde0f48 | 74 | TraceEventInfoList *events = NULL; |
0d4e995c | 75 | TraceEventIter iter; |
1dde0f48 | 76 | TraceEvent *ev; |
77e2b172 LV |
77 | bool is_pattern = trace_event_is_pattern(name); |
78 | CPUState *cpu; | |
1dde0f48 | 79 | |
77e2b172 LV |
80 | /* Check provided vcpu */ |
81 | cpu = get_cpu(has_vcpu, vcpu, &err); | |
82 | if (err) { | |
83 | error_propagate(errp, err); | |
84 | return NULL; | |
85 | } | |
86 | ||
87 | /* Check events */ | |
88 | if (!check_events(has_vcpu, true, is_pattern, name, errp)) { | |
89 | return NULL; | |
90 | } | |
91 | ||
92 | /* Get states (all errors checked above) */ | |
0d4e995c DB |
93 | trace_event_iter_init(&iter, name); |
94 | while ((ev = trace_event_iter_next(&iter)) != NULL) { | |
77e2b172 LV |
95 | TraceEventInfoList *elem; |
96 | bool is_vcpu = trace_event_is_vcpu(ev); | |
97 | if (has_vcpu && !is_vcpu) { | |
98 | continue; | |
99 | } | |
100 | ||
101 | elem = g_new(TraceEventInfoList, 1); | |
1dde0f48 | 102 | elem->value = g_new(TraceEventInfo, 1); |
77e2b172 | 103 | elem->value->vcpu = is_vcpu; |
1dde0f48 | 104 | elem->value->name = g_strdup(trace_event_get_name(ev)); |
77e2b172 | 105 | |
1dde0f48 LV |
106 | if (!trace_event_get_state_static(ev)) { |
107 | elem->value->state = TRACE_EVENT_STATE_UNAVAILABLE; | |
1dde0f48 | 108 | } else { |
77e2b172 LV |
109 | if (has_vcpu) { |
110 | if (is_vcpu) { | |
111 | if (trace_event_get_vcpu_state_dynamic(cpu, ev)) { | |
112 | elem->value->state = TRACE_EVENT_STATE_ENABLED; | |
113 | } else { | |
114 | elem->value->state = TRACE_EVENT_STATE_DISABLED; | |
115 | } | |
116 | } | |
117 | /* else: already skipped above */ | |
118 | } else { | |
119 | if (trace_event_get_state_dynamic(ev)) { | |
120 | elem->value->state = TRACE_EVENT_STATE_ENABLED; | |
121 | } else { | |
122 | elem->value->state = TRACE_EVENT_STATE_DISABLED; | |
123 | } | |
124 | } | |
1dde0f48 LV |
125 | } |
126 | elem->next = events; | |
127 | events = elem; | |
1dde0f48 LV |
128 | } |
129 | ||
130 | return events; | |
131 | } | |
132 | ||
133 | void qmp_trace_event_set_state(const char *name, bool enable, | |
77e2b172 LV |
134 | bool has_ignore_unavailable, bool ignore_unavailable, |
135 | bool has_vcpu, int64_t vcpu, | |
136 | Error **errp) | |
1dde0f48 | 137 | { |
77e2b172 | 138 | Error *err = NULL; |
0d4e995c | 139 | TraceEventIter iter; |
1dde0f48 | 140 | TraceEvent *ev; |
77e2b172 LV |
141 | bool is_pattern = trace_event_is_pattern(name); |
142 | CPUState *cpu; | |
1dde0f48 | 143 | |
77e2b172 LV |
144 | /* Check provided vcpu */ |
145 | cpu = get_cpu(has_vcpu, vcpu, &err); | |
146 | if (err) { | |
147 | error_propagate(errp, err); | |
148 | return; | |
1dde0f48 | 149 | } |
77e2b172 LV |
150 | |
151 | /* Check events */ | |
152 | if (!check_events(has_vcpu, has_ignore_unavailable && ignore_unavailable, | |
153 | is_pattern, name, errp)) { | |
1dde0f48 LV |
154 | return; |
155 | } | |
156 | ||
77e2b172 | 157 | /* Apply changes (all errors checked above) */ |
0d4e995c DB |
158 | trace_event_iter_init(&iter, name); |
159 | while ((ev = trace_event_iter_next(&iter)) != NULL) { | |
77e2b172 LV |
160 | if (!trace_event_get_state_static(ev) || |
161 | (has_vcpu && !trace_event_is_vcpu(ev))) { | |
162 | continue; | |
163 | } | |
164 | if (has_vcpu) { | |
165 | trace_event_set_vcpu_state_dynamic(cpu, ev, enable); | |
166 | } else { | |
1dde0f48 LV |
167 | trace_event_set_state_dynamic(ev, enable); |
168 | } | |
169 | } | |
170 | } |