1 /* -----------------------------------------------------------------------------
3 * (c) The GHC Team 2006-2009
5 * Debug and performance tracing
7 * ---------------------------------------------------------------------------*/
12 #include "OSThreads.h"
20 - multiple log message classes
21 - outpout thread ID & time on each message
23 - trace source locations?
24 - break into the debugger?
27 StgWord32 classes_enabled; // not static due to inline funcs
30 static Mutex trace_utx;
33 #define DEBUG_FLAG(name, class) \
34 if (RtsFlags.DebugFlags.name) classes_enabled |= class;
36 void initTracing (void)
39 initMutex(&trace_utx);
42 DEBUG_FLAG(scheduler, DEBUG_sched);
43 DEBUG_FLAG(interpreter, DEBUG_interp);
44 DEBUG_FLAG(weak, DEBUG_weak);
45 DEBUG_FLAG(gccafs, DEBUG_gccafs);
46 DEBUG_FLAG(gc, DEBUG_gc);
47 DEBUG_FLAG(block_alloc, DEBUG_block_alloc);
48 DEBUG_FLAG(sanity, DEBUG_sanity);
49 DEBUG_FLAG(stable, DEBUG_stable);
50 DEBUG_FLAG(stm, DEBUG_stm);
51 DEBUG_FLAG(prof, DEBUG_prof);
52 DEBUG_FLAG(eventlog, DEBUG_eventlog);
53 DEBUG_FLAG(linker, DEBUG_linker);
54 DEBUG_FLAG(squeeze, DEBUG_squeeze);
55 DEBUG_FLAG(hpc, DEBUG_hpc);
58 static void tracePreface (void)
61 debugBelch("%12lx: ", (unsigned long)osThreadId());
63 if (RtsFlags.DebugFlags.timestamp) {
64 debugBelch("%9" FMT_Word64 ": ", stat_getElapsedTime());
68 void trace (StgWord32 class, const char *str, ...)
73 ACQUIRE_LOCK(&trace_utx);
75 if ((classes_enabled & class) != 0) {
81 RELEASE_LOCK(&trace_utx);
86 void traceBegin (const char *str, ...)
91 ACQUIRE_LOCK(&trace_utx);
100 RELEASE_LOCK(&trace_utx);