2014-08-25 13:19:57 +02:00
|
|
|
/*
|
|
|
|
* QMP commands for tracing events.
|
|
|
|
*
|
2016-07-11 12:53:57 +02:00
|
|
|
* Copyright (C) 2014-2016 Lluís Vilanova <vilanova@ac.upc.edu>
|
2014-08-25 13:19:57 +02: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-29 18:50:05 +01:00
|
|
|
#include "qemu/osdep.h"
|
2018-02-01 12:18:31 +01:00
|
|
|
#include "qapi/error.h"
|
2018-02-11 10:36:01 +01:00
|
|
|
#include "qapi/qapi-commands-trace.h"
|
2023-05-26 18:53:58 +02:00
|
|
|
#include "control.h"
|
2014-08-25 13:19:57 +02:00
|
|
|
|
|
|
|
|
2023-05-26 18:53:57 +02:00
|
|
|
static bool check_events(bool ignore_unavailable, bool is_pattern,
|
2016-07-11 12:53:57 +02:00
|
|
|
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 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 15:35:43 +02:00
|
|
|
TraceEventIter iter;
|
|
|
|
TraceEvent *ev;
|
2021-06-01 15:24:03 +02:00
|
|
|
trace_event_iter_init_pattern(&iter, name);
|
2016-10-04 15:35:43 +02:00
|
|
|
while ((ev = trace_event_iter_next(&iter)) != NULL) {
|
2016-07-11 12:53:57 +02: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)
|
|
|
|
{
|
2014-08-25 13:19:57 +02:00
|
|
|
TraceEventInfoList *events = NULL;
|
2016-10-04 15:35:43 +02:00
|
|
|
TraceEventIter iter;
|
2014-08-25 13:19:57 +02:00
|
|
|
TraceEvent *ev;
|
2016-07-11 12:53:57 +02:00
|
|
|
bool is_pattern = trace_event_is_pattern(name);
|
|
|
|
|
|
|
|
/* Check events */
|
2023-05-26 18:53:57 +02:00
|
|
|
if (!check_events(true, is_pattern, name, errp)) {
|
2016-07-11 12:53:57 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get states (all errors checked above) */
|
2021-06-01 15:24:03 +02:00
|
|
|
trace_event_iter_init_pattern(&iter, name);
|
2016-10-04 15:35:43 +02:00
|
|
|
while ((ev = trace_event_iter_next(&iter)) != NULL) {
|
2020-11-13 02:13:37 +01:00
|
|
|
TraceEventInfo *value;
|
2016-07-11 12:53:57 +02:00
|
|
|
|
2020-11-13 02:13:37 +01:00
|
|
|
value = g_new(TraceEventInfo, 1);
|
|
|
|
value->name = g_strdup(trace_event_get_name(ev));
|
2016-07-11 12:53:57 +02:00
|
|
|
|
2014-08-25 13:19:57 +02:00
|
|
|
if (!trace_event_get_state_static(ev)) {
|
2020-11-13 02:13:37 +01:00
|
|
|
value->state = TRACE_EVENT_STATE_UNAVAILABLE;
|
2014-08-25 13:19:57 +02:00
|
|
|
} else {
|
2023-05-26 18:53:57 +02:00
|
|
|
if (trace_event_get_state_dynamic(ev)) {
|
|
|
|
value->state = TRACE_EVENT_STATE_ENABLED;
|
2016-07-11 12:53:57 +02:00
|
|
|
} else {
|
2023-05-26 18:53:57 +02:00
|
|
|
value->state = TRACE_EVENT_STATE_DISABLED;
|
2016-07-11 12:53:57 +02:00
|
|
|
}
|
2014-08-25 13:19:57 +02:00
|
|
|
}
|
2020-11-13 02:13:37 +01:00
|
|
|
QAPI_LIST_PREPEND(events, value);
|
2014-08-25 13:19:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return events;
|
|
|
|
}
|
|
|
|
|
|
|
|
void qmp_trace_event_set_state(const char *name, bool enable,
|
2016-07-11 12:53:57 +02:00
|
|
|
bool has_ignore_unavailable, bool ignore_unavailable,
|
|
|
|
bool has_vcpu, int64_t vcpu,
|
|
|
|
Error **errp)
|
2014-08-25 13:19:57 +02:00
|
|
|
{
|
2016-10-04 15:35:43 +02:00
|
|
|
TraceEventIter iter;
|
2014-08-25 13:19:57 +02:00
|
|
|
TraceEvent *ev;
|
2016-07-11 12:53:57 +02:00
|
|
|
bool is_pattern = trace_event_is_pattern(name);
|
|
|
|
|
|
|
|
/* Check events */
|
2023-05-26 18:53:57 +02:00
|
|
|
if (!check_events(has_ignore_unavailable && ignore_unavailable,
|
2016-07-11 12:53:57 +02:00
|
|
|
is_pattern, name, errp)) {
|
2014-08-25 13:19:57 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-11 12:53:57 +02:00
|
|
|
/* Apply changes (all errors checked above) */
|
2021-06-01 15:24:03 +02:00
|
|
|
trace_event_iter_init_pattern(&iter, name);
|
2016-10-04 15:35:43 +02:00
|
|
|
while ((ev = trace_event_iter_next(&iter)) != NULL) {
|
2023-05-26 18:53:57 +02:00
|
|
|
if (!trace_event_get_state_static(ev)) {
|
2016-07-11 12:53:57 +02:00
|
|
|
continue;
|
|
|
|
}
|
2023-05-26 18:53:57 +02:00
|
|
|
trace_event_set_state_dynamic(ev, enable);
|
2014-08-25 13:19:57 +02:00
|
|
|
}
|
|
|
|
}
|