From 22890ab5e825601f4c3d5a1a6b4197904e5d1fee Mon Sep 17 00:00:00 2001 From: Prerna Saxena Date: Thu, 24 Jun 2010 17:04:53 +0530 Subject: trace: Support for dynamically enabling/disabling trace events 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 --- simpletrace.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'simpletrace.c') diff --git a/simpletrace.c b/simpletrace.c index 477730871c..688959a9fe 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; + } +} -- cgit v1.2.3