2014-08-25 19:19:57 +08:00
|
|
|
/*
|
|
|
|
* QMP commands for tracing events.
|
|
|
|
*
|
2016-07-11 18:53:57 +08:00
|
|
|
* Copyright (C) 2014-2016 Lluís Vilanova <vilanova@ac.upc.edu>
|
2014-08-25 19:19:57 +08:00
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
2016-01-30 01:50:05 +08:00
|
|
|
#include "qemu/osdep.h"
|
2014-08-25 19:19:57 +08:00
|
|
|
#include "qmp-commands.h"
|
|
|
|
#include "trace/control.h"
|
|
|
|
|
|
|
|
|
2016-07-11 18:53:57 +08:00
|
|
|
static CPUState *get_cpu(bool has_vcpu, int vcpu, Error **errp)
|
2014-08-25 19:19:57 +08:00
|
|
|
{
|
2016-07-11 18:53:57 +08:00
|
|
|
if (has_vcpu) {
|
|
|
|
CPUState *cpu = qemu_get_cpu(vcpu);
|
|
|
|
if (cpu == NULL) {
|
|
|
|
error_setg(errp, "invalid vCPU index %u", vcpu);
|
|
|
|
}
|
|
|
|
return cpu;
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool check_events(bool has_vcpu, bool ignore_unavailable, bool is_pattern,
|
|
|
|
const char *name, Error **errp)
|
|
|
|
{
|
|
|
|
if (!is_pattern) {
|
|
|
|
TraceEvent *ev = trace_event_name(name);
|
|
|
|
|
|
|
|
/* error for non-existing event */
|
|
|
|
if (ev == NULL) {
|
|
|
|
error_setg(errp, "unknown event \"%s\"", name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* error for non-vcpu event */
|
|
|
|
if (has_vcpu && !trace_event_is_vcpu(ev)) {
|
|
|
|
error_setg(errp, "event \"%s\" is not vCPU-specific", name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* error for unavailable event */
|
|
|
|
if (!ignore_unavailable && !trace_event_get_state_static(ev)) {
|
|
|
|
error_setg(errp, "event \"%s\" is disabled", name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
/* error for unavailable events */
|
2016-10-04 21:35:43 +08:00
|
|
|
TraceEventIter iter;
|
|
|
|
TraceEvent *ev;
|
|
|
|
trace_event_iter_init(&iter, name);
|
|
|
|
while ((ev = trace_event_iter_next(&iter)) != NULL) {
|
2016-07-11 18:53:57 +08:00
|
|
|
if (!ignore_unavailable && !trace_event_get_state_static(ev)) {
|
|
|
|
error_setg(errp, "event \"%s\" is disabled", trace_event_get_name(ev));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TraceEventInfoList *qmp_trace_event_get_state(const char *name,
|
|
|
|
bool has_vcpu, int64_t vcpu,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
Error *err = NULL;
|
2014-08-25 19:19:57 +08:00
|
|
|
TraceEventInfoList *events = NULL;
|
2016-10-04 21:35:43 +08:00
|
|
|
TraceEventIter iter;
|
2014-08-25 19:19:57 +08:00
|
|
|
TraceEvent *ev;
|
2016-07-11 18:53:57 +08:00
|
|
|
bool is_pattern = trace_event_is_pattern(name);
|
|
|
|
CPUState *cpu;
|
2014-08-25 19:19:57 +08:00
|
|
|
|
2016-07-11 18:53:57 +08:00
|
|
|
/* Check provided vcpu */
|
|
|
|
cpu = get_cpu(has_vcpu, vcpu, &err);
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check events */
|
|
|
|
if (!check_events(has_vcpu, true, is_pattern, name, errp)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get states (all errors checked above) */
|
2016-10-04 21:35:43 +08:00
|
|
|
trace_event_iter_init(&iter, name);
|
|
|
|
while ((ev = trace_event_iter_next(&iter)) != NULL) {
|
2016-07-11 18:53:57 +08:00
|
|
|
TraceEventInfoList *elem;
|
|
|
|
bool is_vcpu = trace_event_is_vcpu(ev);
|
|
|
|
if (has_vcpu && !is_vcpu) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
elem = g_new(TraceEventInfoList, 1);
|
2014-08-25 19:19:57 +08:00
|
|
|
elem->value = g_new(TraceEventInfo, 1);
|
2016-07-11 18:53:57 +08:00
|
|
|
elem->value->vcpu = is_vcpu;
|
2014-08-25 19:19:57 +08:00
|
|
|
elem->value->name = g_strdup(trace_event_get_name(ev));
|
2016-07-11 18:53:57 +08:00
|
|
|
|
2014-08-25 19:19:57 +08:00
|
|
|
if (!trace_event_get_state_static(ev)) {
|
|
|
|
elem->value->state = TRACE_EVENT_STATE_UNAVAILABLE;
|
|
|
|
} else {
|
2016-07-11 18:53:57 +08:00
|
|
|
if (has_vcpu) {
|
|
|
|
if (is_vcpu) {
|
|
|
|
if (trace_event_get_vcpu_state_dynamic(cpu, ev)) {
|
|
|
|
elem->value->state = TRACE_EVENT_STATE_ENABLED;
|
|
|
|
} else {
|
|
|
|
elem->value->state = TRACE_EVENT_STATE_DISABLED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* else: already skipped above */
|
|
|
|
} else {
|
|
|
|
if (trace_event_get_state_dynamic(ev)) {
|
|
|
|
elem->value->state = TRACE_EVENT_STATE_ENABLED;
|
|
|
|
} else {
|
|
|
|
elem->value->state = TRACE_EVENT_STATE_DISABLED;
|
|
|
|
}
|
|
|
|
}
|
2014-08-25 19:19:57 +08:00
|
|
|
}
|
|
|
|
elem->next = events;
|
|
|
|
events = elem;
|
|
|
|
}
|
|
|
|
|
|
|
|
return events;
|
|
|
|
}
|
|
|
|
|
|
|
|
void qmp_trace_event_set_state(const char *name, bool enable,
|
2016-07-11 18:53:57 +08:00
|
|
|
bool has_ignore_unavailable, bool ignore_unavailable,
|
|
|
|
bool has_vcpu, int64_t vcpu,
|
|
|
|
Error **errp)
|
2014-08-25 19:19:57 +08:00
|
|
|
{
|
2016-07-11 18:53:57 +08:00
|
|
|
Error *err = NULL;
|
2016-10-04 21:35:43 +08:00
|
|
|
TraceEventIter iter;
|
2014-08-25 19:19:57 +08:00
|
|
|
TraceEvent *ev;
|
2016-07-11 18:53:57 +08:00
|
|
|
bool is_pattern = trace_event_is_pattern(name);
|
|
|
|
CPUState *cpu;
|
2014-08-25 19:19:57 +08:00
|
|
|
|
2016-07-11 18:53:57 +08:00
|
|
|
/* Check provided vcpu */
|
|
|
|
cpu = get_cpu(has_vcpu, vcpu, &err);
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
|
|
|
return;
|
2014-08-25 19:19:57 +08:00
|
|
|
}
|
2016-07-11 18:53:57 +08:00
|
|
|
|
|
|
|
/* Check events */
|
|
|
|
if (!check_events(has_vcpu, has_ignore_unavailable && ignore_unavailable,
|
|
|
|
is_pattern, name, errp)) {
|
2014-08-25 19:19:57 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-11 18:53:57 +08:00
|
|
|
/* Apply changes (all errors checked above) */
|
2016-10-04 21:35:43 +08:00
|
|
|
trace_event_iter_init(&iter, name);
|
|
|
|
while ((ev = trace_event_iter_next(&iter)) != NULL) {
|
2016-07-11 18:53:57 +08:00
|
|
|
if (!trace_event_get_state_static(ev) ||
|
|
|
|
(has_vcpu && !trace_event_is_vcpu(ev))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (has_vcpu) {
|
|
|
|
trace_event_set_vcpu_state_dynamic(cpu, ev, enable);
|
|
|
|
} else {
|
2014-08-25 19:19:57 +08:00
|
|
|
trace_event_set_state_dynamic(ev, enable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|