summaryrefslogtreecommitdiff
path: root/rts/Trace.h
diff options
context:
space:
mode:
authorSimon Marlow <marlowsd@gmail.com>2009-08-29 09:47:27 +0000
committerSimon Marlow <marlowsd@gmail.com>2009-08-29 09:47:27 +0000
commita5288c551349a0adab0d931a429b10a096d9444d (patch)
tree245dd2dfd2b4e23f3fc8ae474b709289b60e5f15 /rts/Trace.h
parentc51229b2bfd3b1a61d3966db894210ef848f0a6d (diff)
downloadhaskell-a5288c551349a0adab0d931a429b10a096d9444d.tar.gz
Unify event logging and debug tracing.
- tracing facilities are now enabled with -DTRACING, and -DDEBUG additionally enables debug-tracing. -DEVENTLOG has been removed. - -debug now implies -eventlog - events can be printed to stderr instead of being sent to the binary .eventlog file by adding +RTS -v (which is implied by the +RTS -Dx options). - -Dx debug messages can be sent to the binary .eventlog file by adding +RTS -l. This should help debugging by reducing the impact of debug tracing on execution time. - Various debug messages that duplicated the information in events have been removed.
Diffstat (limited to 'rts/Trace.h')
-rw-r--r--rts/Trace.h172
1 files changed, 134 insertions, 38 deletions
diff --git a/rts/Trace.h b/rts/Trace.h
index 8820075bea..3ab6df456c 100644
--- a/rts/Trace.h
+++ b/rts/Trace.h
@@ -1,61 +1,55 @@
/* -----------------------------------------------------------------------------
*
- * (c) The GHC Team 2006
+ * (c) The GHC Team, 2008-2009
*
- * Debug tracing.
- *
- * This is a layer over RtsMessages, which provides for generating
- * trace messages with timestamps and task IDs attached
- * automatically. Also, multiple classes of messages are supported,
- * which can be enabled separately via RTS flags.
- *
- * All debug trace messages go through here.
+ * Support for fast binary event logging.
*
* ---------------------------------------------------------------------------*/
#ifndef TRACE_H
#define TRACE_H
+#include "rts/EventLogFormat.h"
+#include "Capability.h"
+
#pragma GCC visibility push(hidden)
// -----------------------------------------------------------------------------
-// Tracing functions
+// Posting events
// -----------------------------------------------------------------------------
+INLINE_HEADER void trace (StgWord32 class, char *msg, ...);
+
#ifdef DEBUG
+INLINE_HEADER void debugTrace (StgWord32 class, char *msg, ...);
+#endif
-void initTracing (void);
+INLINE_HEADER void traceSchedEvent (Capability *cap, EventTypeNum tag,
+ StgTSO *tso, StgWord64 other);
-// The simple way:
-void trace (StgWord32 class, const char *str, ...)
- GNUC3_ATTRIBUTE(format (printf, 2, 3));
-
-// The harder way: sometimes we want to generate a trace message that
-// consists of multiple components generated by different functions.
-// So we provide the functionality of trace() split into 3 parts:
-// - traceClass(): a check that the required class is enabled
-// - traceBegin(): print the beginning of the trace message
-// - traceEnd(): complete the trace message (release the lock too).
-//
-INLINE_HEADER rtsBool traceClass (StgWord32 class);
+INLINE_HEADER void traceCap (StgWord32 class, Capability *cap,
+ char *msg, ...);
-void traceBegin (const char *str, ...)
- GNUC3_ATTRIBUTE(format (printf, 1, 2));
+INLINE_HEADER void traceThreadStatus (StgWord32 class, StgTSO *tso);
+INLINE_HEADER rtsBool traceClass (StgWord32 class);
+
+#ifdef DEBUG
+void traceBegin (const char *str, ...);
void traceEnd (void);
+#endif
-#define debugTrace(class, str, ...) trace(class,str, ## __VA_ARGS__)
-// variable arg macros are C99, and supported by gcc.
-#define debugTraceBegin(str, ...) traceBegin(str, ## __VA_ARGS__)
-#define debugTraceEnd() traceEnd()
+// -----------------------------------------------------------------------------
+// EventLog API
+// -----------------------------------------------------------------------------
-#else /* !DEBUG */
+#if defined(TRACING)
-#define debugTrace(class, str, ...) /* nothing */
-#define debugTraceBegin(str, ...) /* nothing */
-#define debugTraceEnd() /* nothing */
+void initTracing (void);
+void endTracing (void);
+void freeTracing (void);
-#endif
+#endif /* TRACING */
// -----------------------------------------------------------------------------
// Message classes, these may be OR-ed together
@@ -77,18 +71,120 @@ void traceEnd (void);
#define DEBUG_linker (1<<12)
#define DEBUG_squeeze (1<<13)
#define DEBUG_hpc (1<<14)
-#define DEBUG_eventlog (1<<15)
+#define DEBUG_sparks (1<<15)
+
+// events
+#define TRACE_sched (1<<16)
// -----------------------------------------------------------------------------
// PRIVATE below here
// -----------------------------------------------------------------------------
+#ifdef TRACING
+
extern StgWord32 classes_enabled;
-INLINE_HEADER rtsBool
-traceClass (StgWord32 class) { return (classes_enabled & class); }
+INLINE_HEADER rtsBool traceClass (StgWord32 class)
+{ return (classes_enabled & class); }
+
+void traceSchedEvent_ (Capability *cap, EventTypeNum tag,
+ StgTSO *tso, StgWord64 other);
+
+/*
+ * Trace an event to the capability's event buffer.
+ */
+INLINE_HEADER void traceSchedEvent(Capability *cap, EventTypeNum tag,
+ StgTSO *tso, StgWord64 other)
+{
+ if (traceClass(TRACE_sched)) {
+ traceSchedEvent_(cap, tag, tso, other);
+ }
+}
+
+void traceCap_(Capability *cap, char *msg, va_list ap);
+
+/*
+ * Trace a log message
+ */
+INLINE_HEADER void traceCap (StgWord32 class, Capability *cap, char *msg, ...)
+{
+ va_list ap;
+ va_start(ap,msg);
+ if (traceClass(class)) {
+ traceCap_(cap, msg, ap);
+ }
+ va_end(ap);
+}
+
+void trace_(char *msg, va_list ap);
+
+/*
+ * Trace a log message
+ */
+INLINE_HEADER void trace (StgWord32 class, char *msg, ...)
+{
+ va_list ap;
+ va_start(ap,msg);
+ if (traceClass(class)) {
+ trace_(msg, ap);
+ }
+ va_end(ap);
+}
-// -----------------------------------------------------------------------------
+#ifdef DEBUG
+INLINE_HEADER void debugTrace (StgWord32 class, char *msg, ...)
+{
+ va_list ap;
+ va_start(ap,msg);
+ if (traceClass(class)) {
+ trace_(msg, ap);
+ }
+ va_end(ap);
+}
+#else
+
+#define debugTrace(class, str, ...) /* nothing */
+// variable arg macros are C99, and supported by gcc.
+
+#endif
+
+void traceThreadStatus_ (StgTSO *tso);
+
+INLINE_HEADER void traceThreadStatus (StgWord32 class, StgTSO *tso)
+{
+ if (traceClass(class)) {
+ traceThreadStatus_(tso);
+ }
+}
+
+#else /* !TRACING */
+
+INLINE_HEADER rtsBool traceClass (StgWord32 class STG_UNUSED)
+{ return rtsFalse; }
+
+INLINE_HEADER void traceSchedEvent (Capability *cap STG_UNUSED,
+ EventTypeNum tag STG_UNUSED,
+ StgTSO *tso STG_UNUSED,
+ StgWord64 other STG_UNUSED)
+{ /* nothing */ }
+
+INLINE_HEADER void traceCap (StgWord32 class STG_UNUSED,
+ Capability *cap STG_UNUSED,
+ char *msg STG_UNUSED, ...)
+{ /* nothing */ }
+
+INLINE_HEADER void trace (StgWord32 class STG_UNUSED,
+ char *msg STG_UNUSED, ...)
+{ /* nothing */ }
+
+#define debugTrace(class, str, ...) /* nothing */
+// variable arg macros are C99, and supported by gcc.
+
+INLINE_HEADER void traceThreadStatus (StgWord32 class STG_UNUSED,
+ StgTSO *tso STG_UNUSED)
+{ /* nothing */ }
+
+#endif /* TRACING */
#pragma GCC visibility pop