From patchwork Mon Sep 6 15:14:00 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 63933 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 25228B70D3 for ; Tue, 7 Sep 2010 01:18:56 +1000 (EST) Received: from localhost ([127.0.0.1]:52248 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OsdT7-0006hw-TC for incoming@patchwork.ozlabs.org; Mon, 06 Sep 2010 11:18:50 -0400 Received: from [140.186.70.92] (port=47978 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OsdPX-00057R-I6 for qemu-devel@nongnu.org; Mon, 06 Sep 2010 11:15:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OsdPN-0003zC-WD for qemu-devel@nongnu.org; Mon, 06 Sep 2010 11:15:07 -0400 Received: from mtagate5.de.ibm.com ([195.212.17.165]:55763) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OsdPN-0003xl-HA for qemu-devel@nongnu.org; Mon, 06 Sep 2010 11:14:57 -0400 Received: from d12nrmr1607.megacenter.de.ibm.com (d12nrmr1607.megacenter.de.ibm.com [9.149.167.49]) by mtagate5.de.ibm.com (8.13.1/8.13.1) with ESMTP id o86FEtvv005340 for ; Mon, 6 Sep 2010 15:14:55 GMT Received: from d12av02.megacenter.de.ibm.com (d12av02.megacenter.de.ibm.com [9.149.165.228]) by d12nrmr1607.megacenter.de.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o86FEoJ93551232 for ; Mon, 6 Sep 2010 17:14:55 +0200 Received: from d12av02.megacenter.de.ibm.com (loopback [127.0.0.1]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id o86FEoSC017969 for ; Mon, 6 Sep 2010 17:14:50 +0200 Received: from stefan-thinkpad.manchester-maybrook.uk.ibm.com (dyn-9-174-219-60.manchester-maybrook.uk.ibm.com [9.174.219.60]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id o86FEmNZ017891; Mon, 6 Sep 2010 17:14:49 +0200 From: Stefan Hajnoczi To: Date: Mon, 6 Sep 2010 16:14:00 +0100 Message-Id: <1283786051-29530-4-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1283786051-29530-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1283786051-29530-1-git-send-email-stefanha@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Blue Swirl , Anthony Liguori , "Michael S. Tsirkin" , Stefan Hajnoczi , Prerna Saxena Subject: [Qemu-devel] [PATCH 03/14] trace: Support for dynamically enabling/disabling 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 From: Prerna Saxena This patch adds support for dynamically enabling/disabling of trace events. This is done by internally maintaining each trace event's state, and permitting logging of data from a trace event only if it is in an 'active' state. Monitor commands added : 1) info trace-events : to view all available trace events and their state. 2) trace-event NAME on|off : to enable/disable data logging from a given trace event. Eg, trace-event paio_submit off disables logging of data when paio_submit is hit. By default, all trace-events are disabled. One can enable desired trace-events via the monitor. Signed-off-by: Prerna Saxena Signed-off-by: Stefan Hajnoczi trace: Monitor command 'info trace' Monitor command 'info trace' to display contents of trace buffer Signed-off-by: Prerna Saxena Signed-off-by: Stefan Hajnoczi trace: Remove monitor.h dependency from simpletrace User-mode targets don't have a monitor so the simple trace backend currently does not build on those targets. This patch abstracts the monitor printing interface so there is no direct coupling between simpletrace and the monitor. Signed-off-by: Stefan Hajnoczi --- configure | 3 +++ monitor.c | 40 ++++++++++++++++++++++++++++++++++++++++ qemu-monitor.hx | 25 +++++++++++++++++++++++++ simpletrace.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ simpletrace.h | 10 ++++++++++ tracetool | 24 ++++++++++++++++++++---- 6 files changed, 149 insertions(+), 4 deletions(-) diff --git a/configure b/configure index 6729dbe..5afb3b5 100755 --- a/configure +++ b/configure @@ -2468,6 +2468,9 @@ bsd) esac echo "TRACE_BACKEND=$trace_backend" >> $config_host_mak +if test "$trace_backend" = "simple"; then + echo "CONFIG_SIMPLE_TRACE=y" >> $config_host_mak +fi echo "TOOLS=$tools" >> $config_host_mak echo "ROMS=$roms" >> $config_host_mak echo "MAKE=$make" >> $config_host_mak diff --git a/monitor.c b/monitor.c index e27f8d8..0e69bc8 100644 --- a/monitor.c +++ b/monitor.c @@ -56,6 +56,9 @@ #include "json-parser.h" #include "osdep.h" #include "exec-all.h" +#ifdef CONFIG_SIMPLE_TRACE +#include "trace.h" +#endif //#define DEBUG //#define DEBUG_COMPLETION @@ -539,6 +542,15 @@ static void do_help_cmd(Monitor *mon, const QDict *qdict) help_cmd(mon, qdict_get_try_str(qdict, "name")); } +#ifdef CONFIG_SIMPLE_TRACE +static void do_change_trace_event_state(Monitor *mon, const QDict *qdict) +{ + const char *tp_name = qdict_get_str(qdict, "name"); + bool new_state = qdict_get_bool(qdict, "option"); + st_change_trace_event_state(tp_name, new_state); +} +#endif + static void user_monitor_complete(void *opaque, QObject *ret_data) { MonitorCompletionData *data = (MonitorCompletionData *)opaque; @@ -938,6 +950,18 @@ static void do_info_cpu_stats(Monitor *mon) } #endif +#if defined(CONFIG_SIMPLE_TRACE) +static void do_info_trace(Monitor *mon) +{ + st_print_trace((FILE *)mon, &monitor_fprintf); +} + +static void do_info_trace_events(Monitor *mon) +{ + st_print_trace_events((FILE *)mon, &monitor_fprintf); +} +#endif + /** * do_quit(): Quit QEMU execution */ @@ -2594,6 +2618,22 @@ static const mon_cmd_t info_cmds[] = { .help = "show roms", .mhandler.info = do_info_roms, }, +#if defined(CONFIG_SIMPLE_TRACE) + { + .name = "trace", + .args_type = "", + .params = "", + .help = "show current contents of trace buffer", + .mhandler.info = do_info_trace, + }, + { + .name = "trace-events", + .args_type = "", + .params = "", + .help = "show available trace-events & their state", + .mhandler.info = do_info_trace_events, + }, +#endif { .name = NULL, }, diff --git a/qemu-monitor.hx b/qemu-monitor.hx index 5c1da33..c264c7d 100644 --- a/qemu-monitor.hx +++ b/qemu-monitor.hx @@ -281,6 +281,22 @@ STEXI Output logs to @var{filename}. ETEXI +#ifdef CONFIG_SIMPLE_TRACE + { + .name = "trace-event", + .args_type = "name:s,option:b", + .params = "name on|off", + .help = "changes status of a specific trace event", + .mhandler.cmd = do_change_trace_event_state, + }, + +STEXI +@item trace-event +@findex trace-event +changes status of a trace event +ETEXI +#endif + { .name = "log", .args_type = "items:s", @@ -2529,6 +2545,15 @@ show roms @end table ETEXI +#ifdef CONFIG_SIMPLE_TRACE +STEXI +@item info trace +show contents of trace buffer +@item info trace-events +show available trace events and their state +ETEXI +#endif + HXCOMM DO NOT add new commands after 'info', move your addition before it! STEXI diff --git a/simpletrace.c b/simpletrace.c index 4777308..688959a 100644 --- a/simpletrace.c +++ b/simpletrace.c @@ -101,6 +101,10 @@ static void trace(TraceEventID event, uint64_t x1, uint64_t x2, uint64_t x3, */ clock_gettime(CLOCK_MONOTONIC, &ts); + if (!trace_list[event].state) { + return; + } + rec->event = event; rec->timestamp_ns = ts.tv_sec * 1000000000LL + ts.tv_nsec; rec->x1 = x1; @@ -157,3 +161,50 @@ static void __attribute__((constructor)) st_init(void) { atexit(st_flush_trace_buffer); } + +void st_print_trace(FILE *stream, int (*stream_printf)(FILE *stream, const char *fmt, ...)) +{ + unsigned int i; + + for (i = 0; i < trace_idx; i++) { + stream_printf(stream, "Event %lu : %lx %lx %lx %lx %lx\n", + trace_buf[i].event, trace_buf[i].x1, trace_buf[i].x2, + trace_buf[i].x3, trace_buf[i].x4, trace_buf[i].x5); + } +} + +void st_print_trace_events(FILE *stream, int (*stream_printf)(FILE *stream, const char *fmt, ...)) +{ + unsigned int i; + + for (i = 0; i < NR_TRACE_EVENTS; i++) { + stream_printf(stream, "%s [Event ID %u] : state %u\n", + trace_list[i].tp_name, i, trace_list[i].state); + } +} + +static TraceEvent* find_trace_event_by_name(const char *tname) +{ + unsigned int i; + + if (!tname) { + return NULL; + } + + for (i = 0; i < NR_TRACE_EVENTS; i++) { + if (!strcmp(trace_list[i].tp_name, tname)) { + return &trace_list[i]; + } + } + return NULL; /* indicates end of list reached without a match */ +} + +void st_change_trace_event_state(const char *tname, bool tstate) +{ + TraceEvent *tp; + + tp = find_trace_event_by_name(tname); + if (tp) { + tp->state = tstate; + } +} diff --git a/simpletrace.h b/simpletrace.h index 7d0661b..b0161d1 100644 --- a/simpletrace.h +++ b/simpletrace.h @@ -12,9 +12,16 @@ #define SIMPLETRACE_H #include +#include +#include typedef uint64_t TraceEventID; +typedef struct { + const char *tp_name; + bool state; +} TraceEvent; + void trace0(TraceEventID event); void trace1(TraceEventID event, uint64_t x1); void trace2(TraceEventID event, uint64_t x1, uint64_t x2); @@ -22,5 +29,8 @@ void trace3(TraceEventID event, uint64_t x1, uint64_t x2, uint64_t x3); void trace4(TraceEventID event, uint64_t x1, uint64_t x2, uint64_t x3, uint64_t x4); void trace5(TraceEventID event, uint64_t x1, uint64_t x2, uint64_t x3, uint64_t x4, uint64_t x5); void trace6(TraceEventID event, uint64_t x1, uint64_t x2, uint64_t x3, uint64_t x4, uint64_t x5, uint64_t x6); +void st_print_trace(FILE *stream, int (*stream_printf)(FILE *stream, const char *fmt, ...)); +void st_print_trace_events(FILE *stream, int (*stream_printf)(FILE *stream, const char *fmt, ...)); +void st_change_trace_event_state(const char *tname, bool tstate); #endif /* SIMPLETRACE_H */ diff --git a/tracetool b/tracetool index 19b1659..2e2e37d 100755 --- a/tracetool +++ b/tracetool @@ -169,22 +169,38 @@ EOF linetoh_end_simple() { - return + cat <