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