include spark counters in the sparks trace class
[ghc.git] / rts / Trace.h
index f253280..34efdf6 100644 (file)
@@ -62,6 +62,7 @@ extern int DEBUG_sparks;
 
 // events
 extern int TRACE_sched;
+extern int TRACE_spark;
 
 // -----------------------------------------------------------------------------
 // Posting events
@@ -93,6 +94,11 @@ void traceEnd (void);
         traceSchedEvent_(cap, tag, tso, info1, info2); \
     }
 
+#define traceSparkEvent(cap, tag, tso, other)   \
+    if (RTS_UNLIKELY(TRACE_spark)) {            \
+        traceSchedEvent_(cap, tag, tso, other, 0); \
+    }
+
 void traceSchedEvent_ (Capability *cap, EventTypeNum tag, 
                        StgTSO *tso, StgWord info1, StgWord info2);
 
@@ -182,18 +188,27 @@ void traceCapsetModify_ (EventTypeNum tag,
                          CapsetID capset,
                          StgWord32 other);
 
+void traceOSProcessInfo_ (void);
+
+void traceSparkCounters_ (Capability *cap,
+                          SparkCounters counters,
+                          StgWord remaining);
+
 #else /* !TRACING */
 
 #define traceSchedEvent(cap, tag, tso, other) /* nothing */
 #define traceSchedEvent2(cap, tag, tso, other, info) /* nothing */
+#define traceSparkEvent(cap, tag, tso, other) /* nothing */
 #define traceEvent(cap, tag) /* nothing */
 #define traceCap(class, cap, msg, ...) /* nothing */
 #define trace(class, msg, ...) /* nothing */
 #define debugTrace(class, str, ...) /* nothing */
 #define debugTraceCap(class, cap, str, ...) /* nothing */
 #define traceThreadStatus(class, tso) /* nothing */
-#define traceEventStartup_(n_caps) /* nothing */
+INLINE_HEADER void traceEventStartup_ (int n_caps STG_UNUSED) {};
 #define traceCapsetModify_(tag, capset, other) /* nothing */
+#define traceOSProcessInfo_() /* nothing */
+#define traceSparkCounters_(cap, counters, remaining) /* nothing */
 
 #endif /* TRACING */
 
@@ -240,8 +255,9 @@ void dtraceUserMsgWrapper(Capability *cap, char *msg);
     HASKELLEVENT_REQUEST_PAR_GC(cap)
 #define dtraceCreateSparkThread(cap, spark_tid)         \
     HASKELLEVENT_CREATE_SPARK_THREAD(cap, spark_tid)
-#define dtraceStartup(num_caps)                         \
-    HASKELLEVENT_STARTUP(num_caps)
+INLINE_HEADER void dtraceStartup (int num_caps) {
+    HASKELLEVENT_STARTUP(num_caps);
+}
 #define dtraceUserMsg(cap, msg)                         \
     HASKELLEVENT_USER_MSG(cap, msg)
 #define dtraceGcIdle(cap)                               \
@@ -258,6 +274,8 @@ void dtraceUserMsgWrapper(Capability *cap, char *msg);
     HASKELLEVENT_CAPSET_ASSIGN_CAP(capset, capno)
 #define dtraceCapsetRemoveCap(capset, capno)            \
     HASKELLEVENT_CAPSET_REMOVE_CAP(capset, capno)
+#define dtraceSparkCounters(cap, a, b, c, d, e, f, g) \
+    HASKELLEVENT_SPARK_COUNTERS(cap, a, b, c, d, e, f, g)
 
 #else /* !defined(DTRACE) */
 
@@ -275,7 +293,7 @@ void dtraceUserMsgWrapper(Capability *cap, char *msg);
 #define dtraceRequestSeqGc(cap)                         /* nothing */
 #define dtraceRequestParGc(cap)                         /* nothing */
 #define dtraceCreateSparkThread(cap, spark_tid)         /* nothing */
-#define dtraceStartup(num_caps)                         /* nothing */
+INLINE_HEADER void dtraceStartup (int num_caps STG_UNUSED) {};
 #define dtraceUserMsg(cap, msg)                         /* nothing */
 #define dtraceGcIdle(cap)                               /* nothing */
 #define dtraceGcWork(cap)                               /* nothing */
@@ -284,6 +302,7 @@ void dtraceUserMsgWrapper(Capability *cap, char *msg);
 #define dtraceCapsetDelete(capset)                      /* nothing */
 #define dtraceCapsetAssignCap(capset, capno)            /* nothing */
 #define dtraceCapsetRemoveCap(capset, capno)            /* nothing */
