Skip to contentSkip to conversation

trace: [qmp] Add QAPI/QMP commands to query and control event tracing state

PATCH Superseded Lluís Vilanova 4 participants 10 messages Aug 21, 2014 – Aug 25, 2014

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 trace: [qmp] Add QAPI/QMP commands to query and control event tracing state

Also removes old "trace-event", "trace-file" and "info trace-events" HMP commands.

---
 monitor.c           |   24 +++++++---------
 qapi-schema.json    |    3 ++
 qapi/trace.json     |   44 +++++++++++++++++++++++++++++
 qmp-commands.hx     |   27 ++++++++++++++++++
 trace/Makefile.objs |    1 +
 trace/control.c     |   13 ---------
 trace/control.h     |    7 -----
 trace/qmp.c         |   77 +++++++++++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 162 insertions(+), 34 deletions(-)
 create mode 100644 qapi/trace.json
 create mode 100644 trace/qmp.c
monitor.c +10 -14
index cdbaa60..0f605f5 100644
@@ -887,19 +887,8 @@ static void do_trace_event_set_state(Monitor *mon, const QDict *qdict)
     const char *tp_name = qdict_get_str(qdict, "name");
     bool new_state = qdict_get_bool(qdict, "option");
 
-    bool found = false;
-    TraceEvent *ev = NULL;
-    while ((ev = trace_event_pattern(tp_name, ev)) != NULL) {
-        found = true;
-        if (!trace_event_get_state_static(ev)) {
-            monitor_printf(mon, "event \"%s\" is not traceable\n", tp_name);
-        } else {
-            trace_event_set_state_dynamic(ev, new_state);
-        }
-    }
-    if (!trace_event_is_pattern(tp_name) && !found) {
-        monitor_printf(mon, "unknown event name \"%s\"\n", tp_name);
-    }
+    /* TODO: should propagate QMP errors to HMP */
+    qmp_trace_event_set_state(tp_name, new_state, true, true, NULL);
 }
 
 #ifdef CONFIG_TRACE_SIMPLE
@@ -1079,7 +1068,14 @@ static void do_info_cpu_stats(Monitor *mon, const QDict *qdict)
 
 static void do_trace_print_events(Monitor *mon, const QDict *qdict)
 {
-    trace_print_events((FILE *)mon, &monitor_fprintf);
+    TraceEventStateList *events = qmp_trace_event_get_state("*", NULL);
+    TraceEventStateList *event;
+    for (event = events; event != NULL; event = event->next) {
+        monitor_printf(mon, "%s : state %u\n",
+                       event->value->name,
+                       event->value->sstatic && event->value->sdynamic);
+    }
+    qapi_free_TraceEventStateList(events);
 }
 
 static int client_migrate_info(Monitor *mon, const QDict *qdict,
qapi-schema.json +3 -0
index 341f417..42b90df 100644
@@ -11,6 +11,9 @@
 # QAPI event definitions
 { 'include': 'qapi/event.json' }
 
+# Tracing commands
+{ 'include': 'qapi/trace.json' }
+
 ##
 # LostTickPolicy:
 #
qapi/trace.json new file +44 -0

44 lines not on this page · raw message

qmp-commands.hx +27 -0
index 4be4765..443dd16 100644
@@ -3753,5 +3753,32 @@ Example:
 
 -> { "execute": "rtc-reset-reinjection" }
 <- { "return": {} }
+EQMP
+
+    {
+        .name       = "trace-event-get-state",
+        .args_type  = "name:s",
+        .mhandler.cmd_new = qmp_marshal_input_trace_event_get_state,
+    },
+
+SQMP
+trace-event-get-state
+---------------------
+
+Query the state of events.
+
+EQMP
+
+    {
+        .name       = "trace-event-set-state",
+        .args_type  = "name:s,state:b,keepgoing:b?",
+        .mhandler.cmd_new = qmp_marshal_input_trace_event_set_state,
+    },
+
+SQMP
+trace-event-set-state
+---------------------
+
+Set the state of events.
 
 EQMP
trace/Makefile.objs +1 -0
index 387f191..01b3718 100644
@@ -145,3 +145,4 @@ util-obj-$(CONFIG_TRACE_FTRACE) += ftrace.o
 util-obj-$(CONFIG_TRACE_UST) += generated-ust.o
 util-obj-y += control.o
 util-obj-y += generated-tracers.o
+util-obj-y += qmp.o
trace/control.c +0 -13
index 9631a40..0d30801 100644
@@ -85,19 +85,6 @@ TraceEvent *trace_event_pattern(const char *pat, TraceEvent *ev)
     return NULL;
 }
 
