Skip to contentSkip to conversation

QMP Query interfaces for tracing

RFC PATCH Superseded Prerna Saxena 2 participants 4 messages Oct 15, 2010

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover QMP Query interfaces for tracing

This patch set introduces two QMP interfaces for tracing :

* query-trace : to list current contents of trace-buffer
* query-trace-events : to list all available trace-events with their state.

Changelog :
-----------
Changes from v1 :
- Add 'timestamp' field for query-trace output.
- Misc cleanups.

Signature · 5 lines
Prerna Saxena

Linux Technology Centre,
IBM Systems and Technology Lab,
Bangalore, India
#1 lore raw

RFC PATCH v2 1/2 Introduce 'query-trace' & 'query-trace-events' interfaces

[PATCH 1/2] Introduce QMP interfaces : query-trace & query-trace-events

---
 monitor.c     |   46 +++++++++++++++++++++++++++++++++++++++++---
 simpletrace.c |   58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 simpletrace.h |    4 +++
 3 files changed, 104 insertions(+), 4 deletions(-)
monitor.c +42 -4
index fbb678d..7a150ae 100644
@@ -941,15 +941,33 @@ static void do_info_cpu_stats(Monitor *mon)
 #endif
 
 #if defined(CONFIG_SIMPLE_TRACE)
-static void do_info_trace(Monitor *mon)
+static void do_info_trace_print(Monitor *mon)
 {
     st_print_trace((FILE *)mon, &monitor_fprintf);
 }
 
-static void do_info_trace_events(Monitor *mon)
+static void do_info_trace(Monitor *mon, QObject **ret_data)
+{
+    QList *trace_event_list = NULL;
+
+    st_print_trace_to_qlist(&trace_event_list);
+
+    *ret_data = QOBJECT(trace_event_list);
+}
+
+static void do_info_trace_events_print(Monitor *mon, const QObject *data)
 {
     st_print_trace_events((FILE *)mon, &monitor_fprintf);
 }
+
+static void do_info_trace_events(Monitor *mon, QObject **ret_data)
+{
+    QList *trace_event_list = NULL;
+
+    st_print_trace_events_to_qlist(&trace_event_list);
+
+    *ret_data = QOBJECT(trace_event_list);
+}
 #endif
 
 /**
@@ -2606,14 +2624,16 @@ static const mon_cmd_t info_cmds[] = {
         .args_type  = "",
         .params     = "",
         .help       = "show current contents of trace buffer",
-        .mhandler.info = do_info_trace,
+        .user_print = do_info_trace_print,
+        .mhandler.info_new = do_info_trace,
     },
     {
         .name       = "trace-events",
         .args_type  = "",
         .params     = "",
         .help       = "show available trace-events & their state",
-        .mhandler.info = do_info_trace_events,
+        .user_print = do_info_trace_events_print,
+        .mhandler.info_new = do_info_trace_events,
     },
 #endif
     {
@@ -2748,6 +2768,24 @@ static const mon_cmd_t qmp_query_cmds[] = {
         .mhandler.info_async = do_info_balloon,
         .flags      = MONITOR_CMD_ASYNC,
     },
+#if defined(CONFIG_SIMPLE_TRACE)
+    {
+        .name       = "trace",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show current contents of trace buffer",
+        .user_print = do_info_trace_print,
+        .mhandler.info_new = do_info_trace,
+    },
+    {
+        .name       = "trace-events",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show available trace-events & their state",
+        .user_print = do_info_trace_events_print,
+        .mhandler.info_new = do_info_trace_events,
+    },
+#endif
     { /* NULL */ },
 };
 
simpletrace.c +58 -0

70 lines not on this page · raw message

simpletrace.h +4 -0
index cf35897..6043c21 100644
@@ -14,6 +14,8 @@
 #include <stdint.h>
 #include <stdbool.h>
 #include <stdio.h>
+#include "qdict.h"
+#include "qjson.h"
 
 typedef uint64_t TraceEventID;
 
