X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=rts%2FTrace.h;h=3ab6df456cf89393a38e8d05ff101e24908e61c0;hb=a5288c551349a0adab0d931a429b10a096d9444d;hp=cf6c1411c0d196118118d4cf0fa95bcfe9f409e6;hpb=b1953bbb1ed3cb16497e5447db7487f0c2d9e41a;p=ghc-hetmet.git diff --git a/rts/Trace.h b/rts/Trace.h index cf6c141..3ab6df4 100644 --- a/rts/Trace.h +++ b/rts/Trace.h @@ -1,58 +1,55 @@ /* ----------------------------------------------------------------------------- * - * (c) The GHC Team 2006 + * (c) The GHC Team, 2008-2009 * - * Debug and performance tracing. - * - * This is a layer over RtsMessages, which provides for generating - * trace messages with timestamps and thread 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. Additionally, we - * generate timestamped trace messages for consumption by profiling - * tools using this API. + * 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 // ----------------------------------------------------------------------------- -void initTracing (void); +INLINE_HEADER void trace (StgWord32 class, char *msg, ...); -// 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); +#ifdef DEBUG +INLINE_HEADER void debugTrace (StgWord32 class, char *msg, ...); +#endif -void traceBegin (const char *str, ...) - GNUC3_ATTRIBUTE(format (printf, 1, 2)); +INLINE_HEADER void traceSchedEvent (Capability *cap, EventTypeNum tag, + StgTSO *tso, StgWord64 other); -void traceEnd (void); +INLINE_HEADER void traceCap (StgWord32 class, Capability *cap, + char *msg, ...); + +INLINE_HEADER void traceThreadStatus (StgWord32 class, StgTSO *tso); + +INLINE_HEADER rtsBool traceClass (StgWord32 class); #ifdef DEBUG -#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() -#else -#define debugTrace(class, str, ...) /* nothing */ -#define debugTraceBegin(str, ...) /* nothing */ -#define debugTraceEnd() /* nothing */ +void traceBegin (const char *str, ...); +void traceEnd (void); #endif +// ----------------------------------------------------------------------------- +// EventLog API +// ----------------------------------------------------------------------------- + +#if defined(TRACING) + +void initTracing (void); +void endTracing (void); +void freeTracing (void); + +#endif /* TRACING */ // ----------------------------------------------------------------------------- // Message classes, these may be OR-ed together @@ -73,51 +70,122 @@ void traceEnd (void); #define DEBUG_par (1<<11) #define DEBUG_linker (1<<12) #define DEBUG_squeeze (1<<13) +#define DEBUG_hpc (1<<14) +#define DEBUG_sparks (1<<15) -// PAR debugging flags, set with +RTS -qD -#define PAR_DEBUG_verbose (1<<14) -#define PAR_DEBUG_bq (1<<15) -#define PAR_DEBUG_schedule (1<<16) -#define PAR_DEBUG_free (1<<17) -#define PAR_DEBUG_resume (1<<18) -#define PAR_DEBUG_weight (1<<19) -#define PAR_DEBUG_fetch (1<<21) -#define PAR_DEBUG_fish (1<<22) -#define PAR_DEBUG_tables (1<<23) -#define PAR_DEBUG_packet (1<<24) -#define PAR_DEBUG_pack (1<<25) -#define PAR_DEBUG_paranoia (1<<26) - -// GRAN and PAR don't coexist, so we re-use the PAR values for GRAN. -#define GRAN_DEBUG_event_trace (1<<14) -#define GRAN_DEBUG_event_stats (1<<15) -#define GRAN_DEBUG_bq (1<<16) -#define GRAN_DEBUG_pack (1<<17) -#define GRAN_DEBUG_checkSparkQ (1<<18) -#define GRAN_DEBUG_thunkStealing (1<<19) -#define GRAN_DEBUG_randomSteal (1<<20) -#define GRAN_DEBUG_findWork (1<<21) -#define GRAN_DEBUG_unused (1<<22) -#define GRAN_DEBUG_pri (1<<23) -#define GRAN_DEBUG_checkLight (1<<24) -#define GRAN_DEBUG_sortedQ (1<<25) -#define GRAN_DEBUG_blockOnFetch (1<<26) -#define GRAN_DEBUG_packBuffer (1<<27) -#define GRAN_DEBUG_BOF_sanity (1<<28) - -// Profiling flags -#define TRACE_sched (1<<29) - +// 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 #endif /* TRACE_H */