Trace.h 4.95 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

Simon Marlow's avatar
Simon Marlow committed
17
// -----------------------------------------------------------------------------
18
// Posting events
Simon Marlow's avatar
Simon Marlow committed
19 20
// -----------------------------------------------------------------------------

21 22
INLINE_HEADER void trace (StgWord32 class, char *msg, ...);

Simon Marlow's avatar
Simon Marlow committed
23
#ifdef DEBUG
24 25
INLINE_HEADER void debugTrace (StgWord32 class, char *msg, ...);
#endif
Simon Marlow's avatar
Simon Marlow committed
26

27 28
INLINE_HEADER void traceSchedEvent (Capability *cap, EventTypeNum tag, 
                                    StgTSO *tso, StgWord64 other);
Simon Marlow's avatar
Simon Marlow committed
29

30 31
INLINE_HEADER void traceCap (StgWord32 class, Capability *cap,
                             char *msg, ...);
Simon Marlow's avatar
Simon Marlow committed
32

33
INLINE_HEADER void traceThreadStatus (StgWord32 class, StgTSO *tso);
Simon Marlow's avatar
Simon Marlow committed
34

35 36 37 38
INLINE_HEADER rtsBool traceClass (StgWord32 class);

#ifdef DEBUG
void traceBegin (const char *str, ...);
Simon Marlow's avatar
Simon Marlow committed
39
void traceEnd (void);
40
#endif
Simon Marlow's avatar
Simon Marlow committed
41

42 43 44
// -----------------------------------------------------------------------------
// EventLog API
// -----------------------------------------------------------------------------
Simon Marlow's avatar
Simon Marlow committed
45

46
#if defined(TRACING)
Simon Marlow's avatar
Simon Marlow committed
47

48 49 50
void initTracing (void);
void endTracing  (void);
void freeTracing (void);
Simon Marlow's avatar
Simon Marlow committed
51

52
#endif /* TRACING */
Simon Marlow's avatar
Simon Marlow committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72

// -----------------------------------------------------------------------------
// Message classes, these may be OR-ed together
// -----------------------------------------------------------------------------

// debugging flags, set with +RTS -D<something>
#define DEBUG_sched		   (1<<0)
#define DEBUG_interp		   (1<<1)
#define DEBUG_weak		   (1<<2)
#define DEBUG_gccafs		   (1<<3) 
#define DEBUG_gc		   (1<<4) 
#define DEBUG_block_alloc	   (1<<5) 
#define DEBUG_sanity		   (1<<6) 
#define DEBUG_stable		   (1<<7) 
#define DEBUG_stm   		   (1<<8) 
#define DEBUG_prof		   (1<<9) 
#define DEBUG_gran		   (1<<10)
#define DEBUG_par		   (1<<11)
#define DEBUG_linker		   (1<<12)
#define DEBUG_squeeze              (1<<13)
73
#define DEBUG_hpc                  (1<<14)
74 75 76 77
#define DEBUG_sparks		   (1<<15)

// events
#define TRACE_sched                (1<<16)
Simon Marlow's avatar
Simon Marlow committed
78 79 80 81 82

// -----------------------------------------------------------------------------
// PRIVATE below here
// -----------------------------------------------------------------------------

83 84
#ifdef TRACING

Simon Marlow's avatar
Simon Marlow committed
85 86
extern StgWord32 classes_enabled;

87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
INLINE_HEADER rtsBool traceClass (StgWord32 class) 
{ return (classes_enabled & class); }

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

/* 
 * Trace an event to the capability's event buffer.
 */
INLINE_HEADER void traceSchedEvent(Capability *cap, EventTypeNum tag, 
                                   StgTSO *tso, StgWord64 other)
{
    if (traceClass(TRACE_sched)) {
        traceSchedEvent_(cap, tag, tso, other);
    }
}

void traceCap_(Capability *cap, char *msg, va_list ap);

/* 
 * Trace a log message
 */
INLINE_HEADER void traceCap (StgWord32 class, Capability *cap, char *msg, ...)
{
    va_list ap;
    va_start(ap,msg);
    if (traceClass(class)) {
        traceCap_(cap, msg, ap);
    }
    va_end(ap);
}

void trace_(char *msg, va_list ap);

/* 
 * Trace a log message
 */
INLINE_HEADER void trace (StgWord32 class, char *msg, ...)
{
    va_list ap;
    va_start(ap,msg);
    if (traceClass(class)) {
        trace_(msg, ap);
    }
    va_end(ap);
}
Simon Marlow's avatar
Simon Marlow committed
133

134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
#ifdef DEBUG
INLINE_HEADER void debugTrace (StgWord32 class, char *msg, ...)
{
    va_list ap;
    va_start(ap,msg);
    if (traceClass(class)) {
        trace_(msg, ap);
    }
    va_end(ap);
}
#else

#define debugTrace(class, str, ...) /* nothing */
// variable arg macros are C99, and supported by gcc.

#endif

void traceThreadStatus_ (StgTSO *tso);

INLINE_HEADER void traceThreadStatus (StgWord32 class, StgTSO *tso)
{
    if (traceClass(class)) {
        traceThreadStatus_(tso);
    }
}    

#else /* !TRACING */

INLINE_HEADER rtsBool traceClass (StgWord32 class STG_UNUSED) 
{ return rtsFalse; }

INLINE_HEADER void traceSchedEvent (Capability *cap STG_UNUSED,
                                    EventTypeNum tag STG_UNUSED, 
                                    StgTSO *tso STG_UNUSED,
                                    StgWord64 other STG_UNUSED)
{ /* nothing */ }

INLINE_HEADER void traceCap (StgWord32 class STG_UNUSED,
                             Capability *cap STG_UNUSED,
                             char *msg STG_UNUSED, ...)
{ /* nothing */ }

INLINE_HEADER void trace (StgWord32 class STG_UNUSED, 
                          char *msg STG_UNUSED, ...)
{ /* nothing */ }

#define debugTrace(class, str, ...) /* nothing */
// variable arg macros are C99, and supported by gcc.

INLINE_HEADER void traceThreadStatus (StgWord32 class STG_UNUSED, 
                                      StgTSO *tso STG_UNUSED)
{ /* nothing */ }

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

189
END_RTS_PRIVATE
190

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