From patchwork Mon Oct 18 06:14:33 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prerna Saxena X-Patchwork-Id: 68125 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9CA14B70E9 for ; Mon, 18 Oct 2010 17:19:03 +1100 (EST) Received: from localhost ([127.0.0.1]:53464 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P7j3k-0004FN-9a for incoming@patchwork.ozlabs.org; Mon, 18 Oct 2010 02:19:00 -0400 Received: from [140.186.70.92] (port=49809 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P7j1G-0003s1-DW for qemu-devel@nongnu.org; Mon, 18 Oct 2010 02:16:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P7j1F-0004eF-9d for qemu-devel@nongnu.org; Mon, 18 Oct 2010 02:16:26 -0400 Received: from e23smtp04.au.ibm.com ([202.81.31.146]:53949) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P7j1E-0004e8-Op for qemu-devel@nongnu.org; Mon, 18 Oct 2010 02:16:25 -0400 Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [202.81.31.245]) by e23smtp04.au.ibm.com (8.14.4/8.13.1) with ESMTP id o9I6BXQ2017439 for ; Mon, 18 Oct 2010 17:11:33 +1100 Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o9I6GLN2761884 for ; Mon, 18 Oct 2010 17:16:21 +1100 Received: from d23av01.au.ibm.com (loopback [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o9I6GLk7027330 for ; Mon, 18 Oct 2010 17:16:21 +1100 Received: from zephyr ([9.124.35.82]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o9I6GJVt027306; Mon, 18 Oct 2010 17:16:20 +1100 Date: Mon, 18 Oct 2010 11:44:33 +0530 From: Prerna Saxena To: qemu-devel Message-ID: <20101018114433.56271fe4@zephyr> In-Reply-To: <20101018113655.09b6a48d@zephyr> References: <20101018113655.09b6a48d@zephyr> Organization: IBM X-Mailer: Claws Mail 3.7.6 (GTK+ 2.20.1; i386-redhat-linux-gnu) Mime-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Anthony Liguori , Hajnoczi , Mahesh , Stefan, Luiz Capitulino , Ananth Narayan Subject: [Qemu-devel] [Tracing][RFC v3 PATCH 1/2] Introduce QMP interfaces : query-trace & query-trace-events X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org [PATCH 1/2] Introduce QMP interfaces : query-trace & query-trace-events. Signed-off-by: Prerna Saxena --- monitor.c | 40 +++++++++++++++++++++++++++++++++++--- simpletrace.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ simpletrace.h | 4 +++ 3 files changed, 98 insertions(+), 4 deletions(-) diff --git a/monitor.c b/monitor.c index fbb678d..41f3477 100644 --- a/monitor.c +++ b/monitor.c @@ -941,15 +941,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) { 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 /** @@ -2606,14 +2618,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 +2762,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 */ }, }; diff --git a/simpletrace.c b/simpletrace.c index f849e42..9d7ec68 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() +{ + 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,27 @@ 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() +{ + 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; +} + static TraceEvent* find_trace_event_by_name(const char *tname) { unsigned int i; diff --git a/simpletrace.h b/simpletrace.h index cf35897..8727728 100644 --- a/simpletrace.h +++ b/simpletrace.h @@ -14,6 +14,8 @@ #include #include #include +#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); +QList* st_print_trace_to_qlist(); +QList* st_print_trace_events_to_qlist(); #endif /* SIMPLETRACE_H */