Trace.h 3.04 KB
Newer Older
Simon Marlow's avatar
Simon Marlow committed
1 2 3 4
/* -----------------------------------------------------------------------------
 *
 * (c) The GHC Team 2006
 *
Simon Marlow's avatar
Simon Marlow committed
5
 * Debug tracing.  
Simon Marlow's avatar
Simon Marlow committed
6 7
 *
 * This is a layer over RtsMessages, which provides for generating
Simon Marlow's avatar
Simon Marlow committed
8
 * trace messages with timestamps and task IDs attached
Simon Marlow's avatar
Simon Marlow committed
9 10 11
 * automatically.  Also, multiple classes of messages are supported,
 * which can be enabled separately via RTS flags.
 *
Simon Marlow's avatar
Simon Marlow committed
12
 * All debug trace messages go through here.
Simon Marlow's avatar
Simon Marlow committed
13 14 15 16 17 18
 *
 * ---------------------------------------------------------------------------*/

#ifndef TRACE_H
#define TRACE_H

19 20
#pragma GCC visibility push(hidden)

Simon Marlow's avatar
Simon Marlow committed
21 22 23 24
// -----------------------------------------------------------------------------
// Tracing functions
// -----------------------------------------------------------------------------

Simon Marlow's avatar
Simon Marlow committed
25 26
#ifdef DEBUG

Simon Marlow's avatar
Simon Marlow committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
void initTracing (void);

// The simple way:
void trace (StgWord32 class, const char *str, ...)
    GNUC3_ATTRIBUTE(format (printf, 2, 3));

// The harder way: sometimes we want to generate a trace message that
// consists of multiple components generated by different functions.
// So we provide the functionality of trace() split into 3 parts: 
//   - traceClass(): a check that the required class is enabled
//   - traceBegin(): print the beginning of the trace message
//   - traceEnd(): complete the trace message (release the lock too).
// 
INLINE_HEADER rtsBool traceClass (StgWord32 class);

void traceBegin (const char *str, ...)
    GNUC3_ATTRIBUTE(format (printf, 1, 2));

void traceEnd (void);

#define debugTrace(class, str, ...) trace(class,str, ## __VA_ARGS__)
// variable arg macros are C99, and supported by gcc.
49
#define debugTraceBegin(str, ...) traceBegin(str, ## __VA_ARGS__)
Simon Marlow's avatar
Simon Marlow committed
50
#define debugTraceEnd() traceEnd()
Simon Marlow's avatar
Simon Marlow committed
51 52 53

#else /* !DEBUG */

Simon Marlow's avatar
Simon Marlow committed
54
#define debugTrace(class, str, ...) /* nothing */
55
#define debugTraceBegin(str, ...) /* nothing */
Simon Marlow's avatar
Simon Marlow committed
56 57
#define debugTraceEnd() /* nothing */

Simon Marlow's avatar
Simon Marlow committed
58
#endif
Simon Marlow's avatar
Simon Marlow committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78

// -----------------------------------------------------------------------------
// 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)
79
#define DEBUG_hpc                  (1<<14)
Simon Marlow's avatar
Simon Marlow committed
80
#define DEBUG_eventlog		   (1<<15)
Simon Marlow's avatar
Simon Marlow committed
81 82 83 84 85 86 87 88 89 90 91 92

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

extern StgWord32 classes_enabled;

INLINE_HEADER rtsBool
traceClass (StgWord32 class) { return (classes_enabled & class); }

// -----------------------------------------------------------------------------

93 94
#pragma GCC visibility pop

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