From 0b5538c300a56c3cfb33022840fe0b4968147e7a Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Sat, 26 Feb 2011 18:38:39 +0000 Subject: simpletrace: Thread-safe tracing Trace events outside the global mutex cannot be used with the simple trace backend since it is not thread-safe. There is no check to prevent them being enabled so people sometimes learn this the hard way. This patch restructures the simple trace backend with a ring buffer suitable for multiple concurrent writers. A writeout thread empties the trace buffer when threshold fill levels are reached. Should the writeout thread be unable to keep up with trace generation, records will simply be dropped. Each time events are dropped a special record is written to the trace file indicating how many events were dropped. The event ID is 0xfffffffffffffffe and its signature is dropped(uint32_t count). Signed-off-by: Stefan Hajnoczi --- simpletrace.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'simpletrace.h') diff --git a/simpletrace.h b/simpletrace.h index 2f44ed3c3c..3a5bd9fb9d 100644 --- a/simpletrace.h +++ b/simpletrace.h @@ -15,6 +15,7 @@ #include #include +#ifdef CONFIG_SIMPLE_TRACE typedef uint64_t TraceEventID; typedef struct { @@ -36,5 +37,12 @@ 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); +void st_init(const char *file); +#else +static inline void st_init(const char *file) +{ + /* Do nothing */ +} +#endif /* !CONFIG_SIMPLE_TRACE */ #endif /* SIMPLETRACE_H */ -- cgit v1.2.3-55-g7522