fix #3910
[ghc-hetmet.git] / rts / Trace.c
index 7cfb78c..53fc25a 100644 (file)
@@ -9,10 +9,11 @@
 // external headers
 #include "Rts.h"
 
-#ifdef TRACING
-
 // internal headers
 #include "Trace.h"
+
+#ifdef TRACING
+
 #include "GetTime.h"
 #include "Stats.h"
 #include "eventlog/EventLog.h"
@@ -105,6 +106,14 @@ void freeTracing (void)
     }
 }
 
+void resetTracing (void)
+{
+    if (eventlog_enabled) {
+        abortEventLogging(); // abort eventlog inherited from parent
+        initEventLogging(); // child starts its own eventlog
+    }
+}
+
 /* ---------------------------------------------------------------------------
    Emitting trace messages/events
  --------------------------------------------------------------------------- */
@@ -203,7 +212,7 @@ static void traceSchedEvent_stderr (Capability *cap, EventTypeNum tag,
         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;
     }
@@ -243,7 +252,7 @@ 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");
 
@@ -298,18 +307,27 @@ void trace_(char *msg, ...)
     va_end(ap);
 }
 
-void traceUserMsg(Capability *cap, char *msg)
+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, NULL);
+        traceCap_stderr(cap, msg, ap);
     } else
 #endif
     {
         if (eventlog_enabled) {
-            postUserMsg(cap, msg);
+            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)
@@ -345,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) */