Remove old GUM/GranSim code
[ghc-hetmet.git] / rts / Trace.c
1 /* -----------------------------------------------------------------------------
2  *
3  * (c) The GHC Team 2006-2009
4  *
5  * Debug and performance tracing
6  *
7  * ---------------------------------------------------------------------------*/
8
9 #ifdef DEBUG
10
11 #include "Rts.h"
12 #include "OSThreads.h"
13 #include "Trace.h"
14 #include "RtsFlags.h"
15 #include "GetTime.h"
16 #include "Stats.h"
17
18 /*
19   Features we want:
20     - multiple log message classes
21     - outpout thread ID & time on each message
22     - thread-safe
23     - trace source locations?
24     - break into the debugger?
25 */
26
27 StgWord32 classes_enabled; // not static due to inline funcs
28
29 #ifdef THREADED_RTS
30 static Mutex trace_utx;
31 #endif
32
33 #define DEBUG_FLAG(name, class) \
34     if (RtsFlags.DebugFlags.name) classes_enabled |= class;
35
36 void initTracing (void)
37 {
38 #ifdef THREADED_RTS
39     initMutex(&trace_utx);
40 #endif
41
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);
56 }
57
58 static void tracePreface (void)
59 {
60 #ifdef THREADED_RTS
61     debugBelch("%12lx: ", (unsigned long)osThreadId());
62 #endif
63     if (RtsFlags.DebugFlags.timestamp) {
64         debugBelch("%9" FMT_Word64 ": ", stat_getElapsedTime());
65     }
66 }
67
68 void trace (StgWord32 class, const char *str, ...)
69 {
70     va_list ap;
71     va_start(ap,str);
72
73     ACQUIRE_LOCK(&trace_utx);
74
75     if ((classes_enabled & class) != 0) {
76         tracePreface();
77         vdebugBelch(str,ap);
78         debugBelch("\n");
79     }
80
81     RELEASE_LOCK(&trace_utx);
82
83     va_end(ap);
84 }
85
86 void traceBegin (const char *str, ...)
87 {
88     va_list ap;
89     va_start(ap,str);
90
91     ACQUIRE_LOCK(&trace_utx);
92
93     tracePreface();
94     vdebugBelch(str,ap);
95 }
96
97 void traceEnd (void)
98 {
99     debugBelch("\n");
100     RELEASE_LOCK(&trace_utx);
101 }
102
103 #endif