summaryrefslogtreecommitdiffstats
path: root/qemu/trace/qmp.c
blob: 8aa2660aac2d13748cd9ae82622c351d06a3de4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 * QMP commands for tracing events.
 *
 * Copyright (C) 2014 Lluís Vilanova <vilanova@ac.upc.edu>
 *
 * This work is licensed under the terms of the GNU GPL, version 2 or later.
 * See the COPYING file in the top-level directory.
 */

#include "qemu/osdep.h"
#include "qmp-commands.h"
#include "trace/control.h"


TraceEventInfoList *qmp_trace_event_get_state(const char *name, Error **errp)
{
    TraceEventInfoList *events = NULL;
    bool found = false;
    TraceEvent *ev;

    ev = NULL;
    while ((ev = trace_event_pattern(name, ev)) != NULL) {
        TraceEventInfoList *elem = g_new(TraceEventInfoList, 1);
        elem->value = g_new(TraceEventInfo, 1);
        elem->value->name = g_strdup(trace_event_get_name(ev));
        if (!trace_event_get_state_static(ev)) {
            elem->value->state = TRACE_EVENT_STATE_UNAVAILABLE;
        } else if (!trace_event_get_state_dynamic(ev)) {
            elem->value->state = TRACE_EVENT_STATE_DISABLED;
        } else {
            elem->value->state = TRACE_EVENT_STATE_ENABLED;
        }
        elem->next = events;
        events = elem;
        found = true;
    }

    if (!found && !trace_event_is_pattern(name)) {
        error_setg(errp, "unknown event \"%s\"", name);
    }

    return events;
}

void qmp_trace_event_set_state(const char *name, bool enable,
                               bool has_ignore_unavailable,
                               bool ignore_unavailable, Error **errp)
{
    bool found = false;
    TraceEvent *ev;

    /* Check all selected events are dynamic */
    ev = NULL;
    while ((ev = trace_event_pattern(name, ev)) != NULL) {
        found = true;
        if (!(has_ignore_unavailable && ignore_unavailable) &&
            !trace_event_get_state_static(ev)) {
            error_setg(errp, "cannot set dynamic tracing state for \"%s\"",
                       trace_event_get_name(ev));
            return;
        }
    }
    if (!found && !trace_event_is_pattern(name)) {
        error_setg(errp, "unknown event \"%s\"", name);
        return;
    }

    /* Apply changes */
    ev = NULL;
    while ((ev = trace_event_pattern(name, ev)) != NULL) {
        if (trace_event_get_state_static(ev)) {
            trace_event_set_state_dynamic(ev, enable);
        }
    }
}