-void trace_print_events(FILE *stream, fprintf_function stream_printf)
-{
-    TraceEventID i;
-
-    for (i = 0; i < trace_event_count(); i++) {
-        TraceEvent *ev = trace_event_id(i);
-        stream_printf(stream, "%s [Event ID %u] : state %u\n",
-                      trace_event_get_name(ev), i,
-                      trace_event_get_state_static(ev) &&
-                      trace_event_get_state_dynamic(ev));
-    }
-}
-
 static void trace_init_events(const char *fname)
 {
     Location loc;
trace/control.h +0 -7
index e1ec033..da9bb6b 100644
@@ -149,13 +149,6 @@ static void trace_event_set_state_dynamic(TraceEvent *ev, bool state);
 
 
 /**
- * trace_print_events:
- *
- * Print the state of all events.
- */
-void trace_print_events(FILE *stream, fprintf_function stream_printf);
-
-/**
  * trace_init_backends:
  * @events: Name of file with events to be enabled at startup; may be NULL.
  *          Corresponds to commandline option "-trace events=...".
trace/qmp.c new file +77 -0

77 lines not on this page · raw message

#1 lore raw
Quoted 2 lines · Lluís Vilanova

Also removes old "trace-event", "trace-file" and "info trace-events" HMP commands.

Is this commit description correct? I think we don't want to remove HMP commands. It is "legacy" but users may still rely on HMP. It's certainly used for ad-hoc debugging.

Quoted 13 lines
monitor.c +0 -5
index cdbaa60..0f605f5 100644
@@ -887,19 +887,8 @@ static void do_trace_event_set_state(Monitor *mon, const QDict *qdict)
     const char *tp_name = qdict_get_str(qdict, "name");
     bool new_state = qdict_get_bool(qdict, "option");
 
-    bool found = false;
-    TraceEvent *ev = NULL;
-    while ((ev = trace_event_pattern(tp_name, ev)) != NULL) {
-        found = true;
-        if (!trace_event_get_state_static(ev)) {

monitor.c static void do_trace_event_set_state(Monitor *mon, const QDict *qdict) · line 891

Quoted 10 lines
monitor.c +2 -8
-            monitor_printf(mon, "event \"%s\" is not traceable\n", tp_name);
-        } else {
-            trace_event_set_state_dynamic(ev, new_state);
-        }
-    }
-    if (!trace_event_is_pattern(tp_name) && !found) {
-        monitor_printf(mon, "unknown event name \"%s\"\n", tp_name);
-    }
+    /* TODO: should propagate QMP errors to HMP */
+    qmp_trace_event_set_state(tp_name, new_state, true, true, NULL);

The TODO can be resolved with:

if (errp) {
    monitor_printf(mon, "%s", error_get_pretty(errp));
    error_free(errp);
}
Quoted 9 lines
monitor.c +9 -0
+TraceEventStateList *qmp_trace_event_get_state(const char *name, Error **errp)
+{
+    TraceEventStateList dummy = {};
+    TraceEventStateList *prev = &dummy;
+
+    bool found = false;
+    TraceEvent *ev = NULL;
+    while ((ev = trace_event_pattern(name, ev)) != NULL) {
+        found = true;

monitor.c static void do_trace_event_set_state(Monitor *mon, const QDict *qdict)

Quoted 10 lines
monitor.c +10 -0
+        TraceEventStateList *elem = g_malloc0(sizeof(*elem));
+        elem->value = g_malloc0(sizeof(*elem->value));
+        elem->value->name = g_strdup(trace_event_get_name(ev));
+        elem->value->sstatic = trace_event_get_state_static(ev);
+        elem->value->sdynamic = trace_event_get_state_dynamic(ev);
+        prev->next = elem;
+        prev = elem;
+    }
+    if (!found && !trace_event_is_pattern(name)) {
+        error_setg(errp, "unknown event \"%s\"\n", name);

\n is not needed in error_setg() message. Please remove it.

There are more instances below.

Quoted 8 lines
monitor.c +8 -0
+    }
+
+    return dummy.next;
+}
+
+void qmp_trace_event_set_state(const char *name, bool state, bool has_keepgoing,
+                               bool keepgoing, Error **errp)
+{

monitor.c

Quoted 10 lines
monitor.c +10 -0
+    bool error = false;
+    bool found = false;
+    TraceEvent *ev = NULL;
+
+    /* Check all selected events are dynamic */
+    while ((ev = trace_event_pattern(name, ev)) != NULL) {
+        found = true;
+        if (!trace_event_get_state_static(ev)) {
+            error_setg(errp, "cannot set dynamic tracing state for \"%s\"\n",
+                       trace_event_get_name(ev));

error_setg() can only be called once. Calling it with non-NULL errp produces an assertion failure.

Maybe this approach can be used instead:

while ((ev = trace_event_pattern(name, ev)) != NULL) {
    found = true;
    if (!(has_keepgoing && keepgoing) &&
        !trace_event_get_state_static(ev)) {
        error_setg(errp, "cannot set dynamic tracing state for \"%s\"",
	           trace_event_get_name(ev));
	return;
    }
}

The bool error variable can be dropped.

Quoted 7 lines
monitor.c +7 -0
+            if (!(has_keepgoing && keepgoing)) {
+                error = true;
+            }
+            break;
+        }
+    }
+    if (error) {

monitor.c

Quoted 10 lines
monitor.c +10 -0
+        return;
+    }
+    if (!found && !trace_event_is_pattern(name)) {
+        error_setg(errp, "unknown event \"%s\"\n", name);
+        return;
+    }
+
+    if (error) {
+        return;
+    }

This condition has already been checked above. This if statement can be dropped.

#2 lore raw
Quoted 7 lines · Stefan Hajnoczi
Quoted 2 lines · Lluís Vilanova

Also removes old "trace-event", "trace-file" and "info trace-events" HMP commands.

Is this commit description correct? I think we don't want to remove HMP commands. It is "legacy" but users may still rely on HMP. It's certainly used for ad-hoc debugging.

The description is a leftover from a previous version.

Quoted 26 lines
Quoted 13 lines
monitor.c +0 -5
index cdbaa60..0f605f5 100644
@@ -887,19 +887,8 @@ static void do_trace_event_set_state(Monitor *mon, const QDict *qdict)
 const char *tp_name = qdict_get_str(qdict, "name");
 bool new_state = qdict_get_bool(qdict, "option");
 
-    bool found = false;
-    TraceEvent *ev = NULL;
-    while ((ev = trace_event_pattern(tp_name, ev)) != NULL) {
-        found = true;
-        if (!trace_event_get_state_static(ev)) {

monitor.c static void do_trace_event_set_state(Monitor *mon, const QDict *qdict) · line 891

Quoted 10 lines
monitor.c +2 -8
-            monitor_printf(mon, "event \"%s\" is not traceable\n", tp_name);
-        } else {
-            trace_event_set_state_dynamic(ev, new_state);
-        }
-    }
-    if (!trace_event_is_pattern(tp_name) && !found) {
-        monitor_printf(mon, "unknown event name \"%s\"\n", tp_name);
-    }
+    /* TODO: should propagate QMP errors to HMP */
+    qmp_trace_event_set_state(tp_name, new_state, true, true, NULL);

The TODO can be resolved with:

Quoted 4 lines
if (errp) {
    monitor_printf(mon, "%s", error_get_pretty(errp));
    error_free(errp);
}

Thanks.

Quoted 22 lines
Quoted 9 lines
monitor.c +9 -0
+TraceEventStateList *qmp_trace_event_get_state(const char *name, Error **errp)
+{
+    TraceEventStateList dummy = {};
+    TraceEventStateList *prev = &dummy;
+
+    bool found = false;
+    TraceEvent *ev = NULL;
+    while ((ev = trace_event_pattern(name, ev)) != NULL) {
+        found = true;

monitor.c static void do_trace_event_set_state(Monitor *mon, const QDict *qdict)

Quoted 10 lines
monitor.c +10 -0
+        TraceEventStateList *elem = g_malloc0(sizeof(*elem));
+        elem->value = g_malloc0(sizeof(*elem->value));
+        elem->value->name = g_strdup(trace_event_get_name(ev));
+        elem->value->sstatic = trace_event_get_state_static(ev);
+        elem->value->sdynamic = trace_event_get_state_dynamic(ev);
+        prev->next = elem;
+        prev = elem;
+    }
+    if (!found && !trace_event_is_pattern(name)) {
+        error_setg(errp, "unknown event \"%s\"\n", name);

\n is not needed in error_setg() message. Please remove it.

Quoted 1 line

There are more instances below.

Ok.

Quoted 34 lines
Quoted 8 lines
monitor.c +8 -0
+    }
+
+    return dummy.next;
+}
+
+void qmp_trace_event_set_state(const char *name, bool state, bool has_keepgoing,
+                               bool keepgoing, Error **errp)
+{

monitor.c

Quoted 10 lines
monitor.c +10 -0
+    bool error = false;
+    bool found = false;
+    TraceEvent *ev = NULL;
+
+    /* Check all selected events are dynamic */
+    while ((ev = trace_event_pattern(name, ev)) != NULL) {
+        found = true;
+        if (!trace_event_get_state_static(ev)) {
+            error_setg(errp, "cannot set dynamic tracing state for \"%s\"\n",
+                       trace_event_get_name(ev));

error_setg() can only be called once. Calling it with non-NULL errp produces an assertion failure.

Maybe this approach can be used instead:

while ((ev = trace_event_pattern(name, ev)) != NULL) {
    found = true;
    if (!(has_keepgoing && keepgoing) &&
        !trace_event_get_state_static(ev)) {
        error_setg(errp, "cannot set dynamic tracing state for \"%s\"",
	           trace_event_get_name(ev));
	return;
    }
}
Quoted 1 line

The bool error variable can be dropped.

Ok.

Quoted 18 lines
Quoted 7 lines
monitor.c +7 -0
+            if (!(has_keepgoing && keepgoing)) {
+                error = true;
+            }
+            break;
+        }
+    }
+    if (error) {

monitor.c

Quoted 10 lines
monitor.c +10 -0
+        return;
+    }
+    if (!found && !trace_event_is_pattern(name)) {
+        error_setg(errp, "unknown event \"%s\"\n", name);
+        return;
+    }
+
+    if (error) {
+        return;
+    }
Quoted 2 lines

This condition has already been checked above. This if statement can be dropped.

Copy/paste is the root of many evils...

Thanks,
Lluis

Signature · 4 lines
 "And it's much the same thing with knowledge, for whenever you learn
 something new, the whole world becomes that much richer."
 -- The Princess of Pure Reason, as told by Norton Juster in The Phantom
 Tollbooth
#3 lore raw
In reply to Lluís Vilanova
Quoted 2 lines · Lluís Vilanova

Also removes old "trace-event", "trace-file" and "info trace-events" HMP commands.

I can't see any HMP commands removal in your patch. You

Quoted 27 lines
---
 monitor.c           |   24 +++++++---------
 qapi-schema.json    |    3 ++
 qapi/trace.json     |   44 +++++++++++++++++++++++++++++
 qmp-commands.hx     |   27 ++++++++++++++++++
 trace/Makefile.objs |    1 +
 trace/control.c     |   13 ---------
 trace/control.h     |    7 -----
 trace/qmp.c         |   77 +++++++++++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 162 insertions(+), 34 deletions(-)
 create mode 100644 qapi/trace.json
 create mode 100644 trace/qmp.c
monitor.c +0 -5
index cdbaa60..0f605f5 100644
@@ -887,19 +887,8 @@ static void do_trace_event_set_state(Monitor *mon, const QDict *qdict)
     const char *tp_name = qdict_get_str(qdict, "name");
     bool new_state = qdict_get_bool(qdict, "option");
 
-    bool found = false;
-    TraceEvent *ev = NULL;
-    while ((ev = trace_event_pattern(tp_name, ev)) != NULL) {
-        found = true;
-        if (!trace_event_get_state_static(ev)) {

monitor.c static void do_trace_event_set_state(Monitor *mon, const QDict *qdict) · line 891

Quoted 10 lines
monitor.c +2 -8
-            monitor_printf(mon, "event \"%s\" is not traceable\n", tp_name);
-        } else {
-            trace_event_set_state_dynamic(ev, new_state);
-        }
-    }
-    if (!trace_event_is_pattern(tp_name) && !found) {
-        monitor_printf(mon, "unknown event name \"%s\"\n", tp_name);
-    }
+    /* TODO: should propagate QMP errors to HMP */
+    qmp_trace_event_set_state(tp_name, new_state, true, true, NULL);

Easy:

    Error *local_err = NULL;
    [...]
    qmp_trace_event_set_state(tp_name, new_state, true, true, &local_err);
    if (local_err) {
        qerror_report_err(local_err);
        error_free(local_err);
    }

monitor.c static void do_info_cpu_stats(Monitor *mon, const QDict *qdict) · line 1072

Quoted 10 lines
monitor.c +2 -1
 }
 
 #ifdef CONFIG_TRACE_SIMPLE
@@ -1079,7 +1068,14 @@ static void do_info_cpu_stats(Monitor *mon, const QDict *qdict)
 
 static void do_trace_print_events(Monitor *mon, const QDict *qdict)
 {
-    trace_print_events((FILE *)mon, &monitor_fprintf);
+    TraceEventStateList *events = qmp_trace_event_get_state("*", NULL);
+    TraceEventStateList *event;

Blank line here, please, to visually separate declarations and statements.

monitor.c static void do_info_cpu_stats(Monitor *mon, const QDict *qdict) · line 1078

Quoted 6 lines
monitor.c +6 -0
+    for (event = events; event != NULL; event = event->next) {
+        monitor_printf(mon, "%s : state %u\n",
+                       event->value->name,
+                       event->value->sstatic && event->value->sdynamic);
+    }
+    qapi_free_TraceEventStateList(events);

Drops "[Event ID %u]" from output. Is that number interesting to users? If no, I don't mind.

Quoted 23 lines
monitor.c +0 -0
 }
 
 static int client_migrate_info(Monitor *mon, const QDict *qdict,
qapi-schema.json +3 -0
index 341f417..42b90df 100644
@@ -11,6 +11,9 @@
 # QAPI event definitions
 { 'include': 'qapi/event.json' }
 
+# Tracing commands
+{ 'include': 'qapi/trace.json' }
+
 ##
 # LostTickPolicy:
 #
qapi/trace.json new file +0 -0
new file mode 100644
index 0000000..6e6313d

qapi/trace.json line 10

Quoted 10 lines
qapi/trace.json new file +10 -0
@@ -0,0 +1,44 @@
+# -*- mode: python -*-
+
+##
+# @TraceEventState:
+#
+# State of a tracing event.
+#
+# @name: Event name.
+# @sstatic: Static tracing state.
+# @sdynamic: Dynamic tracing state.

Maybe static-state, dynamic-state?

What do static and dynamic state mean?

qapi/trace.json line 22

Quoted 12 lines
qapi/trace.json new file +12 -0
+#
+# Since 2.2
+##
+{ 'type': 'TraceEventState',
+  'data': {'name': 'str', 'sstatic': 'bool', 'sdynamic': 'bool'} }
+
+##
+# @trace-event-get-state:
+#
+# Query the state of events.
+#
+# @name: Event name pattern.

What kind of pattern is this?

qapi/trace.json line 24

Quoted 2 lines
qapi/trace.json new file +2 -0
+#
+# Returns: @TraceEventState of the matched events

Make that "Returns: a list of @TraceEventState for the matching events".

Quoted 4 lines
qapi/trace.json new file +4 -0
+#
+# Since 2.2
+##
+{ 'command': 'trace-event-get-state',

qapi/trace.json line 38

Quoted 10 lines
qapi/trace.json new file +10 -0
+  'data': {'name': 'str'},
+  'returns': ['TraceEventState'] }
+
+##
+# @trace-event-set-state:
+#
+# Set the dynamic state of events.
+#
+# @name: Event name pattern.
+# @state: Dynamic tracing state.

Suggest to name this argument exactly like the TraceEventState member.

qapi/trace.json line 39

Quoted 1 line
qapi/trace.json new file +1 -0
+# @keepgoing: #optional Apply changes even if not all events can be changed.

How can that happen? I.e. how can setting an event's state fail?

Quoted 108 lines
qapi/trace.json new file +5 -0
+#
+# Since 2.2
+##
+{ 'command': 'trace-event-set-state',
+  'data': {'name': 'str', 'state': 'bool', '*keepgoing': 'bool'} }
qmp-commands.hx +27 -0
index 4be4765..443dd16 100644
@@ -3753,5 +3753,32 @@ Example:
 
 -> { "execute": "rtc-reset-reinjection" }
 <- { "return": {} }
+EQMP
+
+    {
+        .name       = "trace-event-get-state",
+        .args_type  = "name:s",
+        .mhandler.cmd_new = qmp_marshal_input_trace_event_get_state,
+    },
+
+SQMP
+trace-event-get-state
+---------------------
+
+Query the state of events.
+
+EQMP
+
+    {
+        .name       = "trace-event-set-state",
+        .args_type  = "name:s,state:b,keepgoing:b?",
+        .mhandler.cmd_new = qmp_marshal_input_trace_event_set_state,
+    },
+
+SQMP
+trace-event-set-state
+---------------------
+
+Set the state of events.
 
 EQMP
trace/Makefile.objs +1 -0
index 387f191..01b3718 100644
@@ -145,3 +145,4 @@ util-obj-$(CONFIG_TRACE_FTRACE) += ftrace.o
 util-obj-$(CONFIG_TRACE_UST) += generated-ust.o
 util-obj-y += control.o
 util-obj-y += generated-tracers.o
+util-obj-y += qmp.o
trace/control.c +0 -13
index 9631a40..0d30801 100644
@@ -85,19 +85,6 @@ TraceEvent *trace_event_pattern(const char *pat, TraceEvent *ev)
     return NULL;
 }
 
-void trace_print_events(FILE *stream, fprintf_function stream_printf)
-{
-    TraceEventID i;
-
-    for (i = 0; i < trace_event_count(); i++) {
-        TraceEvent *ev = trace_event_id(i);
-        stream_printf(stream, "%s [Event ID %u] : state %u\n",
-                      trace_event_get_name(ev), i,
-                      trace_event_get_state_static(ev) &&
-                      trace_event_get_state_dynamic(ev));
-    }
-}
-
 static void trace_init_events(const char *fname)
 {
     Location loc;
trace/control.h +0 -7
index e1ec033..da9bb6b 100644
@@ -149,13 +149,6 @@ static void trace_event_set_state_dynamic(TraceEvent *ev, bool state);
 
 
 /**
- * trace_print_events:
- *
- * Print the state of all events.
- */
-void trace_print_events(FILE *stream, fprintf_function stream_printf);
-
-/**
  * trace_init_backends:
  * @events: Name of file with events to be enabled at startup; may be NULL.
  *          Corresponds to commandline option "-trace events=...".
trace/qmp.c new file +9 -0
new file mode 100644
index 0000000..d22d8fa
@@ -0,0 +1,77 @@
+/*
+ * QMP commands for tracing events.
+ *
+ * Copyright (C) 2014 Lluís Vilanova <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+

trace/qmp.c line 19

Quoted 10 lines
trace/qmp.c new file +10 -0
+#include "qemu/typedefs.h"
+#include "qmp-commands.h"
+#include "trace/control.h"
+
+
+TraceEventStateList *qmp_trace_event_get_state(const char *name, Error **errp)
+{
+    TraceEventStateList dummy = {};
+    TraceEventStateList *prev = &dummy;
+

Please move this blank line...

trace/qmp.c line 21

Quoted 2 lines
trace/qmp.c new file +2 -0
+    bool found = false;
+    TraceEvent *ev = NULL;

here, so that it visually separates declarations and statements.

Dead initialization of ev, by the way.

trace/qmp.c line 24

Quoted 3 lines
trace/qmp.c new file +3 -0
+    while ((ev = trace_event_pattern(name, ev)) != NULL) {
+        found = true;
+        TraceEventStateList *elem = g_malloc0(sizeof(*elem));

Declaration follows statement, please don't do that.

trace/qmp.c line 36

Quoted 12 lines
trace/qmp.c new file +12 -0
+        elem->value = g_malloc0(sizeof(*elem->value));
+        elem->value->name = g_strdup(trace_event_get_name(ev));
+        elem->value->sstatic = trace_event_get_state_static(ev);
+        elem->value->sdynamic = trace_event_get_state_dynamic(ev);
+        prev->next = elem;
+        prev = elem;
+    }
+    if (!found && !trace_event_is_pattern(name)) {
+        error_setg(errp, "unknown event \"%s\"\n", name);
+    }
+
+    return dummy.next;

The usual way to build a list of some QAPI type would be like this:

    TraceEventStateList *events = NULL;
    TraceEvent *ev;
    TraceEventStateList *elem;

    while ((ev = trace_event_pattern(name, ev)) != NULL) {
        elem = g_new(TraceEventStateList);
        [Initialize *elem...]
        elem->next = events;
        events = elem;
    }

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

    return events;

A good deal easier to understand. Several examples of QMP commands returning lists can be found in qmp.c.

trace/qmp.c line 44

Quoted 8 lines
trace/qmp.c new file +8 -0
+}
+
+void qmp_trace_event_set_state(const char *name, bool state, bool has_keepgoing,
+                               bool keepgoing, Error **errp)
+{
+    bool error = false;
+    bool found = false;
+    TraceEvent *ev = NULL;

Dead initialization.

Quoted 8 lines
trace/qmp.c new file +8 -0
+
+    /* Check all selected events are dynamic */
+    while ((ev = trace_event_pattern(name, ev)) != NULL) {
+        found = true;
+        if (!trace_event_get_state_static(ev)) {
+            error_setg(errp, "cannot set dynamic tracing state for \"%s\"\n",
+                       trace_event_get_name(ev));
+            if (!(has_keepgoing && keepgoing)) {

trace/qmp.c line 62

Quoted 10 lines
trace/qmp.c new file +10 -0
+                error = true;
+            }
+            break;
+        }
+    }
+    if (error) {
+        return;
+    }
+    if (!found && !trace_event_is_pattern(name)) {
+        error_setg(errp, "unknown event \"%s\"\n", name);

Safe, because when the loop above set an error, it also set found; if we get here, the loop didn't set one.

trace/qmp.c line 68

Quoted 6 lines
trace/qmp.c new file +6 -0
+        return;
+    }
+
+    if (error) {
+        return;
+    }

This can't happen.

trace/qmp.c line 71

Quoted 3 lines
trace/qmp.c new file +3 -0
+
+    /* Apply changes */
+    ev = NULL;

Dead assignment.

trace/qmp.c line 77

Quoted 6 lines
trace/qmp.c new file +6 -0
+    while ((ev = trace_event_pattern(name, ev)) != NULL) {
+        if (trace_event_get_state_static(ev)) {
+            trace_event_set_state_dynamic(ev, state);
+        }
+    }
+}

When keepgoing, this can apply changes and still return an error. Intentional?

Your error variable tracks whether an error happened. Why not test for that directly? Of course, you shouldn't test *errp, because that would require a non-null errp argument. You could set local_err, then error_propagate(). Just a thought, perhaps you like it.

Consider splitting this patch into two parts: 1. New QMP commands, 2. reimplement HMP commands in term of the new QMP commands.

#4 lore raw
Quoted 5 lines · Markus Armbruster
Quoted 2 lines · Lluís Vilanova

Also removes old "trace-event", "trace-file" and "info trace-events" HMP commands.

I can't see any HMP commands removal in your patch. You

Sorry, I forgot to remove that from the commit message.

Quoted 40 lines
Quoted 27 lines

---

monitor.c           |   24 +++++++---------
qapi-schema.json    |    3 ++
qapi/trace.json     |   44 +++++++++++++++++++++++++++++
qmp-commands.hx     |   27 ++++++++++++++++++
trace/Makefile.objs |    1 +
trace/control.c     |   13 ---------
trace/control.h     |    7 -----
trace/qmp.c         |   77 +++++++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 162 insertions(+), 34 deletions(-)

create mode 100644 qapi/trace.json
create mode 100644 trace/qmp.c

monitor.c +0 -5
index cdbaa60..0f605f5 100644
@@ -887,19 +887,8 @@ static void do_trace_event_set_state(Monitor *mon, const QDict *qdict)
 const char *tp_name = qdict_get_str(qdict, "name");
 bool new_state = qdict_get_bool(qdict, "option");
 
-    bool found = false;
-    TraceEvent *ev = NULL;
-    while ((ev = trace_event_pattern(tp_name, ev)) != NULL) {
-        found = true;
-        if (!trace_event_get_state_static(ev)) {

monitor.c static void do_trace_event_set_state(Monitor *mon, const QDict *qdict) · line 891

Quoted 10 lines
monitor.c +2 -8
-            monitor_printf(mon, "event \"%s\" is not traceable\n", tp_name);
-        } else {
-            trace_event_set_state_dynamic(ev, new_state);
-        }
-    }
-    if (!trace_event_is_pattern(tp_name) && !found) {
-        monitor_printf(mon, "unknown event name \"%s\"\n", tp_name);
-    }
+    /* TODO: should propagate QMP errors to HMP */
+    qmp_trace_event_set_state(tp_name, new_state, true, true, NULL);

Easy:

Quoted 7 lines
    Error *local_err = NULL;
    [...]
    qmp_trace_event_set_state(tp_name, new_state, true, true, &local_err);
    if (local_err) {
        qerror_report_err(local_err);
        error_free(local_err);
    }

Nice, thanks.

Quoted 5 lines
Quoted 5 lines
monitor.c +0 -0
 }
 
 #ifdef CONFIG_TRACE_SIMPLE
@@ -1079,7 +1068,14 @@ static void do_info_cpu_stats(Monitor *mon, const QDict *qdict)
 
Quoted 7 lines

monitor.c static void do_info_cpu_stats(Monitor *mon, const QDict *qdict) · line 1072

Quoted 5 lines
monitor.c +2 -1
 static void do_trace_print_events(Monitor *mon, const QDict *qdict)
 {
-    trace_print_events((FILE *)mon, &monitor_fprintf);
+    TraceEventStateList *events = qmp_trace_event_get_state("*", NULL);
+    TraceEventStateList *event;

Blank line here, please, to visually separate declarations and statements.

Ok.

Quoted 9 lines

monitor.c static void do_info_cpu_stats(Monitor *mon, const QDict *qdict) · line 1078

Quoted 6 lines
monitor.c +6 -0
+    for (event = events; event != NULL; event = event->next) {
+        monitor_printf(mon, "%s : state %u\n",
+                       event->value->name,
+                       event->value->sstatic && event->value->sdynamic);
+    }
+    qapi_free_TraceEventStateList(events);

Drops "[Event ID %u]" from output. Is that number interesting to users? If no, I don't mind.

I think it's not, that's why I removed it. The removal also avoids exposing that number through the QAPI interface.

Quoted 36 lines
Quoted 23 lines
monitor.c +0 -0
 }
 
 static int client_migrate_info(Monitor *mon, const QDict *qdict,
qapi-schema.json +3 -0
index 341f417..42b90df 100644
@@ -11,6 +11,9 @@
 # QAPI event definitions
 { 'include': 'qapi/event.json' }
 
+# Tracing commands
+{ 'include': 'qapi/trace.json' }
+
 ##
 # LostTickPolicy:
 #
qapi/trace.json new file +0 -0
new file mode 100644
index 0000000..6e6313d

qapi/trace.json line 10

Quoted 10 lines
qapi/trace.json new file +10 -0
@@ -0,0 +1,44 @@
+# -*- mode: python -*-
+
+##
+# @TraceEventState:
+#
+# State of a tracing event.
+#
+# @name: Event name.
+# @sstatic: Static tracing state.
+# @sdynamic: Dynamic tracing state.

Maybe static-state, dynamic-state?

Quoted 1 line

What do static and dynamic state mean?

If "sstatic" is false, it means the event is not available (the event has the "disable" property). Maybe it will be clearer if I merge them into a tristate enum as Eric suggested.

Quoted 6 lines
Quoted 6 lines
qapi/trace.json new file +6 -0
+#
+# Since 2.2
+##
+{ 'type': 'TraceEventState',
+  'data': {'name': 'str', 'sstatic': 'bool', 'sdynamic': 'bool'} }
+
Quoted 8 lines

qapi/trace.json line 22

Quoted 6 lines
qapi/trace.json new file +6 -0
+##
+# @trace-event-get-state:
+#
+# Query the state of events.
+#
+# @name: Event name pattern.

What kind of pattern is this?

See response to Eric.

Quoted 4 lines

qapi/trace.json line 24

Quoted 2 lines
qapi/trace.json new file +2 -0
+#
+# Returns: @TraceEventState of the matched events

Make that "Returns: a list of @TraceEventState for the matching events".

Ok.

Quoted 8 lines
Quoted 8 lines
qapi/trace.json new file +8 -0
+#
+# Since 2.2
+##
+{ 'command': 'trace-event-get-state',
+  'data': {'name': 'str'},
+  'returns': ['TraceEventState'] }
+
+##
Quoted 8 lines

qapi/trace.json line 38

Quoted 6 lines
qapi/trace.json new file +6 -0
+# @trace-event-set-state:
+#
+# Set the dynamic state of events.
+#
+# @name: Event name pattern.
+# @state: Dynamic tracing state.

Suggest to name this argument exactly like the TraceEventState member.

Will do.

Quoted 3 lines

qapi/trace.json line 39

Quoted 1 line
qapi/trace.json new file +1 -0
+# @keepgoing: #optional Apply changes even if not all events can be changed.

How can that happen? I.e. how can setting an event's state fail?

See my explanation about "sstate" above.

Quoted 11 lines

qmp-commands.hx Example: · line 3753

Quoted 11 lines
qapi/trace.json new file +5 -0
+#
+# Since 2.2
+##
+{ 'command': 'trace-event-set-state',
+  'data': {'name': 'str', 'state': 'bool', '*keepgoing': 'bool'} }
qmp-commands.hx +0 -0
index 4be4765..443dd16 100644
@@ -3753,5 +3753,32 @@ Example:
 

-> { "execute": "rtc-reset-reinjection" }

Quoted 137 lines
Quoted 96 lines
qmp-commands.hx +27 -0
 <- { "return": {} }
+EQMP
+
+    {
+        .name       = "trace-event-get-state",
+        .args_type  = "name:s",
+        .mhandler.cmd_new = qmp_marshal_input_trace_event_get_state,
+    },
+
+SQMP
+trace-event-get-state
+---------------------
+
+Query the state of events.
+
+EQMP
+
+    {
+        .name       = "trace-event-set-state",
+        .args_type  = "name:s,state:b,keepgoing:b?",
+        .mhandler.cmd_new = qmp_marshal_input_trace_event_set_state,
+    },
+
+SQMP
+trace-event-set-state
+---------------------
+
+Set the state of events.
 

EQMP

trace/Makefile.objs +0 -0
index 387f191..01b3718 100644
@@ -145,3 +145,4 @@ util-obj-$(CONFIG_TRACE_FTRACE) += ftrace.o

util-obj-$(CONFIG_TRACE_UST) += generated-ust.o
util-obj-y += control.o
util-obj-y += generated-tracers.o

trace/Makefile.objs +1 -0
+util-obj-y += qmp.o
trace/control.c +0 -13
index 9631a40..0d30801 100644
@@ -85,19 +85,6 @@ TraceEvent *trace_event_pattern(const char *pat, TraceEvent *ev)
 return NULL;
 }
 
-void trace_print_events(FILE *stream, fprintf_function stream_printf)
-{
-    TraceEventID i;
-
-    for (i = 0; i < trace_event_count(); i++) {
-        TraceEvent *ev = trace_event_id(i);
-        stream_printf(stream, "%s [Event ID %u] : state %u\n",
-                      trace_event_get_name(ev), i,
-                      trace_event_get_state_static(ev) &&
-                      trace_event_get_state_dynamic(ev));
-    }
-}
-
 static void trace_init_events(const char *fname)
 {
 Location loc;
trace/control.h +0 -7
index e1ec033..da9bb6b 100644
@@ -149,13 +149,6 @@ static void trace_event_set_state_dynamic(TraceEvent *ev, bool state);
 
 
 /**
- * trace_print_events:
- *
- * Print the state of all events.
- */
-void trace_print_events(FILE *stream, fprintf_function stream_printf);
-
-/**
 * trace_init_backends:
 * @events: Name of file with events to be enabled at startup; may be NULL.
 *          Corresponds to commandline option "-trace events=...".
trace/qmp.c new file +9 -0
new file mode 100644
index 0000000..d22d8fa
@@ -0,0 +1,77 @@
+/*
+ * QMP commands for tracing events.
+ *
+ * Copyright (C) 2014 Lluís Vilanova <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+

trace/qmp.c line 19

Quoted 10 lines
trace/qmp.c new file +10 -0
+#include "qemu/typedefs.h"
+#include "qmp-commands.h"
+#include "trace/control.h"
+
+
+TraceEventStateList *qmp_trace_event_get_state(const char *name, Error **errp)
+{
+    TraceEventStateList dummy = {};
+    TraceEventStateList *prev = &dummy;
+

Please move this blank line...

trace/qmp.c line 21

Quoted 2 lines
trace/qmp.c new file +2 -0
+    bool found = false;
+    TraceEvent *ev = NULL;

here, so that it visually separates declarations and statements.

Dead initialization of ev, by the way.

trace/qmp.c line 24

Quoted 3 lines
trace/qmp.c new file +3 -0
+    while ((ev = trace_event_pattern(name, ev)) != NULL) {
+        found = true;
+        TraceEventStateList *elem = g_malloc0(sizeof(*elem));

Declaration follows statement, please don't do that.

trace/qmp.c line 36

Quoted 12 lines
trace/qmp.c new file +12 -0
+        elem->value = g_malloc0(sizeof(*elem->value));
+        elem->value->name = g_strdup(trace_event_get_name(ev));
+        elem->value->sstatic = trace_event_get_state_static(ev);
+        elem->value->sdynamic = trace_event_get_state_dynamic(ev);
+        prev->next = elem;
+        prev = elem;
+    }
+    if (!found && !trace_event_is_pattern(name)) {
+        error_setg(errp, "unknown event \"%s\"\n", name);
+    }
+
+    return dummy.next;

The usual way to build a list of some QAPI type would be like this:

Quoted 7 lines
    TraceEventStateList *events = NULL;
    TraceEvent *ev;
    TraceEventStateList *elem;

    while ((ev = trace_event_pattern(name, ev)) != NULL) {
        elem = g_new(TraceEventStateList);
        [Initialize *elem...]

elem-> next = events;

Quoted 11 lines
        events = elem;
    }

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

    return events;

A good deal easier to understand. Several examples of QMP commands returning lists can be found in qmp.c.

Ok, thanks.

Quoted 10 lines

trace/qmp.c line 44

Quoted 8 lines
trace/qmp.c new file +8 -0
+}
+
+void qmp_trace_event_set_state(const char *name, bool state, bool has_keepgoing,
+                               bool keepgoing, Error **errp)
+{
+    bool error = false;
+    bool found = false;
+    TraceEvent *ev = NULL;

Dead initialization.

Ok.

Quoted 44 lines
Quoted 8 lines
trace/qmp.c new file +8 -0
+
+    /* Check all selected events are dynamic */
+    while ((ev = trace_event_pattern(name, ev)) != NULL) {
+        found = true;
+        if (!trace_event_get_state_static(ev)) {
+            error_setg(errp, "cannot set dynamic tracing state for \"%s\"\n",
+                       trace_event_get_name(ev));
+            if (!(has_keepgoing && keepgoing)) {

trace/qmp.c line 62

Quoted 10 lines
trace/qmp.c new file +10 -0
+                error = true;
+            }
+            break;
+        }
+    }
+    if (error) {
+        return;
+    }
+    if (!found && !trace_event_is_pattern(name)) {
+        error_setg(errp, "unknown event \"%s\"\n", name);

Safe, because when the loop above set an error, it also set found; if we get here, the loop didn't set one.

trace/qmp.c line 68

Quoted 6 lines
trace/qmp.c new file +6 -0
+        return;
+    }
+
+    if (error) {
+        return;
+    }

This can't happen.

trace/qmp.c line 71

Quoted 3 lines
trace/qmp.c new file +3 -0
+
+    /* Apply changes */
+    ev = NULL;

Dead assignment.

trace/qmp.c line 77

Quoted 6 lines
trace/qmp.c new file +6 -0
+    while ((ev = trace_event_pattern(name, ev)) != NULL) {
+        if (trace_event_get_state_static(ev)) {
+            trace_event_set_state_dynamic(ev, state);
+        }
+    }
+}
Quoted 2 lines

When keepgoing, this can apply changes and still return an error. Intentional?

Yes, but it does sound that good now...

Quoted 4 lines

Your error variable tracks whether an error happened. Why not test for that directly? Of course, you shouldn't test *errp, because that would require a non-null errp argument. You could set local_err, then error_propagate(). Just a thought, perhaps you like it.

Right, and I can skip propagation if "keepgoing" is set. Much better.

Quoted 2 lines

Consider splitting this patch into two parts: 1. New QMP commands, 2. reimplement HMP commands in term of the new QMP commands.

Will do.

Thanks,
Lluis

Signature · 4 lines
 "And it's much the same thing with knowledge, for whenever you learn
 something new, the whole world becomes that much richer."
 -- The Princess of Pure Reason, as told by Norton Juster in The Phantom
 Tollbooth
#5 lore raw
In reply to Lluís Vilanova
Quoted 20 lines · Lluís Vilanova

Also removes old "trace-event", "trace-file" and "info trace-events" HMP commands.

---
 monitor.c           |   24 +++++++---------
 qapi-schema.json    |    3 ++
 qapi/trace.json     |   44 +++++++++++++++++++++++++++++
 qmp-commands.hx     |   27 ++++++++++++++++++
 trace/Makefile.objs |    1 +
 trace/control.c     |   13 ---------
 trace/control.h     |    7 -----
 trace/qmp.c         |   77 +++++++++++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 162 insertions(+), 34 deletions(-)
 create mode 100644 qapi/trace.json
 create mode 100644 trace/qmp.c

+++ b/qapi/trace.json

Review line 2

Quoted 2 lines
(quoted diff) +2 -0
@@ -0,0 +1,44 @@
+# -*- mode: python -*-
+

No copyright statement (but you are just following (poor) existing practice).

qapi/trace.json line 10

Quoted 8 lines
qapi/trace.json new file +8 -0
+##
+# @TraceEventState:
+#
+# State of a tracing event.
+#
+# @name: Event name.
+# @sstatic: Static tracing state.
+# @sdynamic: Dynamic tracing state.

Does the leading 's' add any value? QAPI doesn't have to use obscure abbreviations.

qapi/trace.json line 15

Quoted 5 lines
qapi/trace.json new file +5 -0
+#
+# Since 2.2
+##
+{ 'type': 'TraceEventState',
+  'data': {'name': 'str', 'sstatic': 'bool', 'sdynamic': 'bool'} }

Are all four states between the combinations of the two bools possible, or is this more of a tri-state setting (default, sstatic, or sdynamic), in which case a single parameter of enum type would be better than two bools?

qapi/trace.json line 22

Quoted 7 lines
qapi/trace.json new file +7 -0
+
+##
+# @trace-event-get-state:
+#
+# Query the state of events.
+#
+# @name: Event name pattern.

glob? regex? Is the pattern anchored or just substring analysis? Case-sensitive?

qapi/trace.json line 30

Quoted 8 lines
qapi/trace.json new file +8 -0
+#
+# Returns: @TraceEventState of the matched events
+#
+# Since 2.2
+##
+{ 'command': 'trace-event-get-state',
+  'data': {'name': 'str'},
+  'returns': ['TraceEventState'] }

What if I want ALL events? Can name be made optional to avoid any filtering?

qapi/trace.json line 37

Quoted 7 lines
qapi/trace.json new file +7 -0
+
+##
+# @trace-event-set-state:
+#
+# Set the dynamic state of events.
+#
+# @name: Event name pattern.

Same comments about pattern as before.

qapi/trace.json line 39

Quoted 2 lines
qapi/trace.json new file +2 -0
+# @state: Dynamic tracing state.
+# @keepgoing: #optional Apply changes even if not all events can be changed.

keep-going - use dash to separate words for legibility

qapi/trace.json line 44

Quoted 5 lines
qapi/trace.json new file +5 -0
+#
+# Since 2.2
+##
+{ 'command': 'trace-event-set-state',
+  'data': {'name': 'str', 'state': 'bool', '*keepgoing': 'bool'} }

This only lets me set the state of one name at a time. Oh, unless I'm setting a pattern, and it then sets the state of all names that match that pattern. I'm wondering if you should have 'name':['str'] to allow me to set multiple names/patterns in one go, instead of having to call the command multiple times; but it's probably not worth the complexity.

Quoted 11 lines
qmp-commands.hx +3 -0
index 4be4765..443dd16 100644
@@ -3753,5 +3753,32 @@ Example:
 
 -> { "execute": "rtc-reset-reinjection" }
 <- { "return": {} }
+EQMP
+
+    {

qmp-commands.hx Example: · line 3768

Quoted 10 lines
qmp-commands.hx +10 -0
+        .name       = "trace-event-get-state",
+        .args_type  = "name:s",
+        .mhandler.cmd_new = qmp_marshal_input_trace_event_get_state,
+    },
+
+SQMP
+trace-event-get-state
+---------------------
+
+Query the state of events.

No example usage?

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#6 lore raw
Quoted 19 lines · Eric Blake
Quoted 17 lines · Lluís Vilanova

Also removes old "trace-event", "trace-file" and "info trace-events" HMP commands.

---

monitor.c           |   24 +++++++---------
qapi-schema.json    |    3 ++
qapi/trace.json     |   44 +++++++++++++++++++++++++++++
qmp-commands.hx     |   27 ++++++++++++++++++
trace/Makefile.objs |    1 +
trace/control.c     |   13 ---------
trace/control.h     |    7 -----
trace/qmp.c         |   77 +++++++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 162 insertions(+), 34 deletions(-)

create mode 100644 qapi/trace.json
create mode 100644 trace/qmp.c

Quoted 7 lines

Review line 2

Quoted 4 lines

+++ b/qapi/trace.json

(quoted diff) +2 -0
@@ -0,0 +1,44 @@
+# -*- mode: python -*-
+

No copyright statement (but you are just following (poor) existing practice).

Will add.

Quoted 11 lines

qapi/trace.json line 10

Quoted 8 lines
qapi/trace.json new file +8 -0
+##
+# @TraceEventState:
+#
+# State of a tracing event.
+#
+# @name: Event name.
+# @sstatic: Static tracing state.
+# @sdynamic: Dynamic tracing state.

Does the leading 's' add any value? QAPI doesn't have to use obscure abbreviations.

It felt wrong to have a JSON attribute named differently from the C struct (static is a reserved word).

Quoted 10 lines

qapi/trace.json line 15

Quoted 5 lines
qapi/trace.json new file +5 -0
+#
+# Since 2.2
+##
+{ 'type': 'TraceEventState',
+  'data': {'name': 'str', 'sstatic': 'bool', 'sdynamic': 'bool'} }

Are all four states between the combinations of the two bools possible, or is this more of a tri-state setting (default, sstatic, or sdynamic), in which case a single parameter of enum type would be better than two bools?

I can certainly change it to an "state" enum:

* unavailable: statically disabled
* disabled : statically enabled, dynamically disabled
* enabled : statically enabled, dynamically enabled

Quoted 10 lines

qapi/trace.json line 22

Quoted 7 lines
qapi/trace.json new file +7 -0
+
+##
+# @trace-event-get-state:
+#
+# Query the state of events.
+#
+# @name: Event name pattern.

glob? regex? Is the pattern anchored or just substring analysis? Case-sensitive?

It's the same pattern matching used internally in QEMU (case-sensitive globbing).

Quoted 11 lines

qapi/trace.json line 30

Quoted 8 lines
qapi/trace.json new file +8 -0
+#
+# Returns: @TraceEventState of the matched events
+#
+# Since 2.2
+##
+{ 'command': 'trace-event-get-state',
+  'data': {'name': 'str'},
+  'returns': ['TraceEventState'] }

What if I want ALL events? Can name be made optional to avoid any filtering?

I use "*" as the "name", which seems simple enough to me.

Quoted 10 lines

qapi/trace.json line 37

Quoted 7 lines
qapi/trace.json new file +7 -0
+
+##
+# @trace-event-set-state:
+#
+# Set the dynamic state of events.
+#
+# @name: Event name pattern.

Same comments about pattern as before.

Quoted 4 lines

qapi/trace.json line 39

Quoted 2 lines
qapi/trace.json new file +2 -0
+# @state: Dynamic tracing state.
+# @keepgoing: #optional Apply changes even if not all events can be changed.

keep-going - use dash to separate words for legibility

Ok.

Quoted 11 lines

qapi/trace.json line 44

Quoted 5 lines
qapi/trace.json new file +5 -0
+#
+# Since 2.2
+##
+{ 'command': 'trace-event-set-state',
+  'data': {'name': 'str', 'state': 'bool', '*keepgoing': 'bool'} }

This only lets me set the state of one name at a time. Oh, unless I'm setting a pattern, and it then sets the state of all names that match that pattern. I'm wondering if you should have 'name':['str'] to allow me to set multiple names/patterns in one go, instead of having to call the command multiple times; but it's probably not worth the complexity.

I agree with the complexity comment. Also, the keepgoing is useful to set events using a pattern, even if some of them are statically disabled (otherwise it gives an error).

Quoted 6 lines

qmp-commands.hx Example: · line 3753

Quoted 6 lines
qmp-commands.hx +0 -0
index 4be4765..443dd16 100644
@@ -3753,5 +3753,32 @@ Example:
 

-> { "execute": "rtc-reset-reinjection" }

Quoted 8 lines
Quoted 8 lines
qmp-commands.hx +7 -0
 <- { "return": {} }
+EQMP
+
+    {
+        .name       = "trace-event-get-state",
+        .args_type  = "name:s",
+        .mhandler.cmd_new = qmp_marshal_input_trace_event_get_state,
+    },
Quoted 8 lines

qmp-commands.hx Example: · line 3768

Quoted 6 lines
qmp-commands.hx +6 -0
+
+SQMP
+trace-event-get-state
+---------------------
+
+Query the state of events.

No example usage?

Heh, lazy me. Will add.

Thanks,
Lluis

Signature · 4 lines
 "And it's much the same thing with knowledge, for whenever you learn
 something new, the whole world becomes that much richer."
 -- The Princess of Pure Reason, as told by Norton Juster in The Phantom
 Tollbooth
#7 lore raw
Quoted 9 lines · Lluís Vilanova
Quoted 6 lines

qapi/trace.json line 10

Quoted 3 lines
qapi/trace.json new file +3 -0
+# @name: Event name.
+# @sstatic: Static tracing state.
+# @sdynamic: Dynamic tracing state.

Does the leading 's' add any value? QAPI doesn't have to use obscure abbreviations.

It felt wrong to have a JSON attribute named differently from the C struct (static is a reserved word).

The qapi generator will automatically convert 'static' in QMP to q_static in C code. I'd rather the QMP looks clean, even if the underlying C code has to deal with a munged name.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#8 lore raw
In reply to Lluís Vilanova
Quoted 60 lines · Lluís Vilanova
Quoted 20 lines · Eric Blake
Quoted 18 lines · Lluís Vilanova

Also removes old "trace-event", "trace-file" and "info trace-events" HMP commands.

---

monitor.c           |   24 +++++++---------
qapi-schema.json    |    3 ++
qapi/trace.json     |   44 +++++++++++++++++++++++++++++
qmp-commands.hx     |   27 ++++++++++++++++++
trace/Makefile.objs |    1 +
trace/control.c     |   13 ---------
trace/control.h     |    7 -----
trace/qmp.c | 77
+++++++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 162 insertions(+), 34 deletions(-)

create mode 100644 qapi/trace.json
create mode 100644 trace/qmp.c

Quoted 7 lines

Review line 2

Quoted 4 lines

+++ b/qapi/trace.json

(quoted diff) +2 -0
@@ -0,0 +1,44 @@
+# -*- mode: python -*-
+

No copyright statement (but you are just following (poor) existing practice).

Will add.

Quoted 11 lines

qapi/trace.json line 10

Quoted 8 lines
qapi/trace.json new file +8 -0
+##
+# @TraceEventState:
+#
+# State of a tracing event.
+#
+# @name: Event name.
+# @sstatic: Static tracing state.
+# @sdynamic: Dynamic tracing state.

Does the leading 's' add any value? QAPI doesn't have to use obscure abbreviations.

It felt wrong to have a JSON attribute named differently from the C struct (static is a reserved word).

Quoted 10 lines

qapi/trace.json line 15

Quoted 5 lines
qapi/trace.json new file +5 -0
+#
+# Since 2.2
+##
+{ 'type': 'TraceEventState',
+  'data': {'name': 'str', 'sstatic': 'bool', 'sdynamic': 'bool'} }

Are all four states between the combinations of the two bools possible, or is this more of a tri-state setting (default, sstatic, or sdynamic), in which case a single parameter of enum type would be better than two bools?

Quoted 5 lines

I can certainly change it to an "state" enum:

* unavailable: statically disabled
* disabled : statically enabled, dynamically disabled
* enabled : statically enabled, dynamically enabled

Yes, please; it's neater.

Quoted 11 lines
Quoted 10 lines

qapi/trace.json line 22

Quoted 7 lines
qapi/trace.json new file +7 -0
+
+##
+# @trace-event-get-state:
+#
+# Query the state of events.
+#
+# @name: Event name pattern.

glob? regex? Is the pattern anchored or just substring analysis? Case-sensitive?

Quoted 2 lines

It's the same pattern matching used internally in QEMU (case-sensitive globbing).

Please document it.

Quoted 12 lines
Quoted 11 lines

qapi/trace.json line 30

Quoted 8 lines
qapi/trace.json new file +8 -0
+#
+# Returns: @TraceEventState of the matched events
+#
+# Since 2.2
+##
+{ 'command': 'trace-event-get-state',
+  'data': {'name': 'str'},
+  'returns': ['TraceEventState'] }

What if I want ALL events? Can name be made optional to avoid any filtering?

Quoted 1 line

I use "*" as the "name", which seems simple enough to me.

Good enough for me, too.

Quoted 30 lines
Quoted 10 lines

qapi/trace.json line 37

Quoted 7 lines
qapi/trace.json new file +7 -0
+
+##
+# @trace-event-set-state:
+#
+# Set the dynamic state of events.
+#
+# @name: Event name pattern.

Same comments about pattern as before.

Quoted 4 lines

qapi/trace.json line 39

Quoted 2 lines
qapi/trace.json new file +2 -0
+# @state: Dynamic tracing state.
+# @keepgoing: #optional Apply changes even if not all events can be changed.

keep-going - use dash to separate words for legibility

Ok.

Quoted 11 lines

qapi/trace.json line 44

Quoted 5 lines
qapi/trace.json new file +5 -0
+#
+# Since 2.2
+##
+{ 'command': 'trace-event-set-state',
+  'data': {'name': 'str', 'state': 'bool', '*keepgoing': 'bool'} }

This only lets me set the state of one name at a time. Oh, unless I'm setting a pattern, and it then sets the state of all names that match that pattern. I'm wondering if you should have 'name':['str'] to allow me to set multiple names/patterns in one go, instead of having to call the command multiple times; but it's probably not worth the complexity.

Quoted 3 lines

I agree with the complexity comment. Also, the keepgoing is useful to set events using a pattern, even if some of them are statically disabled (otherwise it gives an error).

Yes, let's keep this simple.

However, I feel keepgoing is unnecessarily vague. Its purpose is to enable use of a pattern in the presence of disabled events. I'd prefer to nail it down to exactly that purpose rather than having it cover arbitrary, unspecified errors.

A few ideas on how to do that:

* Have a flag to modify the semantics of the pattern: either "match all events", or "match just disabled and enabled events, not unavailable events".

* To find out what a trace-event-set-state actually does, you need to trace-event-get-state the same pattern. We could make trace-event-set-state return the events it changed, so you never have to trace-event-get-state, but it's probably not worthwhile.

[...]

#9 lore raw
Quoted 4 lines · Markus Armbruster
Quoted 3 lines · Lluís Vilanova
Quoted 1 line · Eric Blake

On 08/21/2014 11:52 AM, Lluís Vilanova wrote:

[...]

Quoted 29 lines
Quoted 12 lines
Quoted 11 lines

qapi/trace.json line 44

Quoted 5 lines
qapi/trace.json new file +5 -0
+#
+# Since 2.2
+##
+{ 'command': 'trace-event-set-state',
+  'data': {'name': 'str', 'state': 'bool', '*keepgoing': 'bool'} }

This only lets me set the state of one name at a time. Oh, unless I'm setting a pattern, and it then sets the state of all names that match that pattern. I'm wondering if you should have 'name':['str'] to allow me to set multiple names/patterns in one go, instead of having to call the command multiple times; but it's probably not worth the complexity.

Quoted 3 lines

I agree with the complexity comment. Also, the keepgoing is useful to set events using a pattern, even if some of them are statically disabled (otherwise it gives an error).

Yes, let's keep this simple.

However, I feel keepgoing is unnecessarily vague. Its purpose is to enable use of a pattern in the presence of disabled events. I'd prefer to nail it down to exactly that purpose rather than having it cover arbitrary, unspecified errors.

A few ideas on how to do that:

* Have a flag to modify the semantics of the pattern: either "match all events", or "match just disabled and enabled events, not unavailable events".

Quoted 6 lines

* To find out what a trace-event-set-state actually does, you need to trace-event-get-state the same pattern. We could make trace-event-set-state return the events it changed, so you never have to trace-event-get-state, but it's probably not worthwhile.

[...]

I've renamed it to "ignore-unavailable" (off by default).

Thanks,
Lluis

Signature · 4 lines
 "And it's much the same thing with knowledge, for whenever you learn
 something new, the whole world becomes that much richer."
 -- The Princess of Pure Reason, as told by Norton Juster in The Phantom
 Tollbooth