Add events to show when GC threads are idle/working
[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 BEGIN_RTS_PRIVATE
16
17 // -----------------------------------------------------------------------------
18 // EventLog API
19 // -----------------------------------------------------------------------------
20
21 #if defined(TRACING)
22
23 void initTracing (void);
24 void endTracing (void);
25 void freeTracing (void);
26
27 #endif /* TRACING */
28
29 // -----------------------------------------------------------------------------
30 // Message classes
31 // -----------------------------------------------------------------------------
32
33 // debugging flags, set with +RTS -D<something>
34 extern int DEBUG_sched;
35 extern int DEBUG_interp;
36 extern int DEBUG_weak;
37 extern int DEBUG_gccafs;
38 extern int DEBUG_gc;
39 extern int DEBUG_block_alloc;
40 extern int DEBUG_sanity;
41 extern int DEBUG_stable;
42 extern int DEBUG_stm;
43 extern int DEBUG_prof;
44 extern int DEBUG_gran;
45 extern int DEBUG_par;
46 extern int DEBUG_linker;
47 extern int DEBUG_squeeze;
48 extern int DEBUG_hpc;
49 extern int DEBUG_sparks;
50
51 // events
52 extern int TRACE_sched;
53
54 // -----------------------------------------------------------------------------
55 // Posting events
56 //
57 // We use macros rather than inline functions deliberately. We want
58 // the not-taken case to be as efficient as possible, a simple
59 // test-and-jump, and with inline functions gcc seemed to move some of
60 // the instructions from the branch up before the test.
61 //
62 // -----------------------------------------------------------------------------
63
64 #ifdef DEBUG
65 void traceBegin (const char *str, ...);
66 void traceEnd (void);
67 #endif
68
69 #ifdef TRACING
70
71 /*
72 * Record a scheduler event
73 */
74 #define traceSchedEvent(cap, tag, tso, other) \
75 if (RTS_UNLIKELY(TRACE_sched)) { \
76 traceSchedEvent_(cap, tag, tso, other); \
77 }
78
79 void traceSchedEvent_ (Capability *cap, EventTypeNum tag,
80 StgTSO *tso, StgWord64 other);
81
82
83 /*
84 * Record a nullary event
85 */
86 #define traceEvent(cap, tag) \
87 if (RTS_UNLIKELY(TRACE_sched)) { \
88 traceEvent_(cap, tag); \
89 }
90
91 void traceEvent_ (Capability *cap, EventTypeNum tag);
92
93 // variadic macros are C99, and supported by gcc. However, the
94 // ##__VA_ARGS syntax is a gcc extension, which allows the variable
95 // argument list to be empty (see gcc docs for details).
96
97 /*
98 * Emit a trace message on a particular Capability
99 */
100 #define traceCap(class, cap, msg, ...) \
101 if (RTS_UNLIKELY(class)) { \
102 traceCap_(cap, msg, ##__VA_ARGS__); \
103 }
104
105 void traceCap_(Capability *cap, char *msg, ...);
106
107 /*
108 * Emit a trace message
109 */
110 #define trace(class, msg, ...) \
111 if (RTS_UNLIKELY(class)) { \
112 trace_(msg, ##__VA_ARGS__); \
113 }
114
115 void trace_(char *msg, ...);
116
117 /*
118 * A message or event emitted by the program
119 */
120 void traceUserMsg(Capability *cap, char *msg);
121
122 /*
123 * Emit a debug message (only when DEBUG is defined)
124 */
125 #ifdef DEBUG
126 #define debugTrace(class, msg, ...) \
127 if (RTS_UNLIKELY(class)) { \
128 trace_(msg, ##__VA_ARGS__); \
129 }
130 #else
131 #define debugTrace(class, str, ...) /* nothing */
132 #endif
133
134 /*
135 * Emit a message/event describing the state of a thread
136 */
137 #define traceThreadStatus(class, tso) \
138 if (RTS_UNLIKELY(class)) { \
139 traceThreadStatus_(tso); \
140 }
141
142 void traceThreadStatus_ (StgTSO *tso);
143
144 #else /* !TRACING */
145
146 #define traceSchedEvent(cap, tag, tso, other) /* nothing */
147 #define traceEvent(cap, tag) /* nothing */
148 #define traceCap(class, cap, msg, ...) /* nothing */
149 #define trace(class, msg, ...) /* nothing */
150 #define debugTrace(class, str, ...) /* nothing */
151 #define traceThreadStatus(class, tso) /* nothing */
152
153 #endif /* TRACING */
154
155 END_RTS_PRIVATE
156
157 #endif /* TRACE_H */