1 /* -----------------------------------------------------------------------------
3 * (c) The GHC Team 2006-2009
5 * Debug and performance tracing
7 * ---------------------------------------------------------------------------*/
13 #include "rts/Flags.h"
22 - multiple log message classes
23 - outpout thread ID & time on each message
25 - trace source locations?
26 - break into the debugger?
29 StgWord32 classes_enabled; // not static due to inline funcs
32 static Mutex trace_utx;
35 #define DEBUG_FLAG(name, class) \
36 if (RtsFlags.DebugFlags.name) classes_enabled |= class;
38 void initTracing (void)
41 initMutex(&trace_utx);
44 DEBUG_FLAG(scheduler, DEBUG_sched);
45 DEBUG_FLAG(interpreter, DEBUG_interp);
46 DEBUG_FLAG(weak, DEBUG_weak);
47 DEBUG_FLAG(gccafs, DEBUG_gccafs);
48 DEBUG_FLAG(gc, DEBUG_gc);
49 DEBUG_FLAG(block_alloc, DEBUG_block_alloc);
50 DEBUG_FLAG(sanity, DEBUG_sanity);
51 DEBUG_FLAG(stable, DEBUG_stable);
52 DEBUG_FLAG(stm, DEBUG_stm);
53 DEBUG_FLAG(prof, DEBUG_prof);
54 DEBUG_FLAG(eventlog, DEBUG_eventlog);
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);