From edb47ec498a5c00607e8d428668d5141822a9eac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs?= Date: Wed, 31 Aug 2011 20:30:57 +0200 Subject: trace: move backend-specific code into the trace/ directory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lluís Vilanova --- trace/simple.c | 355 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ trace/simple.h | 48 ++++++++ 2 files changed, 403 insertions(+) create mode 100644 trace/simple.c create mode 100644 trace/simple.h (limited to 'trace') diff --git a/trace/simple.c b/trace/simple.c new file mode 100644 index 0000000..de355e9 --- /dev/null +++ b/trace/simple.c @@ -0,0 +1,355 @@ +/* + * Simple trace backend + * + * Copyright IBM, Corp. 2010 + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + */ + +#include +#include +#include +#include +#include +#include +#include "qemu-timer.h" +#include "trace.h" + +/** Trace file header event ID */ +#define HEADER_EVENT_ID (~(uint64_t)0) /* avoids conflicting with TraceEventIDs */ + +/** Trace file magic number */ +#define HEADER_MAGIC 0xf2b177cb0aa429b4ULL + +/** Trace file version number, bump if format changes */ +#define HEADER_VERSION 0 + +/** Records were dropped event ID */ +#define DROPPED_EVENT_ID (~(uint64_t)0 - 1) + +/** Trace record is valid */ +#define TRACE_RECORD_VALID ((uint64_t)1 << 63) + +/** Trace buffer entry */ +typedef struct { + uint64_t event; + uint64_t timestamp_ns; + uint64_t x1; + uint64_t x2; + uint64_t x3; + uint64_t x4; + uint64_t x5; + uint64_t x6; +} TraceRecord; + +enum { + TRACE_BUF_LEN = 4096, + TRACE_BUF_FLUSH_THRESHOLD = TRACE_BUF_LEN / 4, +}; + +/* + * Trace records are written out by a dedicated thread. The thread waits for + * records to become available, writes them out, and then waits again. + */ +static pthread_mutex_t trace_lock = PTHREAD_MUTEX_INITIALIZER; +static pthread_cond_t trace_available_cond = PTHREAD_COND_INITIALIZER; +static pthread_cond_t trace_empty_cond = PTHREAD_COND_INITIALIZER; +static bool trace_available; +static bool trace_writeout_enabled; + +static TraceRecord trace_buf[TRACE_BUF_LEN]; +static unsigned int trace_idx; +static FILE *trace_fp; +static char *trace_file_name = NULL; + +/** + * Read a trace record from the trace buffer + * + * @idx Trace buffer index + * @record Trace record to fill + * + * Returns false if the record is not valid. + */ +static bool get_trace_record(unsigned int idx, TraceRecord *record) +{ + if (!(trace_buf[idx].event & TRACE_RECORD_VALID)) { + return false; + } + + __sync_synchronize(); /* read memory barrier before accessing record */ + + *record = trace_buf[idx]; + record->event &= ~TRACE_RECORD_VALID; + return true; +} + +/** + * Kick writeout thread + * + * @wait Whether to wait for writeout thread to complete + */ +static void flush_trace_file(bool wait) +{ + pthread_mutex_lock(&trace_lock); + trace_available = true; + pthread_cond_signal(&trace_available_cond); + + if (wait) { + pthread_cond_wait(&trace_empty_cond, &trace_lock); + } + + pthread_mutex_unlock(&trace_lock); +} + +static void wait_for_trace_records_available(void) +{ + pthread_mutex_lock(&trace_lock); + while (!(trace_available && trace_writeout_enabled)) { + pthread_cond_signal(&trace_empty_cond); + pthread_cond_wait(&trace_available_cond, &trace_lock); + } + trace_available = false; + pthread_mutex_unlock(&trace_lock); +} + +static void *writeout_thread(void *opaque) +{ + TraceRecord record; + unsigned int writeout_idx = 0; + unsigned int num_available, idx; + size_t unused __attribute__ ((unused)); + + for (;;) { + wait_for_trace_records_available(); + + num_available = trace_idx - writeout_idx; + if (num_available > TRACE_BUF_LEN) { + record = (TraceRecord){ + .event = DROPPED_EVENT_ID, + .x1 = num_available, + }; + unused = fwrite(&record, sizeof(record), 1, trace_fp); + writeout_idx += num_available; + } + + idx = writeout_idx % TRACE_BUF_LEN; + while (get_trace_record(idx, &record)) { + trace_buf[idx].event = 0; /* clear valid bit */ + unused = fwrite(&record, sizeof(record), 1, trace_fp); + idx = ++writeout_idx % TRACE_BUF_LEN; + } + + fflush(trace_fp); + } + return NULL; +} + +static void trace(TraceEventID event, uint64_t x1, uint64_t x2, uint64_t x3, + uint64_t x4, uint64_t x5, uint64_t x6) +{ + unsigned int idx; + uint64_t timestamp; + + if (!trace_list[event].state) { + return; + } + + timestamp = get_clock(); + + idx = __sync_fetch_and_add(&trace_idx, 1) % TRACE_BUF_LEN; + trace_buf[idx] = (TraceRecord){ + .event = event, + .timestamp_ns = timestamp, + .x1 = x1, + .x2 = x2, + .x3 = x3, + .x4 = x4, + .x5 = x5, + .x6 = x6, + }; + __sync_synchronize(); /* write barrier before marking as valid */ + trace_buf[idx].event |= TRACE_RECORD_VALID; + + if ((idx + 1) % TRACE_BUF_FLUSH_THRESHOLD == 0) { + flush_trace_file(false); + } +} + +void trace0(TraceEventID event) +{ + trace(event, 0, 0, 0, 0, 0, 0); +} + +void trace1(TraceEventID event, uint64_t x1) +{ + trace(event, x1, 0, 0, 0, 0, 0); +} + +void trace2(TraceEventID event, uint64_t x1, uint64_t x2) +{ + trace(event, x1, x2, 0, 0, 0, 0); +} + +void trace3(TraceEventID event, uint64_t x1, uint64_t x2, uint64_t x3) +{ + trace(event, x1, x2, x3, 0, 0, 0); +} + +void trace4(TraceEventID event, uint64_t x1, uint64_t x2, uint64_t x3, uint64_t x4) +{ + trace(event, x1, x2, x3, x4, 0, 0); +} + +void trace5(TraceEventID event, uint64_t x1, uint64_t x2, uint64_t x3, uint64_t x4, uint64_t x5) +{ + trace(event, x1, x2, x3, x4, x5, 0); +} + +void trace6(TraceEventID event, uint64_t x1, uint64_t x2, uint64_t x3, uint64_t x4, uint64_t x5, uint64_t x6) +{ + trace(event, x1, x2, x3, x4, x5, x6); +} + +void st_set_trace_file_enabled(bool enable) +{ + if (enable == !!trace_fp) { + return; /* no change */ + } + + /* Halt trace writeout */ + flush_trace_file(true); + trace_writeout_enabled = false; + flush_trace_file(true); + + if (enable) { + static const TraceRecord header = { + .event = HEADER_EVENT_ID, + .timestamp_ns = HEADER_MAGIC, + .x1 = HEADER_VERSION, + }; + + trace_fp = fopen(trace_file_name, "w"); + if (!trace_fp) { + return; + } + + if (fwrite(&header, sizeof header, 1, trace_fp) != 1) { + fclose(trace_fp); + trace_fp = NULL; + return; + } + + /* Resume trace writeout */ + trace_writeout_enabled = true; + flush_trace_file(false); + } else { + fclose(trace_fp); + trace_fp = NULL; + } +} + +/** + * Set the name of a trace file + * + * @file The trace file name or NULL for the default name- set at + * config time + */ +bool st_set_trace_file(const char *file) +{ + st_set_trace_file_enabled(false); + + free(trace_file_name); + + if (!file) { + if (asprintf(&trace_file_name, CONFIG_TRACE_FILE, getpid()) < 0) { + trace_file_name = NULL; + return false; + } + } else { + if (asprintf(&trace_file_name, "%s", file) < 0) { + trace_file_name = NULL; + return false; + } + } + + st_set_trace_file_enabled(true); + return true; +} + +void st_print_trace_file_status(FILE *stream, int (*stream_printf)(FILE *stream, const char *fmt, ...)) +{ + stream_printf(stream, "Trace file \"%s\" %s.\n", + trace_file_name, trace_fp ? "on" : "off"); +} + +void st_print_trace(FILE *stream, int (*stream_printf)(FILE *stream, const char *fmt, ...)) +{ + unsigned int i; + + for (i = 0; i < TRACE_BUF_LEN; i++) { + TraceRecord record; + + if (!get_trace_record(i, &record)) { + continue; + } + stream_printf(stream, "Event %" PRIu64 " : %" PRIx64 " %" PRIx64 + " %" PRIx64 " %" PRIx64 " %" PRIx64 " %" PRIx64 "\n", + record.event, record.x1, record.x2, + record.x3, record.x4, record.x5, + record.x6); + } +} + +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); + } +} + +bool st_change_trace_event_state(const char *name, bool enabled) +{ + unsigned int i; + + for (i = 0; i < NR_TRACE_EVENTS; i++) { + if (!strcmp(trace_list[i].tp_name, name)) { + trace_list[i].state = enabled; + return true; + } + } + return false; +} + +void st_flush_trace_buffer(void) +{ + flush_trace_file(true); +} + +bool st_init(const char *file) +{ + pthread_t thread; + pthread_attr_t attr; + sigset_t set, oldset; + int ret; + + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + + sigfillset(&set); + pthread_sigmask(SIG_SETMASK, &set, &oldset); + ret = pthread_create(&thread, &attr, writeout_thread, NULL); + pthread_sigmask(SIG_SETMASK, &oldset, NULL); + + if (ret != 0) { + return false; + } + + atexit(st_flush_trace_buffer); + st_set_trace_file(file); + return true; +} diff --git a/trace/simple.h b/trace/simple.h new file mode 100644 index 0000000..77633ab --- /dev/null +++ b/trace/simple.h @@ -0,0 +1,48 @@ +/* + * Simple trace backend + * + * Copyright IBM, Corp. 2010 + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + */ + +#ifndef TRACE_SIMPLE_H +#define TRACE_SIMPLE_H + +#include +#include +#include + +#ifdef CONFIG_TRACE_SIMPLE +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); +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, fprintf_function stream_printf); +void st_print_trace_events(FILE *stream, fprintf_function stream_printf); +bool st_change_trace_event_state(const char *tname, bool tstate); +void st_print_trace_file_status(FILE *stream, fprintf_function stream_printf); +void st_set_trace_file_enabled(bool enable); +bool st_set_trace_file(const char *file); +void st_flush_trace_buffer(void); +bool st_init(const char *file); +#else +static inline bool st_init(const char *file) +{ + return true; +} +#endif /* !CONFIG_TRACE_SIMPLE */ + +#endif /* TRACE_SIMPLE_H */ -- cgit v1.1 From e4858974ec36afd8a6b3a9e2b0ad8f357f28efc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs?= Date: Wed, 31 Aug 2011 20:31:03 +0200 Subject: trace: avoid conditional code compilation during option parsing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A default implementation for backend-specific routines is provided in "trace/default.c", which backends can override by setting "trace_default=no" in "configure". Signed-off-by: Lluís Vilanova --- trace/control.h | 24 ++++++++++++++++++++++++ trace/default.c | 21 +++++++++++++++++++++ trace/simple.c | 10 ++++++---- trace/simple.h | 8 -------- 4 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 trace/control.h create mode 100644 trace/default.c (limited to 'trace') diff --git a/trace/control.h b/trace/control.h new file mode 100644 index 0000000..bb54339 --- /dev/null +++ b/trace/control.h @@ -0,0 +1,24 @@ +/* + * Interface for configuring and controlling the state of tracing events. + * + * Copyright (C) 2011 Lluís Vilanova + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + */ + +#ifndef TRACE_CONTROL_H +#define TRACE_CONTROL_H + +#include + + +/** Initialize the tracing backend. + * + * @file Name of trace output file; may be NULL. + * Corresponds to commandline option "-trace file=...". + * @return Whether the backend could be successfully initialized. + */ +bool trace_backend_init(const char *file); + +#endif /* TRACE_CONTROL_H */ diff --git a/trace/default.c b/trace/default.c new file mode 100644 index 0000000..42fdb6b --- /dev/null +++ b/trace/default.c @@ -0,0 +1,21 @@ +/* + * Default implementation for backend initialization from commandline. + * + * Copyright (C) 2011 Lluís Vilanova + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + */ + +#include "trace/control.h" + + +bool trace_backend_init(const char *file) +{ + if (file) { + fprintf(stderr, "error: -trace file=...: " + "option not supported by the selected tracing backend\n"); + return false; + } + return true; +} diff --git a/trace/simple.c b/trace/simple.c index de355e9..369e860 100644 --- a/trace/simple.c +++ b/trace/simple.c @@ -16,6 +16,7 @@ #include #include "qemu-timer.h" #include "trace.h" +#include "trace/control.h" /** Trace file header event ID */ #define HEADER_EVENT_ID (~(uint64_t)0) /* avoids conflicting with TraceEventIDs */ @@ -330,7 +331,7 @@ void st_flush_trace_buffer(void) flush_trace_file(true); } -bool st_init(const char *file) +bool trace_backend_init(const char *file) { pthread_t thread; pthread_attr_t attr; @@ -346,10 +347,11 @@ bool st_init(const char *file) pthread_sigmask(SIG_SETMASK, &oldset, NULL); if (ret != 0) { - return false; + fprintf(stderr, "warning: unable to initialize simple trace backend\n"); + } else { + atexit(st_flush_trace_buffer); + st_set_trace_file(file); } - atexit(st_flush_trace_buffer); - st_set_trace_file(file); return true; } diff --git a/trace/simple.h b/trace/simple.h index 77633ab..08b9a52 100644 --- a/trace/simple.h +++ b/trace/simple.h @@ -15,7 +15,6 @@ #include #include -#ifdef CONFIG_TRACE_SIMPLE typedef uint64_t TraceEventID; typedef struct { @@ -37,12 +36,5 @@ void st_print_trace_file_status(FILE *stream, fprintf_function stream_printf); void st_set_trace_file_enabled(bool enable); bool st_set_trace_file(const char *file); void st_flush_trace_buffer(void); -bool st_init(const char *file); -#else -static inline bool st_init(const char *file) -{ - return true; -} -#endif /* !CONFIG_TRACE_SIMPLE */ #endif /* TRACE_SIMPLE_H */ -- cgit v1.1 From fc764105397fa55e7c03f42a6d019063ec0cad00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs?= Date: Wed, 31 Aug 2011 20:31:18 +0200 Subject: trace: separate trace event control and query routines from the simple backend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Generalize the 'st_print_trace_events' and 'st_change_trace_event_state' into backend-specific 'trace_print_events' and 'trace_event_set_state' (respectively) in the "trace/control.h" file. Signed-off-by: Lluís Vilanova --- trace/control.h | 11 ++++++++++- trace/default.c | 15 +++++++++++++++ trace/simple.c | 16 ++++++++-------- trace/simple.h | 2 -- 4 files changed, 33 insertions(+), 11 deletions(-) (limited to 'trace') diff --git a/trace/control.h b/trace/control.h index bb54339..c99b4d5 100644 --- a/trace/control.h +++ b/trace/control.h @@ -10,7 +10,16 @@ #ifndef TRACE_CONTROL_H #define TRACE_CONTROL_H -#include +#include "qemu-common.h" + + +/** Print the state of all events. */ +void trace_print_events(FILE *stream, fprintf_function stream_printf); +/** Set the state of an event. + * + * @return Whether the state changed. + */ +bool trace_event_set_state(const char *name, bool state); /** Initialize the tracing backend. diff --git a/trace/default.c b/trace/default.c index 42fdb6b..3573d5b 100644 --- a/trace/default.c +++ b/trace/default.c @@ -10,6 +10,21 @@ #include "trace/control.h" +void trace_print_events(FILE *stream, fprintf_function stream_printf) +{ + fprintf(stderr, "warning: " + "cannot print the trace events with the current backend\n"); + stream_printf(stream, "error: " + "operation not supported with the current backend\n"); +} + +bool trace_event_set_state(const char *name, bool state) +{ + fprintf(stderr, "warning: " + "cannot set the state of a trace event with the current backend\n"); + return false; +} + bool trace_backend_init(const char *file) { if (file) { diff --git a/trace/simple.c b/trace/simple.c index 369e860..70689e9 100644 --- a/trace/simple.c +++ b/trace/simple.c @@ -303,7 +303,12 @@ void st_print_trace(FILE *stream, int (*stream_printf)(FILE *stream, const char } } -void st_print_trace_events(FILE *stream, int (*stream_printf)(FILE *stream, const char *fmt, ...)) +void st_flush_trace_buffer(void) +{ + flush_trace_file(true); +} + +void trace_print_events(FILE *stream, fprintf_function stream_printf) { unsigned int i; @@ -313,24 +318,19 @@ void st_print_trace_events(FILE *stream, int (*stream_printf)(FILE *stream, cons } } -bool st_change_trace_event_state(const char *name, bool enabled) +bool trace_event_set_state(const char *name, bool state) { unsigned int i; for (i = 0; i < NR_TRACE_EVENTS; i++) { if (!strcmp(trace_list[i].tp_name, name)) { - trace_list[i].state = enabled; + trace_list[i].state = state; return true; } } return false; } -void st_flush_trace_buffer(void) -{ - flush_trace_file(true); -} - bool trace_backend_init(const char *file) { pthread_t thread; diff --git a/trace/simple.h b/trace/simple.h index 08b9a52..466e75b 100644 --- a/trace/simple.h +++ b/trace/simple.h @@ -30,8 +30,6 @@ void trace4(TraceEventID event, uint64_t x1, uint64_t x2, uint64_t x3, uint64_t 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, fprintf_function stream_printf); -void st_print_trace_events(FILE *stream, fprintf_function stream_printf); -bool st_change_trace_event_state(const char *tname, bool tstate); void st_print_trace_file_status(FILE *stream, fprintf_function stream_printf); void st_set_trace_file_enabled(bool enable); bool st_set_trace_file(const char *file); -- cgit v1.1 From 23d15e860b33819ad76092fbb32577542fe0c44d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs?= Date: Wed, 31 Aug 2011 20:31:31 +0200 Subject: trace: add "-trace events" argument to control initial state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The "-trace events" argument can be used to provide a file with a list of trace event names that will be enabled prior to starting execution, thus providing early tracing. This saves the user from manually toggling event states through the monitor interface or whichever backend-specific interface. Signed-off-by: Lluís Vilanova --- trace/control.c | 42 ++++++++++++++++++++++++++++++++++++++++++ trace/control.h | 14 +++++++++++--- trace/default.c | 7 ++++++- trace/simple.c | 3 ++- 4 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 trace/control.c (limited to 'trace') diff --git a/trace/control.c b/trace/control.c new file mode 100644 index 0000000..4c5527d --- /dev/null +++ b/trace/control.c @@ -0,0 +1,42 @@ +/* + * Interface for configuring and controlling the state of tracing events. + * + * Copyright (C) 2011 Lluís Vilanova + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + */ + +#include "trace/control.h" + + +void trace_backend_init_events(const char *fname) +{ + if (fname == NULL) { + return; + } + + FILE *fp = fopen(fname, "r"); + if (!fp) { + fprintf(stderr, "error: could not open trace events file '%s': %s\n", + fname, strerror(errno)); + exit(1); + } + char line_buf[1024]; + while (fgets(line_buf, sizeof(line_buf), fp)) { + size_t len = strlen(line_buf); + if (len > 1) { /* skip empty lines */ + line_buf[len - 1] = '\0'; + if (!trace_event_set_state(line_buf, true)) { + fprintf(stderr, + "error: trace event '%s' does not exist\n", line_buf); + exit(1); + } + } + } + if (fclose(fp) != 0) { + fprintf(stderr, "error: closing file '%s': %s\n", + fname, strerror(errno)); + exit(1); + } +} diff --git a/trace/control.h b/trace/control.h index c99b4d5..2acaa42 100644 --- a/trace/control.h +++ b/trace/control.h @@ -24,10 +24,18 @@ bool trace_event_set_state(const char *name, bool state); /** Initialize the tracing backend. * - * @file Name of trace output file; may be NULL. - * Corresponds to commandline option "-trace file=...". + * @events Name of file with events to be enabled at startup; may be NULL. + * Corresponds to commandline option "-trace events=...". + * @file Name of trace output file; may be NULL. + * Corresponds to commandline option "-trace file=...". * @return Whether the backend could be successfully initialized. */ -bool trace_backend_init(const char *file); +bool trace_backend_init(const char *events, const char *file); + +/** Generic function to initialize the state of events. + * + * @fname Name of file with events to enable; may be NULL. + */ +void trace_backend_init_events(const char *fname); #endif /* TRACE_CONTROL_H */ diff --git a/trace/default.c b/trace/default.c index 3573d5b..c9b27a2 100644 --- a/trace/default.c +++ b/trace/default.c @@ -25,8 +25,13 @@ bool trace_event_set_state(const char *name, bool state) return false; } -bool trace_backend_init(const char *file) +bool trace_backend_init(const char *events, const char *file) { + if (events) { + fprintf(stderr, "error: -trace events=...: " + "option not supported by the selected tracing backend\n"); + return false; + } if (file) { fprintf(stderr, "error: -trace file=...: " "option not supported by the selected tracing backend\n"); diff --git a/trace/simple.c b/trace/simple.c index 70689e9..a609368 100644 --- a/trace/simple.c +++ b/trace/simple.c @@ -331,7 +331,7 @@ bool trace_event_set_state(const char *name, bool state) return false; } -bool trace_backend_init(const char *file) +bool trace_backend_init(const char *events, const char *file) { pthread_t thread; pthread_attr_t attr; @@ -350,6 +350,7 @@ bool trace_backend_init(const char *file) fprintf(stderr, "warning: unable to initialize simple trace backend\n"); } else { atexit(st_flush_trace_buffer); + trace_backend_init_events(events); st_set_trace_file(file); } -- cgit v1.1 From 9a82b6a590bd7c845ab9754b34b33ffee982ccb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs?= Date: Wed, 31 Aug 2011 20:31:51 +0200 Subject: trace: [stderr] add support for dynamically enabling/disabling events MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Uses the generic interface provided in "trace/control.h" in order to provide a programmatic interface as well as command line and monitor controls. Signed-off-by: Fabien Chouteau Signed-off-by: Lluís Vilanova --- trace/stderr.c | 37 +++++++++++++++++++++++++++++++++++++ trace/stderr.h | 11 +++++++++++ 2 files changed, 48 insertions(+) create mode 100644 trace/stderr.c create mode 100644 trace/stderr.h (limited to 'trace') diff --git a/trace/stderr.c b/trace/stderr.c new file mode 100644 index 0000000..7107c4a --- /dev/null +++ b/trace/stderr.c @@ -0,0 +1,37 @@ +#include "trace.h" +#include "trace/control.h" + + +void trace_print_events(FILE *stream, fprintf_function stream_printf) +{ + 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); + } +} + +bool trace_event_set_state(const char *name, bool state) +{ + unsigned int i; + + for (i = 0; i < NR_TRACE_EVENTS; i++) { + if (!strcmp(trace_list[i].tp_name, name)) { + trace_list[i].state = state; + return true; + } + } + return false; +} + +bool trace_backend_init(const char *events, const char *file) +{ + if (file) { + fprintf(stderr, "error: -trace file=...: " + "option not supported by the selected tracing backend\n"); + return false; + } + trace_backend_init_events(events); + return true; +} diff --git a/trace/stderr.h b/trace/stderr.h new file mode 100644 index 0000000..d575b61 --- /dev/null +++ b/trace/stderr.h @@ -0,0 +1,11 @@ +#ifndef TRACE_STDERR_H +#define TRACE_STDERR_H + +typedef uint64_t TraceEventID; + +typedef struct { + const char *tp_name; + bool state; +} TraceEvent; + +#endif /* ! TRACE_STDERR_H */ -- cgit v1.1