// external headers
#include "Rts.h"
-#ifdef TRACING
-
// internal headers
#include "Trace.h"
+
+#ifdef TRACING
+
#include "GetTime.h"
#include "Stats.h"
#include "eventlog/EventLog.h"
initMutex(&trace_utx);
#endif
-#define TRACE_FLAG(name, class) \
- class = RtsFlags.TraceFlags.name ? 1 : 0;
-
- TRACE_FLAG(scheduler, TRACE_sched);
-
#ifdef DEBUG
#define DEBUG_FLAG(name, class) \
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);
DEBUG_FLAG(sparks, DEBUG_sparks);
#endif
- eventlog_enabled = !RtsFlags.TraceFlags.trace_stderr && (
- TRACE_sched
-#ifdef DEBUG
- | DEBUG_sched
- | DEBUG_interp
- | DEBUG_weak
- | DEBUG_gccafs
- | DEBUG_gc
- | DEBUG_block_alloc
- | DEBUG_sanity
- | DEBUG_stable
- | DEBUG_stm
- | DEBUG_prof
- | DEBUG_linker
- | DEBUG_squeeze
- | DEBUG_hpc
-#endif
- );
+ // -Ds turns on scheduler tracing too
+ TRACE_sched =
+ RtsFlags.TraceFlags.scheduler ||
+ RtsFlags.DebugFlags.scheduler;
+
+ eventlog_enabled = RtsFlags.TraceFlags.tracing == TRACE_EVENTLOG;
if (eventlog_enabled) {
initEventLogging();
}
}
+void resetTracing (void)
+{
+ if (eventlog_enabled) {
+ abortEventLogging(); // abort eventlog inherited from parent
+ initEventLogging(); // child starts its own eventlog
+ }
+}
+
/* ---------------------------------------------------------------------------
Emitting trace messages/events
--------------------------------------------------------------------------- */
[ThreadYielding] = "yielding",
[ThreadBlocked] = "blocked",
[ThreadFinished] = "finished",
- [THREAD_SUSPENDED_FOREIGN_CALL] = "suspended while making a foreign call"
+ [THREAD_SUSPENDED_FOREIGN_CALL] = "suspended while making a foreign call",
+ [6 + BlockedOnMVar] = "blocked on an MVar",
+ [6 + BlockedOnBlackHole] = "blocked on a black hole",
+ [6 + BlockedOnRead] = "blocked on a read operation",
+ [6 + BlockedOnWrite] = "blocked on a write operation",
+ [6 + BlockedOnDelay] = "blocked on a delay operation",
+ [6 + BlockedOnSTM] = "blocked on STM",
+ [6 + BlockedOnDoProc] = "blocked on asyncDoProc",
+ [6 + BlockedOnCCall] = "blocked on a foreign call",
+ [6 + BlockedOnCCall_Interruptible] = "blocked on a foreign call (interruptible)",
+ [6 + BlockedOnMsgThrowTo] = "blocked on throwTo",
+ [6 + ThreadMigrating] = "migrating"
};
#endif
#ifdef DEBUG
static void traceSchedEvent_stderr (Capability *cap, EventTypeNum tag,
StgTSO *tso,
- StgWord64 other STG_UNUSED)
+ StgWord info1 STG_UNUSED,
+ StgWord info2 STG_UNUSED)
{
ACQUIRE_LOCK(&trace_utx);
break;
case EVENT_CREATE_SPARK_THREAD: // (cap, spark_thread)
debugBelch("cap %d: creating spark thread %lu\n",
- cap->no, (long)other);
+ cap->no, (long)info1);
break;
case EVENT_MIGRATE_THREAD: // (cap, thread, new_cap)
debugBelch("cap %d: thread %lu migrating to cap %d\n",
- cap->no, (lnat)tso->id, (int)other);
+ cap->no, (lnat)tso->id, (int)info1);
break;
case EVENT_STEAL_SPARK: // (cap, thread, victim_cap)
debugBelch("cap %d: thread %lu stealing a spark from cap %d\n",
- cap->no, (lnat)tso->id, (int)other);
+ cap->no, (lnat)tso->id, (int)info1);
break;
- case EVENT_THREAD_WAKEUP: // (cap, thread, other_cap)
+ case EVENT_THREAD_WAKEUP: // (cap, thread, info1_cap)
debugBelch("cap %d: waking up thread %lu on cap %d\n",
- cap->no, (lnat)tso->id, (int)other);
+ cap->no, (lnat)tso->id, (int)info1);
break;
case EVENT_STOP_THREAD: // (cap, thread, status)
- debugBelch("cap %d: thread %lu stopped (%s)\n",
- cap->no, (lnat)tso->id, thread_stop_reasons[other]);
+ if (info1 == 6 + BlockedOnBlackHole) {
+ debugBelch("cap %d: thread %lu stopped (blocked on black hole owned by thread %lu)\n",
+ cap->no, (lnat)tso->id, (long)info2);
+ } else {
+ debugBelch("cap %d: thread %lu stopped (%s)\n",
+ cap->no, (lnat)tso->id, thread_stop_reasons[info1]);
+ }
break;
case EVENT_SHUTDOWN: // (cap)
debugBelch("cap %d: shutting down\n", cap->no);
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;
}
#endif
void traceSchedEvent_ (Capability *cap, EventTypeNum tag,
- StgTSO *tso, StgWord64 other)
+ StgTSO *tso, StgWord info1, StgWord info2)
+{
+#ifdef DEBUG
+ if (RtsFlags.TraceFlags.tracing == TRACE_STDERR) {
+ traceSchedEvent_stderr(cap, tag, tso, info1, info2);
+ } else
+#endif
+ {
+ postSchedEvent(cap,tag,tso ? tso->id : 0, info1, info2);
+ }
+}
+
+void traceEvent_ (Capability *cap, EventTypeNum tag)
{
#ifdef DEBUG
- if (RtsFlags.TraceFlags.trace_stderr) {
- traceSchedEvent_stderr(cap, tag, tso, other);
+ if (RtsFlags.TraceFlags.tracing == TRACE_STDERR) {
+ traceSchedEvent_stderr(cap, tag, 0, 0, 0);
} else
#endif
{
- postSchedEvent(cap,tag,tso ? tso->id : 0,other);
+ postEvent(cap,tag);
}
}
ACQUIRE_LOCK(&trace_utx);
tracePreface();
- debugBelch("cap %2d: ", cap->no);
+ debugBelch("cap %d: ", cap->no);
vdebugBelch(msg,ap);
debugBelch("\n");
va_start(ap,msg);
#ifdef DEBUG
- if (RtsFlags.TraceFlags.trace_stderr) {
+ if (RtsFlags.TraceFlags.tracing == TRACE_STDERR) {
traceCap_stderr(cap, msg, ap);
} else
#endif
va_start(ap,msg);
#ifdef DEBUG
- if (RtsFlags.TraceFlags.trace_stderr) {
+ if (RtsFlags.TraceFlags.tracing == TRACE_STDERR) {
trace_stderr(msg, ap);
} else
#endif
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
#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) */