Optimise the code generated at trace points
[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 // variadic macros are C99, and supported by gcc. However, the
83 // ##__VA_ARGS syntax is a gcc extension, which allows the variable
84 // argument list to be empty (see gcc docs for details).
85
86 /*
87 * Emit a trace message on a particular Capability
88 */
89 #define traceCap(class, cap, msg, ...) \
90 if (RTS_UNLIKELY(class)) { \
91 traceCap_(cap, msg, ##__VA_ARGS__); \
92 }
93
94 void traceCap_(Capability *cap, char *msg, ...);
95
96 /*
97 * Emit a trace message
98 */
99 #define trace(class, msg, ...) \
100 if (RTS_UNLIKELY(class)) { \
101 trace_(msg, ##__VA_ARGS__); \
102 }
103
104 void trace_(char *msg, ...);
105
106 /*
107 * Emit a debug message (only when DEBUG is defined)
108 */
109 #ifdef DEBUG
110 #define debugTrace(class, msg, ...) \
111 if (RTS_UNLIKELY(class)) { \
112 trace_(msg, ##__VA_ARGS__); \
113 }
114 #else
115 #define debugTrace(class, str, ...) /* nothing */
116 #endif
117
118 /*
119 * Emit a message/event describing the state of a thread
120 */
121 #define traceThreadStatus(class, tso) \
122 if (RTS_UNLIKELY(class)) { \
123 traceThreadStatus_(tso); \
124 }
125
126 void traceThreadStatus_ (StgTSO *tso);
127
128 #else /* !TRACING */
129
130 #define traceSchedEvent(cap, tag, tso, other) /* nothing */
131 #define traceCap(class, cap, msg, ...) /* nothing */
132 #define trace(class, msg, ...) /* nothing */
133 #define debugTrace(class, str, ...) /* nothing */
134 #define traceThreadStatus(class, tso) /* nothing */
135
136 #endif /* TRACING */
137
138 END_RTS_PRIVATE
139
140 #endif /* TRACE_H */