Unify event logging and debug tracing.
[ghc.git] / rts / Trace.h
1 /* -----------------------------------------------------------------------------
2 *
3 * (c) The GHC Team, 2008-2009
4 *
5 * Support for fast binary event logging.
6 *
7 * ---------------------------------------------------------------------------*/
8
9 #ifndef TRACE_H
10 #define TRACE_H
11
12 #include "rts/EventLogFormat.h"
13 #include "Capability.h"
14
15 #pragma GCC visibility push(hidden)
16
17 // -----------------------------------------------------------------------------
18 // Posting events
19 // -----------------------------------------------------------------------------
20
21 INLINE_HEADER void trace (StgWord32 class, char *msg, ...);
22
23 #ifdef DEBUG
24 INLINE_HEADER void debugTrace (StgWord32 class, char *msg, ...);
25 #endif
26
27 INLINE_HEADER void traceSchedEvent (Capability *cap, EventTypeNum tag,
28 StgTSO *tso, StgWord64 other);
29
30 INLINE_HEADER void traceCap (StgWord32 class, Capability *cap,
31 char *msg, ...);
32
33 INLINE_HEADER void traceThreadStatus (StgWord32 class, StgTSO *tso);
34
35 INLINE_HEADER rtsBool traceClass (StgWord32 class);
36
37 #ifdef DEBUG
38 void traceBegin (const char *str, ...);
39 void traceEnd (void);
40 #endif
41
42 // -----------------------------------------------------------------------------
43 // EventLog API
44 // -----------------------------------------------------------------------------
45
46 #if defined(TRACING)
47
48 void initTracing (void);
49 void endTracing (void);
50 void freeTracing (void);
51
52 #endif /* TRACING */
53
54 // -----------------------------------------------------------------------------
55 // Message classes, these may be OR-ed together
56 // -----------------------------------------------------------------------------
57
58 // debugging flags, set with +RTS -D<something>
59 #define DEBUG_sched (1<<0)
60 #define DEBUG_interp (1<<1)
61 #define DEBUG_weak (1<<2)
62 #define DEBUG_gccafs (1<<3)
63 #define DEBUG_gc (1<<4)
64 #define DEBUG_block_alloc (1<<5)
65 #define DEBUG_sanity (1<<6)
66 #define DEBUG_stable (1<<7)
67 #define DEBUG_stm (1<<8)
68 #define DEBUG_prof (1<<9)
69 #define DEBUG_gran (1<<10)
70 #define DEBUG_par (1<<11)
71 #define DEBUG_linker (1<<12)
72 #define DEBUG_squeeze (1<<13)
73 #define DEBUG_hpc (1<<14)
74 #define DEBUG_sparks (1<<15)
75
76 // events
77 #define TRACE_sched (1<<16)
78
79 // -----------------------------------------------------------------------------
80 // PRIVATE below here
81 // -----------------------------------------------------------------------------
82
83 #ifdef TRACING
84
85 extern StgWord32 classes_enabled;
86
87 INLINE_HEADER rtsBool traceClass (StgWord32 class)
88 { return (classes_enabled & class); }
89
90 void traceSchedEvent_ (Capability *cap, EventTypeNum tag,
91 StgTSO *tso, StgWord64 other);
92
93 /*
94 * Trace an event to the capability's event buffer.
95 */
96 INLINE_HEADER void traceSchedEvent(Capability *cap, EventTypeNum tag,
97 StgTSO *tso, StgWord64 other)
98 {
99 if (traceClass(TRACE_sched)) {
100 traceSchedEvent_(cap, tag, tso, other);
101 }
102 }
103
104 void traceCap_(Capability *cap, char *msg, va_list ap);
105
106 /*
107 * Trace a log message
108 */
109 INLINE_HEADER void traceCap (StgWord32 class, Capability *cap, char *msg, ...)
110 {
111 va_list ap;
112 va_start(ap,msg);
113 if (traceClass(class)) {
114 traceCap_(cap, msg, ap);
115 }
116 va_end(ap);
117 }
118
119 void trace_(char *msg, va_list ap);
120
121 /*
122 * Trace a log message
123 */
124 INLINE_HEADER void trace (StgWord32 class, char *msg, ...)
125 {
126 va_list ap;
127 va_start(ap,msg);
128 if (traceClass(class)) {
129 trace_(msg, ap);
130 }
131 va_end(ap);
132 }
133
134 #ifdef DEBUG
135 INLINE_HEADER void debugTrace (StgWord32 class, char *msg, ...)
136 {
137 va_list ap;
138 va_start(ap,msg);
139 if (traceClass(class)) {
140 trace_(msg, ap);
141 }
142 va_end(ap);
143 }
144 #else
145
146 #define debugTrace(class, str, ...) /* nothing */
147 // variable arg macros are C99, and supported by gcc.
148
149 #endif
150
151 void traceThreadStatus_ (StgTSO *tso);
152
153 INLINE_HEADER void traceThreadStatus (StgWord32 class, StgTSO *tso)
154 {
155 if (traceClass(class)) {
156 traceThreadStatus_(tso);
157 }
158 }
159
160 #else /* !TRACING */
161
162 INLINE_HEADER rtsBool traceClass (StgWord32 class STG_UNUSED)
163 { return rtsFalse; }
164
165 INLINE_HEADER void traceSchedEvent (Capability *cap STG_UNUSED,
166 EventTypeNum tag STG_UNUSED,
167 StgTSO *tso STG_UNUSED,
168 StgWord64 other STG_UNUSED)
169 { /* nothing */ }
170
171 INLINE_HEADER void traceCap (StgWord32 class STG_UNUSED,
172 Capability *cap STG_UNUSED,
173 char *msg STG_UNUSED, ...)
174 { /* nothing */ }
175
176 INLINE_HEADER void trace (StgWord32 class STG_UNUSED,
177 char *msg STG_UNUSED, ...)
178 { /* nothing */ }
179
180 #define debugTrace(class, str, ...) /* nothing */
181 // variable arg macros are C99, and supported by gcc.
182
183 INLINE_HEADER void traceThreadStatus (StgWord32 class STG_UNUSED,
184 StgTSO *tso STG_UNUSED)
185 { /* nothing */ }
186
187 #endif /* TRACING */
188
189 #pragma GCC visibility pop
190
191 #endif /* TRACE_H */