From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=41267 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P6KfG-0005GB-0n for qemu-devel@nongnu.org; Thu, 14 Oct 2010 06:03:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P6KfE-0000SH-J6 for qemu-devel@nongnu.org; Thu, 14 Oct 2010 06:03:57 -0400 Received: from mtagate1.uk.ibm.com ([194.196.100.161]:46883) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P6KfE-0000Rm-8T for qemu-devel@nongnu.org; Thu, 14 Oct 2010 06:03:56 -0400 Received: from d06nrmr1806.portsmouth.uk.ibm.com (d06nrmr1806.portsmouth.uk.ibm.com [9.149.39.193]) by mtagate1.uk.ibm.com (8.13.1/8.13.1) with ESMTP id o9EA3snY011488 for ; Thu, 14 Oct 2010 10:03:54 GMT Received: from d06av03.portsmouth.uk.ibm.com (d06av03.portsmouth.uk.ibm.com [9.149.37.213]) by d06nrmr1806.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o9EA3svt3530800 for ; Thu, 14 Oct 2010 11:03:54 +0100 Received: from d06av03.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av03.portsmouth.uk.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id o9EA3rmW002104 for ; Thu, 14 Oct 2010 11:03:53 +0100 Date: Thu, 14 Oct 2010 11:03:53 +0100 From: Stefan Hajnoczi Message-ID: <20101014100352.GA3488@stefan-thinkpad.transitives.com> References: <20101014112143.01363808@zephyr> <20101014112604.0a8f2083@zephyr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20101014112604.0a8f2083@zephyr> Subject: [Qemu-devel] Re: [Tracing] [RFC PATCH 1/2] : Introduce 'query-trace' & 'query-trace-events' interfaces List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Prerna Saxena Cc: Mahesh , Ananth Narayan , qemu-devel , Luiz Capitulino On Thu, Oct 14, 2010 at 11:26:04AM +0530, Prerna Saxena wrote: > [PATCH 1/2] Introduce QMP interfaces : query-trace & query-trace-events > > > Signed-off-by: Prerna Saxena > --- > monitor.c | 46 ++++++++++++++++++++++++++++++++++++++++++---- > simpletrace.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ > simpletrace.h | 2 ++ > 3 files changed, 98 insertions(+), 4 deletions(-) > > diff --git a/monitor.c b/monitor.c > index fbb678d..7a150ae 100644 > --- a/monitor.c > +++ b/monitor.c > @@ -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 */ }, > }; > > diff --git a/simpletrace.c b/simpletrace.c > index f849e42..d1f66b4 100644 > --- a/simpletrace.c > +++ b/simpletrace.c > @@ -220,6 +220,39 @@ void st_print_trace(FILE *stream, int (*stream_printf)(FILE *stream, const char > } > } > > +void st_print_trace_to_qlist(QList **tlist) > +{ > + QObject *data; > + unsigned int i; > + > + if (!tlist || *tlist ) > + return; This silences bugs. If you want to check these please use asserts. > + > + /* NOTE : This assumes trace_list hasnt already been allocated with a QList. > + * The initialization happens here. > + */ This should be in a doc comment for this function to make it clear that tlist will be allocated a new list. > + *tlist = qlist_new(); > + > + for (i = 0; i < trace_idx; i++) { > + data = qobject_from_jsonf("{" > + " 'Event': %" PRId64 "," > + " 'arg1': %" PRId64 "," > + " 'arg2': %" PRId64 "," > + " 'arg3': %" PRId64 "," > + " 'arg4': %" PRId64 "," > + " 'arg5': %" PRId64 "," > + " 'arg6': %" PRId64 > + "}", > + 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; Not needed for a void function and not used in QEMU coding style. > +} > + > void st_print_trace_events(FILE *stream, int (*stream_printf)(FILE *stream, const char *fmt, ...)) > { > unsigned int i; > @@ -230,6 +263,27 @@ void st_print_trace_events(FILE *stream, int (*stream_printf)(FILE *stream, cons > } > } > > +void st_print_trace_events_to_qlist(QList **tlist) The same comments apply to this function. > +{ > + QObject *data; > + unsigned int i; > + > + if (!tlist || *tlist ) > + return; > + > + /* NOTE : This assumes trace_list hasnt already been allocated with a QList. > + * The initialization happens here. > + */ > + *tlist = qlist_new(); > + > + for (i = 0; i < NR_TRACE_EVENTS; i++) { > + data = qobject_from_jsonf("{ 'name': %s, 'eventID': %d, 'state': %d }", trace_list[i].tp_name, i, trace_list[i].state); > + qlist_append_obj(*tlist, data); > + } > + > + return; > +} > + > static TraceEvent* find_trace_event_by_name(const char *tname) > { > unsigned int i; > diff --git a/simpletrace.h b/simpletrace.h > index cf35897..9c1f535 100644 > --- a/simpletrace.h > +++ b/simpletrace.h > @@ -14,6 +14,8 @@ > #include > #include > #include > +#include "qdict.h" > +#include "qjson.h" Where are the prototypes for st_print_trace_to_qlist() and st_print_trace_events_to_qlist()? Stefan