1 /* -----------------------------------------------------------------------------
3 * (c) The GHC Team 2006
5 * Debug and performance tracing
7 * ---------------------------------------------------------------------------*/
10 #include "OSThreads.h"
18 - multiple log message classes
19 - outpout thread ID & time on each message
21 - trace source locations?
22 - break into the debugger?
25 StgWord32 classes_enabled; // not static due to inline funcs
28 static Mutex trace_utx;
32 #define DEBUG_FLAG(name, class) \
33 if (RtsFlags.DebugFlags.name) classes_enabled |= class;
35 #define DEBUG_FLAG(name, class) \
40 #define PAR_FLAG(name, class) \
41 if (RtsFlags.ParFlags.Debug.name) classes_enabled |= class;
43 #define PAR_FLAG(name, class) \
48 #define GRAN_FLAG(name, class) \
49 if (RtsFlags.GranFlags.Debug.name) classes_enabled |= class;
51 #define GRAN_FLAG(name, class) \
55 #define TRACE_FLAG(name, class) \
56 if (RtsFlags.TraceFlags.name) classes_enabled |= class;
59 void initTracing (void)
62 initMutex(&trace_utx);
65 DEBUG_FLAG(scheduler, DEBUG_sched);
66 DEBUG_FLAG(interpreter, DEBUG_interp);
67 DEBUG_FLAG(weak, DEBUG_weak);
68 DEBUG_FLAG(gccafs, DEBUG_gccafs);
69 DEBUG_FLAG(gc, DEBUG_gc);
70 DEBUG_FLAG(block_alloc, DEBUG_block_alloc);
71 DEBUG_FLAG(sanity, DEBUG_sanity);
72 DEBUG_FLAG(stable, DEBUG_stable);
73 DEBUG_FLAG(stm, DEBUG_stm);
74 DEBUG_FLAG(prof, DEBUG_prof);
75 DEBUG_FLAG(gran, DEBUG_gran);
76 DEBUG_FLAG(par, DEBUG_par);
77 DEBUG_FLAG(linker, DEBUG_linker);
78 DEBUG_FLAG(squeeze, DEBUG_squeeze);
79 DEBUG_FLAG(hpc, DEBUG_hpc);
81 PAR_FLAG(verbose, PAR_DEBUG_verbose);
82 PAR_FLAG(bq, PAR_DEBUG_bq);
83 PAR_FLAG(schedule, PAR_DEBUG_schedule);
84 PAR_FLAG(free, PAR_DEBUG_free);
85 PAR_FLAG(resume, PAR_DEBUG_resume);
86 PAR_FLAG(weight, PAR_DEBUG_weight);
87 PAR_FLAG(fetch, PAR_DEBUG_fetch);
88 PAR_FLAG(fish, PAR_DEBUG_fish);
89 PAR_FLAG(tables, PAR_DEBUG_tables);
90 PAR_FLAG(packet, PAR_DEBUG_packet);
91 PAR_FLAG(pack, PAR_DEBUG_pack);
92 PAR_FLAG(paranoia, PAR_DEBUG_paranoia);
94 GRAN_FLAG(event_trace, GRAN_DEBUG_event_trace);
95 GRAN_FLAG(event_stats, GRAN_DEBUG_event_stats);
96 GRAN_FLAG(bq, GRAN_DEBUG_bq);
97 GRAN_FLAG(pack, GRAN_DEBUG_pack);
98 GRAN_FLAG(checkSparkQ, GRAN_DEBUG_checkSparkQ);
99 GRAN_FLAG(thunkStealing, GRAN_DEBUG_thunkStealing);
100 GRAN_FLAG(randomSteal, GRAN_DEBUG_randomSteal);
101 GRAN_FLAG(findWork, GRAN_DEBUG_findWork);
102 GRAN_FLAG(unused, GRAN_DEBUG_unused);
103 GRAN_FLAG(pri, GRAN_DEBUG_pri);
104 GRAN_FLAG(checkLight, GRAN_DEBUG_checkLight);
105 GRAN_FLAG(sortedQ, GRAN_DEBUG_sortedQ);
106 GRAN_FLAG(blockOnFetch, GRAN_DEBUG_blockOnFetch);
107 GRAN_FLAG(packBuffer, GRAN_DEBUG_packBuffer);
108 GRAN_FLAG(blockedOnFetch_sanity, GRAN_DEBUG_BOF_sanity);
110 TRACE_FLAG(sched, TRACE_sched);
111 TRACE_FLAG(gc, TRACE_gc);
114 static void tracePreface (void)
117 debugBelch("%12lx: ", (unsigned long)osThreadId());
119 if (RtsFlags.TraceFlags.timestamp) {
120 debugBelch("%9" FMT_Word64 ": ", stat_getElapsedTime());
124 void trace (StgWord32 class, const char *str, ...)
129 ACQUIRE_LOCK(&trace_utx);
131 if ((classes_enabled & class) != 0) {
137 RELEASE_LOCK(&trace_utx);
142 void traceBegin (const char *str, ...)
147 ACQUIRE_LOCK(&trace_utx);
156 RELEASE_LOCK(&trace_utx);