Trace.h 3.64 KB
Newer Older
Simon Marlow's avatar
Simon Marlow committed
1 2
/* -----------------------------------------------------------------------------
 *
3
 * (c) The GHC Team, 2008-2009
Simon Marlow's avatar
Simon Marlow committed
4
 *
5
 * Support for fast binary event logging.
Simon Marlow's avatar
Simon Marlow committed
6 7 8 9 10 11
 *
 * ---------------------------------------------------------------------------*/

#ifndef TRACE_H
#define TRACE_H

12 13 14
#include "rts/EventLogFormat.h"
#include "Capability.h"

15
BEGIN_RTS_PRIVATE
16

17 18 19
// -----------------------------------------------------------------------------
// EventLog API
// -----------------------------------------------------------------------------
Simon Marlow's avatar
Simon Marlow committed
20

21
#if defined(TRACING)
Simon Marlow's avatar
Simon Marlow committed
22

23 24 25
void initTracing (void);
void endTracing  (void);
void freeTracing (void);
Simon Marlow's avatar
Simon Marlow committed
26

27
#endif /* TRACING */
Simon Marlow's avatar
Simon Marlow committed
28 29

// -----------------------------------------------------------------------------
30
// Message classes
Simon Marlow's avatar
Simon Marlow committed
31 32 33
// -----------------------------------------------------------------------------

// debugging flags, set with +RTS -D<something>
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
extern int DEBUG_sched;
extern int DEBUG_interp;
extern int DEBUG_weak;
extern int DEBUG_gccafs;
extern int DEBUG_gc;
extern int DEBUG_block_alloc;
extern int DEBUG_sanity;
extern int DEBUG_stable;
extern int DEBUG_stm;
extern int DEBUG_prof;
extern int DEBUG_gran;
extern int DEBUG_par;
extern int DEBUG_linker;
extern int DEBUG_squeeze;
extern int DEBUG_hpc;
extern int DEBUG_sparks;
50 51

// events
52
extern int TRACE_sched;
Simon Marlow's avatar
Simon Marlow committed
53 54

// -----------------------------------------------------------------------------
55 56 57 58 59 60 61
// Posting events
//
// We use macros rather than inline functions deliberately.  We want
// the not-taken case to be as efficient as possible, a simple
// test-and-jump, and with inline functions gcc seemed to move some of
// the instructions from the branch up before the test.
// 
Simon Marlow's avatar
Simon Marlow committed
62 63
// -----------------------------------------------------------------------------

64 65 66 67
#ifdef DEBUG
void traceBegin (const char *str, ...);
void traceEnd (void);
#endif
68

69
#ifdef TRACING
Simon Marlow's avatar
Simon Marlow committed
70

71 72 73 74 75 76 77
/* 
 * Record a scheduler event
 */
#define traceSchedEvent(cap, tag, tso, other)   \
    if (RTS_UNLIKELY(TRACE_sched)) {            \
        traceSchedEvent_(cap, tag, tso, other); \
    }
78 79 80 81

void traceSchedEvent_ (Capability *cap, EventTypeNum tag, 
                       StgTSO *tso, StgWord64 other);

82 83 84 85
// variadic macros are C99, and supported by gcc.  However, the
// ##__VA_ARGS syntax is a gcc extension, which allows the variable
// argument list to be empty (see gcc docs for details).

86
/* 
87
 * Emit a trace message on a particular Capability
88
 */
89 90 91
#define traceCap(class, cap, msg, ...)          \
    if (RTS_UNLIKELY(class)) {                  \
        traceCap_(cap, msg, ##__VA_ARGS__);     \
92 93
    }

94
void traceCap_(Capability *cap, char *msg, ...);
95 96

/* 
97
 * Emit a trace message
98
 */
99 100 101
#define trace(class, msg, ...)                  \
    if (RTS_UNLIKELY(class)) {                  \
        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 111 112
#define debugTrace(class, msg, ...)             \
    if (RTS_UNLIKELY(class)) {                  \
        trace_(msg, ##__VA_ARGS__);             \
113 114 115 116 117
    }
#else
#define debugTrace(class, str, ...) /* nothing */
#endif

118 119 120 121 122 123
/* 
 * Emit a message/event describing the state of a thread
 */
#define traceThreadStatus(class, tso)           \
    if (RTS_UNLIKELY(class)) {                  \
        traceThreadStatus_(tso);                \
124 125
    }

126
void traceThreadStatus_ (StgTSO *tso);
127

128
#else /* !TRACING */
129

130 131 132
#define traceSchedEvent(cap, tag, tso, other) /* nothing */
#define traceCap(class, cap, msg, ...) /* nothing */
#define trace(class, msg, ...) /* nothing */
133
#define debugTrace(class, str, ...) /* nothing */
134
#define traceThreadStatus(class, tso) /* nothing */
135 136

#endif /* TRACING */
Simon Marlow's avatar
Simon Marlow committed
137

138
END_RTS_PRIVATE
139

Simon Marlow's avatar
Simon Marlow committed
140
#endif /* TRACE_H */