@@ -36,5 +38,7 @@ void st_print_trace_file_status(FILE *stream, int (*stream_printf)(FILE *stream,
 void st_set_trace_file_enabled(bool enable);
 bool st_set_trace_file(const char *file);
 void st_flush_trace_buffer(void);
+void st_print_trace_to_qlist(QList **tlist);
+void st_print_trace_events_to_qlist(QList **tlist);
 
 #endif /* SIMPLETRACE_H */
Signature · 10 lines
1.7.2.2



-- 
Prerna Saxena

Linux Technology Centre,
IBM Systems and Technology Lab,
Bangalore, India
#3 lore raw

RFC PATCH v2 2/2 Documentation for QMP interfaces

In reply to Prerna Saxena

[PATCH 2/2] Add documentation for QMP commands: query-trace & query-trace-events.

---
 qmp-commands.hx |   71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 71 insertions(+), 0 deletions(-)
qmp-commands.hx +71 -0
index 793cf1c..fefc93d 100644
@@ -1539,3 +1539,74 @@ Example:
 
 EQMP
 
+SQMP
+query-trace
+-------------
+
+Show contents of trace buffer.
+
+Returns a set of json-objects containing the following data:
+
+- "event": Event ID for the trace-event(json-int)
+- "timestamp": trace timestamp (json-int)
+- "arg1 .. arg6": Arguments logged by the trace-event (json-int)
+
+Example:
+
+-> { "execute": "query-trace" }
+<- {
+      "return":{
+         "event": 22,
+         "timestamp": 129456235912365,
+         "arg1": 886
+         "arg2": 80,
+         "arg3": 0,
+         "arg4": 0,
+         "arg5": 0,
+         "arg6": 0,
+       },
+       {
+         "event": 22,
+         "timestamp": 129456235973407,
+         "arg1": 886,
+         "arg2": 80,
+         "arg3": 0,
+         "arg4": 0,
+         "arg5": 0,
+         "arg6": 0
+       },
+       ...
+   }
+
+EQMP
+
+SQMP
+query-trace-events
+------------------
+
+Show all available trace-events & their state.
+
+Returns a set of json-objects containing the following data:
+
+- "name": Name of Trace-event (json-string)
+- "event-id": Event ID of Trace-event (json-int)
+- "state": State of trace-event [ '0': inactive; '1':active  ] (json-int)
+
+Example:
+
+-> { "execute": "query-trace-events" }
+<- {
+      "return":{
+         "name": "qemu_malloc",
+         "event-id": 0
+         "state": 0,
+      },
+      {
+         "name": "qemu_realloc",
+         "event-id": 1,
+         "state": 0
+      },
+      ...
+   }
+
+EQMP
Signature · 10 lines
1.7.2.2



-- 
Prerna Saxena

Linux Technology Centre,
IBM Systems and Technology Lab,
Bangalore, India
#2 lore raw

[Qemu-devel] Re: [Tracing][RFC v2 PATCH 1/2] Introduce 'query-trace' & 'query-trace-events' interfaces

In reply to Prerna Saxena
Quoted 99 lines · Prerna Saxena

[PATCH 1/2] Introduce QMP interfaces : query-trace & query-trace-events

---
 monitor.c     |   46 +++++++++++++++++++++++++++++++++++++++++---
 simpletrace.c |   58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 simpletrace.h |    4 +++
 3 files changed, 104 insertions(+), 4 deletions(-)
monitor.c +42 -4
index fbb678d..7a150ae 100644
@@ -941,15 +941,33 @@ static void do_info_cpu_stats(Monitor *mon)
 #endif
 
 #if defined(CONFIG_SIMPLE_TRACE)
-static void do_info_trace(Monitor *mon)
+static void do_info_trace_print(Monitor *mon)
 {
     st_print_trace((FILE *)mon, &monitor_fprintf);
 }
 
-static void do_info_trace_events(Monitor *mon)
+static void do_info_trace(Monitor *mon, QObject **ret_data)
+{
+    QList *trace_event_list = NULL;
+
+    st_print_trace_to_qlist(&trace_event_list);
+
+    *ret_data = QOBJECT(trace_event_list);
+}
+
+static void do_info_trace_events_print(Monitor *mon, const QObject *data)
 {
     st_print_trace_events((FILE *)mon, &monitor_fprintf);
 }
+
+static void do_info_trace_events(Monitor *mon, QObject **ret_data)
+{
+    QList *trace_event_list = NULL;
+
+    st_print_trace_events_to_qlist(&trace_event_list);
+
+    *ret_data = QOBJECT(trace_event_list);
+}
 #endif
 
 /**
@@ -2606,14 +2624,16 @@ static const mon_cmd_t info_cmds[] = {
         .args_type  = "",
         .params     = "",
         .help       = "show current contents of trace buffer",
-        .mhandler.info = do_info_trace,
+        .user_print = do_info_trace_print,
+        .mhandler.info_new = do_info_trace,
     },
     {
         .name       = "trace-events",
         .args_type  = "",
         .params     = "",
         .help       = "show available trace-events & their state",
-        .mhandler.info = do_info_trace_events,
+        .user_print = do_info_trace_events_print,
+        .mhandler.info_new = do_info_trace_events,
     },
 #endif
     {
@@ -2748,6 +2768,24 @@ static const mon_cmd_t qmp_query_cmds[] = {
         .mhandler.info_async = do_info_balloon,
         .flags      = MONITOR_CMD_ASYNC,
     },
+#if defined(CONFIG_SIMPLE_TRACE)
+    {
+        .name       = "trace",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show current contents of trace buffer",
+        .user_print = do_info_trace_print,
+        .mhandler.info_new = do_info_trace,
+    },
+    {
+        .name       = "trace-events",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show available trace-events & their state",
+        .user_print = do_info_trace_events_print,
+        .mhandler.info_new = do_info_trace_events,
+    },
+#endif
     { /* NULL */ },
 };
 