+#define dtraceSparkCounters(cap, a, b, c, d, e, f, g)   /* nothing */
 
 #endif
 
@@ -348,22 +367,6 @@ INLINE_HEADER void traceEventMigrateThread(Capability *cap     STG_UNUSED,
                         (EventCapNo)new_cap);
 }
 
-INLINE_HEADER void traceEventRunSpark(Capability *cap STG_UNUSED, 
-                                      StgTSO     *tso STG_UNUSED)
-{
-    traceSchedEvent(cap, EVENT_RUN_SPARK, tso, 0);
-    dtraceRunSpark((EventCapNo)cap->no, (EventThreadID)tso->id);
-}
-
-INLINE_HEADER void traceEventStealSpark(Capability *cap        STG_UNUSED, 
-                                        StgTSO     *tso        STG_UNUSED,
-                                        nat         victim_cap STG_UNUSED)
-{
-    traceSchedEvent(cap, EVENT_STEAL_SPARK, tso, victim_cap);
-    dtraceStealSpark((EventCapNo)cap->no, (EventThreadID)tso->id,
-                     (EventCapNo)victim_cap);
-}
-
 INLINE_HEADER void traceEventShutdown(Capability *cap STG_UNUSED)
 {
     traceSchedEvent(cap, EVENT_SHUTDOWN, 0, 0);
@@ -403,10 +406,26 @@ INLINE_HEADER void traceEventRequestParGc(Capability *cap STG_UNUSED)
     dtraceRequestParGc((EventCapNo)cap->no);
 }
 
+INLINE_HEADER void traceEventRunSpark(Capability *cap STG_UNUSED, 
+                                      StgTSO     *tso STG_UNUSED)
+{
+    traceSparkEvent(cap, EVENT_RUN_SPARK, tso, 0);
+    dtraceRunSpark((EventCapNo)cap->no, (EventThreadID)tso->id);
+}
+
+INLINE_HEADER void traceEventStealSpark(Capability *cap        STG_UNUSED, 
+                                        StgTSO     *tso        STG_UNUSED,
+                                        nat         victim_cap STG_UNUSED)
+{
+    traceSparkEvent(cap, EVENT_STEAL_SPARK, tso, victim_cap);
+    dtraceStealSpark((EventCapNo)cap->no, (EventThreadID)tso->id,
+                     (EventCapNo)victim_cap);
+}
+
 INLINE_HEADER void traceEventCreateSparkThread(Capability  *cap      STG_UNUSED, 
                                                StgThreadID spark_tid STG_UNUSED)
 {
-    traceSchedEvent(cap, EVENT_CREATE_SPARK_THREAD, 0, spark_tid);
+    traceSparkEvent(cap, EVENT_CREATE_SPARK_THREAD, 0, spark_tid);
     dtraceCreateSparkThread((EventCapNo)cap->no, (EventThreadID)spark_tid);
 }
 
@@ -414,7 +433,7 @@ INLINE_HEADER void traceEventStartup(void)
 {
     int n_caps;
 #ifdef THREADED_RTS
-    // XXX n_capabilities hasn't been initislised yet
+    // XXX n_capabilities hasn't been initialised yet
     n_caps = RtsFlags.ParFlags.nNodes;
 #else
     n_caps = 1;
@@ -469,6 +488,31 @@ INLINE_HEADER void traceCapsetRemoveCap(CapsetID capset STG_UNUSED,
     dtraceCapsetRemoveCap(capset, capno);
 }
 
+INLINE_HEADER void traceOSProcessInfo(void)
+{
+    traceOSProcessInfo_();
+    /* Note: no DTrace equivalent because all this OS process info
+     * is available to DTrace directly */
+}
+
+INLINE_HEADER void traceSparkCounters(Capability *cap STG_UNUSED)
+{
+#ifdef THREADED_RTS
+    if (RTS_UNLIKELY(TRACE_spark)) {
+        traceSparkCounters_(cap, cap->spark_stats, sparkPoolSize(cap->sparks));
+    }
+#endif
+    dtraceSparkCounters((EventCapNo)cap->no,
+                        cap->spark_stats.created,
+                        cap->spark_stats.dud,
+                        cap->spark_stats.overflowed,
+                        cap->spark_stats.converted,
+                        cap->spark_stats.gcd,
+                        cap->spark_stats.fizzled,
+                        sparkPoolSize(cap->sparks));
+}
+
+
 #include "EndPrivate.h"
 
 #endif /* TRACE_H */