X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=rts%2FTrace.c;h=53fc25a249fa1fd65bcfca90c20a48474b2bd95e;hb=8625c675de45bdb8bcfa795572ce7c47687c147c;hp=20debdca5b265a1b183efa54a0f8e708b31d93ae;hpb=064562360a310f08592d41e9fceb3404932c4a04;p=ghc-hetmet.git diff --git a/rts/Trace.c b/rts/Trace.c index 20debdc..53fc25a 100644 --- a/rts/Trace.c +++ b/rts/Trace.c @@ -9,16 +9,18 @@ // external headers #include "Rts.h" -#ifdef TRACING - // internal headers #include "Trace.h" + +#ifdef TRACING + #include "GetTime.h" #include "Stats.h" #include "eventlog/EventLog.h" #include "Threads.h" #include "Printer.h" +#ifdef DEBUG // debugging flags, set with +RTS -D int DEBUG_sched; int DEBUG_interp; @@ -36,6 +38,7 @@ int DEBUG_linker; int DEBUG_squeeze; int DEBUG_hpc; int DEBUG_sparks; +#endif // events int TRACE_sched; @@ -44,6 +47,8 @@ int TRACE_sched; static Mutex trace_utx; #endif +static rtsBool eventlog_enabled; + /* --------------------------------------------------------------------------- Starting up / shuttting down the tracing facilities --------------------------------------------------------------------------- */ @@ -59,7 +64,6 @@ void initTracing (void) class = RtsFlags.DebugFlags.name ? 1 : 0; DEBUG_FLAG(scheduler, DEBUG_sched); - DEBUG_FLAG(scheduler, TRACE_sched); // -Ds enabled all sched events DEBUG_FLAG(interpreter, DEBUG_interp); DEBUG_FLAG(weak, DEBUG_weak); @@ -76,22 +80,38 @@ void initTracing (void) DEBUG_FLAG(sparks, DEBUG_sparks); #endif -#define TRACE_FLAG(name, class) \ - class = RtsFlags.TraceFlags.name ? 1 : 0; + // -Ds turns on scheduler tracing too + TRACE_sched = + RtsFlags.TraceFlags.scheduler || + RtsFlags.DebugFlags.scheduler; - TRACE_FLAG(scheduler, TRACE_sched); + eventlog_enabled = RtsFlags.TraceFlags.tracing == TRACE_EVENTLOG; - initEventLogging(); + if (eventlog_enabled) { + initEventLogging(); + } } void endTracing (void) { - endEventLogging(); + if (eventlog_enabled) { + endEventLogging(); + } } void freeTracing (void) { - freeEventLogging(); + if (eventlog_enabled) { + freeEventLogging(); + } +} + +void resetTracing (void) +{ + if (eventlog_enabled) { + abortEventLogging(); // abort eventlog inherited from parent + initEventLogging(); // child starts its own eventlog + } } /* --------------------------------------------------------------------------- @@ -182,8 +202,17 @@ static void traceSchedEvent_stderr (Capability *cap, EventTypeNum tag, case EVENT_GC_END: // (cap) debugBelch("cap %d: finished GC\n", cap->no); break; + case EVENT_GC_IDLE: // (cap) + debugBelch("cap %d: GC idle\n", cap->no); + break; + case EVENT_GC_WORK: // (cap) + debugBelch("cap %d: GC working\n", cap->no); + break; + case EVENT_GC_DONE: // (cap) + debugBelch("cap %d: GC done\n", cap->no); + break; default: - debugBelch("cap %2d: thread %lu: event %d\n\n", + debugBelch("cap %d: thread %lu: event %d\n\n", cap->no, (lnat)tso->id, tag); break; } @@ -196,7 +225,7 @@ void traceSchedEvent_ (Capability *cap, EventTypeNum tag, StgTSO *tso, StgWord64 other) { #ifdef DEBUG - if (RtsFlags.TraceFlags.trace_stderr) { + if (RtsFlags.TraceFlags.tracing == TRACE_STDERR) { traceSchedEvent_stderr(cap, tag, tso, other); } else #endif @@ -205,13 +234,25 @@ void traceSchedEvent_ (Capability *cap, EventTypeNum tag, } } +void traceEvent_ (Capability *cap, EventTypeNum tag) +{ +#ifdef DEBUG + if (RtsFlags.TraceFlags.tracing == TRACE_STDERR) { + traceSchedEvent_stderr(cap, tag, 0, 0); + } else +#endif + { + postEvent(cap,tag); + } +} + #ifdef DEBUG static void traceCap_stderr(Capability *cap, char *msg, va_list ap) { ACQUIRE_LOCK(&trace_utx); tracePreface(); - debugBelch("cap %2d: ", cap->no); + debugBelch("cap %d: ", cap->no); vdebugBelch(msg,ap); debugBelch("\n"); @@ -225,7 +266,7 @@ void traceCap_(Capability *cap, char *msg, ...) va_start(ap,msg); #ifdef DEBUG - if (RtsFlags.TraceFlags.trace_stderr) { + if (RtsFlags.TraceFlags.tracing == TRACE_STDERR) { traceCap_stderr(cap, msg, ap); } else #endif @@ -255,7 +296,7 @@ void trace_(char *msg, ...) va_start(ap,msg); #ifdef DEBUG - if (RtsFlags.TraceFlags.trace_stderr) { + if (RtsFlags.TraceFlags.tracing == TRACE_STDERR) { trace_stderr(msg, ap); } else #endif @@ -266,10 +307,33 @@ void trace_(char *msg, ...) va_end(ap); } +static void traceFormatUserMsg(Capability *cap, char *msg, ...) +{ + va_list ap; + va_start(ap,msg); + +#ifdef DEBUG + if (RtsFlags.TraceFlags.tracing == TRACE_STDERR) { + traceCap_stderr(cap, msg, ap); + } else +#endif + { + if (eventlog_enabled) { + postUserMsg(cap, msg, ap); + } + } + dtraceUserMsg(cap->no, msg); +} + +void traceUserMsg(Capability *cap, char *msg) +{ + traceFormatUserMsg(cap, "%s", msg); +} + void traceThreadStatus_ (StgTSO *tso USED_IF_DEBUG) { #ifdef DEBUG - if (RtsFlags.TraceFlags.trace_stderr) { + if (RtsFlags.TraceFlags.tracing == TRACE_STDERR) { printThreadStatus(tso); } else #endif @@ -299,3 +363,15 @@ void traceEnd (void) #endif /* DEBUG */ #endif /* TRACING */ + +// If DTRACE is enabled, but neither DEBUG nor TRACING, we need a C land +// wrapper for the user-msg probe (as we can't expand that in PrimOps.cmm) +// +#if !defined(DEBUG) && !defined(TRACING) && defined(DTRACE) + +void dtraceUserMsgWrapper(Capability *cap, char *msg) +{ + dtraceUserMsg(cap->no, msg); +} + +#endif /* !defined(DEBUG) && !defined(TRACING) && defined(DTRACE) */