simpletrace.c +0 -0
index f849e42..a964312 100644

simpletrace.c void st_print_trace(FILE *stream, int (*stream_printf)(FILE *stream, const char · line 228

Quoted 9 lines
simpletrace.c +6 -0
@@ -220,6 +220,43 @@ void st_print_trace(FILE *stream, int (*stream_printf)(FILE *stream, const char
     }
 }
 
+/**
+ * Add the current contents of trace-buffer as a QList.
+ * NOTE: This assumes trace_list hasnt already been allocated with a QList.
+ *        The initialization happens here.
+ */
+void st_print_trace_to_qlist(QList **tlist)

These functions can be simplified by changing their prototypes:

QList *st_get_trace_qlist(void)
QList *st_get_trace_events_qlist(void)

This eliminates the possibility for misuse. The comment and assert can be dropped.

Sorry I didn't think of this the first time.

Quoted 45 lines
simpletrace.c +38 -0
+{
+    QObject *data;
+    unsigned int i;
+
+    assert(tlist);
+
+    *tlist = qlist_new();
+
+    for (i = 0; i < trace_idx; i++) {
+          data = qobject_from_jsonf("{"
+                                    " 'timestamp': %" PRId64 ","
+                                    " 'event': %" PRId64 ","
+                                    " 'arg1': %" PRId64 ","
+                                    " 'arg2': %" PRId64 ","
+                                    " 'arg3': %" PRId64 ","
+                                    " 'arg4': %" PRId64 ","
+                                    " 'arg5': %" PRId64 ","
+                                    " 'arg6': %" PRId64
+                                    "}",
+                                    trace_buf[i].timestamp_ns,
+                                    trace_buf[i].event,
+                                    trace_buf[i].x1,
+                                    trace_buf[i].x2,
+                                    trace_buf[i].x3,
+                                    trace_buf[i].x4,
+                                    trace_buf[i].x5,
+                                    trace_buf[i].x6);
+          qlist_append_obj(*tlist, data);
+    }
+}
+
 void st_print_trace_events(FILE *stream, int (*stream_printf)(FILE *stream, const char *fmt, ...))
 {
     unsigned int i;
@@ -230,6 +267,27 @@ void st_print_trace_events(FILE *stream, int (*stream_printf)(FILE *stream, cons
     }
 }
 
+/**
+ * Add current set of trace-events as a QList.
+ * NOTE: This assumes trace_list hasnt already been allocated with a QList.
+ *        The initialization happens here.
+ */
+void st_print_trace_events_to_qlist(QList **tlist)
+{

simpletrace.c void st_print_trace_events(FILE *stream, int (*stream_printf)(FILE *stream, cons · line 286

Quoted 10 lines
simpletrace.c +10 -0
+    QObject *data;
+    unsigned int i;
+
+    assert(tlist);
+
+    *tlist = qlist_new();
+
+    for (i = 0; i < NR_TRACE_EVENTS; i++) {
+          data = qobject_from_jsonf("{ 'name': %s, 'event-id': %d, 'state': %d}                                    ", trace_list[i].tp_name, i,
+                                    trace_list[i].state);

Why all the spaces in the format string?

simpletrace.c void st_print_trace_events(FILE *stream, int (*stream_printf)(FILE *stream, cons · line 293

Quoted 7 lines
simpletrace.c +4 -0
+          qlist_append_obj(*tlist, data);
+    }
+}
+
 static TraceEvent* find_trace_event_by_name(const char *tname)
 {
     unsigned int i;

Stefan