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(gran, DEBUG_gran);
54 DEBUG_FLAG(par, DEBUG_par);
55 DEBUG_FLAG(linker, DEBUG_linker);
56 DEBUG_FLAG(squeeze, DEBUG_squeeze);
57 DEBUG_FLAG(hpc, DEBUG_hpc);
60 static void tracePreface (void)
63 debugBelch("%12lx: ", (unsigned long)osThreadId());
65 if (RtsFlags.DebugFlags.timestamp) {
66 debugBelch("%9" FMT_Word64 ": ", stat_getElapsedTime());
70 void trace (StgWord32 class, const char *str, ...)
75 ACQUIRE_LOCK(&trace_utx);
77 if ((classes_enabled & class) != 0) {
83 RELEASE_LOCK(&trace_utx);
88 void traceBegin (const char *str, ...)
93 ACQUIRE_LOCK(&trace_utx);
102 RELEASE_LOCK(&trace_utx);