diff mbox

[Tracing,v4,1/2] Introduce QMP interfaces

Message ID 20101019115550.2a3d6682@zephyr
State New
Headers show

Commit Message

Prerna Saxena Oct. 19, 2010, 6:25 a.m. UTC
[PATCH 1/2] Introduce QMP interfaces :
 - query-trace
 - query-trace-events
 - query-trace-file


Signed-off-by: Prerna Saxena <prerna@linux.vnet.ibm.com>
---
 monitor.c     |   53 ++++++++++++++++++++++++++++++++++++++++---
 simpletrace.c |   69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 simpletrace.h |    5 ++++
 3 files changed, 123 insertions(+), 4 deletions(-)

Comments

Stefan Hajnoczi Oct. 19, 2010, 9:12 a.m. UTC | #1
On Tue, Oct 19, 2010 at 11:55:50AM +0530, Prerna Saxena wrote:
> [PATCH 1/2] Introduce QMP interfaces :
>  - query-trace
>  - query-trace-events
>  - query-trace-file
> 
> 
> Signed-off-by: Prerna Saxena <prerna@linux.vnet.ibm.com>
> ---
>  monitor.c     |   53 ++++++++++++++++++++++++++++++++++++++++---
>  simpletrace.c |   69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  simpletrace.h |    5 ++++
>  3 files changed, 123 insertions(+), 4 deletions(-)

Acked-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
diff mbox

Patch

diff --git a/monitor.c b/monitor.c
index 260cc02..c7e1f53 100644
--- a/monitor.c
+++ b/monitor.c
@@ -578,6 +578,11 @@  static void do_trace_file(Monitor *mon, const QDict *qdict)
         help_cmd(mon, "trace-file");
     }
 }
+
+static void do_info_trace_file_to_qmp(Monitor *mon, QObject **ret_data)
+{
+    *ret_data = st_print_file_to_qobject();
+}
 #endif
 
 static void user_monitor_complete(void *opaque, QObject *ret_data)
@@ -945,15 +950,27 @@  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, const QObject *data)
 {
     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 = st_print_trace_to_qlist();
+    *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 = st_print_trace_events_to_qlist();
+    *ret_data = QOBJECT(trace_event_list);
+}
 #endif
 
 /**
@@ -2610,14 +2627,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
     {
@@ -2752,6 +2771,32 @@  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,
+    },
+    {
+        .name       = "trace-file",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show currently active trace output file and its status",
+        .user_print = monitor_user_noop,
+        .mhandler.info_new = do_info_trace_file_to_qmp,
+    },
+#endif
     { /* NULL */ },
 };
 
diff --git a/simpletrace.c b/simpletrace.c
index deb1e07..d24d6b0 100644
--- a/simpletrace.c
+++ b/simpletrace.c
@@ -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.
+ *
+ */
+QList* st_print_trace_to_qlist(void)
+{
+    QObject *data;
+    QList *tlist;
+    unsigned int i;
+
+    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);
+    }
+
+    return tlist;
+}
+
 void st_print_trace_events(FILE *stream, int (*stream_printf)(FILE *stream, const char *fmt, ...))
 {
     unsigned int i;
@@ -230,6 +267,38 @@  void st_print_trace_events(FILE *stream, int (*stream_printf)(FILE *stream, cons
     }
 }
 
+/**
+ * Add current set of trace-events as a QList.
+ *
+ */
+QList* st_print_trace_events_to_qlist(void)
+{
+    QObject *data;
+    QList *tlist;
+    unsigned int i;
+
+    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);
+          qlist_append_obj(tlist, data);
+    }
+
+    return tlist;
+}
+
+/**
+ * Display the current trace-file with its status, as a QObject.
+ *
+ */
+QObject* st_print_file_to_qobject(void)
+{
+    return qobject_from_jsonf("{ 'trace-file': %s, 'status':  %d }",
+                                trace_file_name, trace_file_enabled);
+}
+
 static TraceEvent* find_trace_event_by_name(const char *tname)
 {
     unsigned int i;
diff --git a/simpletrace.h b/simpletrace.h
index 72614ec..76104b0 100644
--- a/simpletrace.h
+++ b/simpletrace.h
@@ -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,8 @@  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);
+QList* st_print_trace_to_qlist(void);
+QList* st_print_trace_events_to_qlist(void);
+QObject* st_print_file_to_qobject(void);
 
 #endif /* SIMPLETRACE_H */