Use snwprintf instead of swprintf in rts/Linker.c.
[ghc.git] / rts / Trace.h
index 18856d9..31aefcb 100644 (file)
@@ -114,6 +114,16 @@ void traceSchedEvent_ (Capability *cap, EventTypeNum tag,
 void traceGcEvent_ (Capability *cap, EventTypeNum tag);
 
 /* 
+ * Record a GC event at the explicitly given timestamp
+ */
+#define traceGcEventAtT(cap, ts, tag)   \
+    if (RTS_UNLIKELY(TRACE_gc)) {       \
+        traceGcEventAtT_(cap, ts, tag); \
+    }
+
+void traceGcEventAtT_ (Capability *cap, StgWord64 ts, EventTypeNum tag);
+
+/* 
  * Record a heap event
  */
 #define traceHeapEvent(cap, tag, heap_capset, info1) \
@@ -123,24 +133,24 @@ void traceGcEvent_ (Capability *cap, EventTypeNum tag);
 void traceHeapEvent_ (Capability   *cap,
                       EventTypeNum  tag,
                       CapsetID      heap_capset,
-                      lnat          info1);
+                      W_          info1);
 
 void traceEventHeapInfo_ (CapsetID    heap_capset,
                           nat         gens,
-                          lnat        maxHeapSize,
-                          lnat        allocAreaSize,
-                          lnat        mblockSize,
-                          lnat        blockSize);
+                          W_        maxHeapSize,
+                          W_        allocAreaSize,
+                          W_        mblockSize,
+                          W_        blockSize);
 
 void traceEventGcStats_  (Capability *cap,
                           CapsetID    heap_capset,
                           nat         gen,
-                          lnat        copied,
-                          lnat        slop,
-                          lnat        fragmentation,
+                          W_        copied,
+                          W_        slop,
+                          W_        fragmentation,
                           nat         par_n_threads,
-                          lnat        par_max_copied,
-                          lnat        par_tot_copied);
+                          W_        par_max_copied,
+                          W_        par_tot_copied);
 
 /* 
  * Record a spark event
@@ -187,6 +197,12 @@ void trace_(char *msg, ...);
  */
 void traceUserMsg(Capability *cap, char *msg);
 
+/* 
+ * A marker event emitted by the program
+ * Used by Debug.Trace.{traceMarker, traceMarkerIO}
+ */
+void traceUserMarker(Capability *cap, char *msg);
+
 /*
  * An event to record a Haskell thread's label/name
  * Used by GHC.Conc.labelThread
@@ -252,11 +268,21 @@ void traceSparkCounters_ (Capability *cap,
                           SparkCounters counters,
                           StgWord remaining);
 
+void traceTaskCreate_ (Task       *task,
+                       Capability *cap);
+
+void traceTaskMigrate_ (Task       *task,
+                        Capability *cap,
+                        Capability *new_cap);
+
+void traceTaskDelete_ (Task       *task);
+
 #else /* !TRACING */
 
 #define traceSchedEvent(cap, tag, tso, other) /* nothing */
 #define traceSchedEvent2(cap, tag, tso, other, info) /* nothing */
 #define traceGcEvent(cap, tag) /* nothing */
+#define traceGcEventAtT(cap, ts, tag) /* nothing */
 #define traceEventGcStats_(cap, heap_capset, gen, \
                            copied, slop, fragmentation, \
                            par_n_threads, par_max_copied, par_tot_copied) /* nothing */
@@ -278,6 +304,9 @@ INLINE_HEADER void traceEventStartup_ (int n_caps STG_UNUSED) {};
 #define traceWallClockTime_() /* nothing */
 #define traceOSProcessInfo_() /* nothing */
 #define traceSparkCounters_(cap, counters, remaining) /* nothing */
+#define traceTaskCreate_(taskID, cap) /* nothing */
+#define traceTaskMigrate_(taskID, cap, new_cap) /* nothing */
+#define traceTaskDelete_(taskID) /* nothing */
 
 #endif /* TRACING */
 
@@ -287,6 +316,7 @@ INLINE_HEADER void traceEventStartup_ (int n_caps STG_UNUSED) {};
 #if !defined(DEBUG) && !defined(TRACING) && defined(DTRACE)
 
 void dtraceUserMsgWrapper(Capability *cap, char *msg);
+void dtraceUserMarkerWrapper(Capability *cap, char *msg);
 
 #endif /* !defined(DEBUG) && !defined(TRACING) && defined(DTRACE) */
 
@@ -333,12 +363,16 @@ INLINE_HEADER void dtraceStartup (int num_caps) {
     HASKELLEVENT_CAP_DISABLE(cap)
 #define dtraceUserMsg(cap, msg)                         \
     HASKELLEVENT_USER_MSG(cap, msg)
+#define dtraceUserMarker(cap, msg)                      \
+    HASKELLEVENT_USER_MARKER(cap, msg)
 #define dtraceGcIdle(cap)                               \
     HASKELLEVENT_GC_IDLE(cap)
 #define dtraceGcWork(cap)                               \
     HASKELLEVENT_GC_WORK(cap)
 #define dtraceGcDone(cap)                               \
     HASKELLEVENT_GC_DONE(cap)
+#define dtraceGcGlobalSync(cap)                         \
+    HASKELLEVENT_GC_GLOBAL_SYNC(cap)
 #define dtraceEventGcStats(heap_capset, gens,           \
                            copies, slop, fragmentation, \
                            par_n_threads,               \
@@ -348,7 +382,7 @@ INLINE_HEADER void dtraceStartup (int num_caps) {
                            copies, slop, fragmentation, \
                            par_n_threads,               \
                            par_max_copied,              \
-                           par_tot_copied)              \
+                           par_tot_copied)
 #define dtraceHeapInfo(heap_capset, gens,               \
                        maxHeapSize, allocAreaSize,      \
                        mblockSize, blockSize)           \
@@ -360,10 +394,9 @@ INLINE_HEADER void dtraceStartup (int num_caps) {
     HASKELLEVENT_HEAP_ALLOCATED(cap, heap_capset,       \
                                 allocated)
 #define dtraceEventHeapSize(heap_capset, size)          \
-    HASKELLEVENT_HEAP_LIVE(heap_capset, size)
+    HASKELLEVENT_HEAP_SIZE(heap_capset, size)
 #define dtraceEventHeapLive(heap_capset, live)          \
     HASKELLEVENT_HEAP_LIVE(heap_capset, live)
-
 #define dtraceCapsetCreate(capset, capset_type)         \
     HASKELLEVENT_CAPSET_CREATE(capset, capset_type)
 #define dtraceCapsetDelete(capset)                      \
@@ -388,6 +421,12 @@ INLINE_HEADER void dtraceStartup (int num_caps) {
     HASKELLEVENT_SPARK_FIZZLE(cap)
 #define dtraceSparkGc(cap)                              \
     HASKELLEVENT_SPARK_GC(cap)
+#define dtraceTaskCreate(taskID, cap, tid)              \
+    HASKELLEVENT_TASK_CREATE(taskID, cap, tid)
+#define dtraceTaskMigrate(taskID, cap, new_cap)         \
+    HASKELLEVENT_TASK_MIGRATE(taskID, cap, new_cap)
+#define dtraceTaskDelete(taskID)                        \
+    HASKELLEVENT_TASK_DELETE(taskID)
 
 #else /* !defined(DTRACE) */
 
@@ -405,9 +444,11 @@ INLINE_HEADER void dtraceStartup (int num_caps) {
 #define dtraceThreadLabel(cap, tso, label)              /* nothing */
 INLINE_HEADER void dtraceStartup (int num_caps STG_UNUSED) {};
 #define dtraceUserMsg(cap, msg)                         /* nothing */
+#define dtraceUserMarker(cap, msg)                      /* nothing */
 #define dtraceGcIdle(cap)                               /* nothing */
 #define dtraceGcWork(cap)                               /* nothing */
 #define dtraceGcDone(cap)                               /* nothing */
+#define dtraceGcGlobalSync(cap)                         /* nothing */
 #define dtraceEventGcStats(heap_capset, gens,           \
                            copies, slop, fragmentation, \
                            par_n_threads,               \
@@ -436,6 +477,9 @@ INLINE_HEADER void dtraceStartup (int num_caps STG_UNUSED) {};
 #define dtraceSparkSteal(cap, victim_cap)               /* nothing */
 #define dtraceSparkFizzle(cap)                          /* nothing */
 #define dtraceSparkGc(cap)                              /* nothing */
+#define dtraceTaskCreate(taskID, cap, tid)              /* nothing */
+#define dtraceTaskMigrate(taskID, cap, new_cap)         /* nothing */
+#define dtraceTaskDelete(taskID)                        /* nothing */
 
 #endif
 
@@ -549,12 +593,26 @@ INLINE_HEADER void traceEventGcStart(Capability *cap STG_UNUSED)
     dtraceGcStart((EventCapNo)cap->no);
 }
 
+INLINE_HEADER void traceEventGcStartAtT(Capability *cap STG_UNUSED,
+                                        StgWord64   ts  STG_UNUSED)
+{
+    traceGcEventAtT(cap, ts, EVENT_GC_START);
+    dtraceGcStart((EventCapNo)cap->no);
+}
+
 INLINE_HEADER void traceEventGcEnd(Capability *cap STG_UNUSED)
 {
     traceGcEvent(cap, EVENT_GC_END);
     dtraceGcEnd((EventCapNo)cap->no);
 }
 
+INLINE_HEADER void traceEventGcEndAtT(Capability *cap STG_UNUSED,
+                                      StgWord64   ts  STG_UNUSED)
+{
+    traceGcEventAtT(cap, ts, EVENT_GC_END);
+    dtraceGcEnd((EventCapNo)cap->no);
+}
+
 INLINE_HEADER void traceEventRequestSeqGc(Capability *cap STG_UNUSED)
 {
     traceGcEvent(cap, EVENT_REQUEST_SEQ_GC);
@@ -585,32 +643,38 @@ INLINE_HEADER void traceEventGcDone(Capability *cap STG_UNUSED)
     dtraceGcDone((EventCapNo)cap->no);
 }
 
+INLINE_HEADER void traceEventGcGlobalSync(Capability *cap STG_UNUSED)
+{
+    traceGcEvent(cap, EVENT_GC_GLOBAL_SYNC);
+    dtraceGcGlobalSync((EventCapNo)cap->no);
+}
+
 INLINE_HEADER void traceEventGcStats(Capability *cap            STG_UNUSED,
                                      CapsetID    heap_capset    STG_UNUSED,
                                      nat         gen            STG_UNUSED,
-                                     lnat        copied         STG_UNUSED,
-                                     lnat        slop           STG_UNUSED,
-                                     lnat        fragmentation  STG_UNUSED,
+                                     W_        copied         STG_UNUSED,
+                                     W_        slop           STG_UNUSED,
+                                     W_        fragmentation  STG_UNUSED,
                                      nat         par_n_threads  STG_UNUSED,
-                                     lnat        par_max_copied STG_UNUSED,
-                                     lnat        par_tot_copied STG_UNUSED)
+                                     W_        par_max_copied STG_UNUSED,
+                                     W_        par_tot_copied STG_UNUSED)
 {
     if (RTS_UNLIKELY(TRACE_gc)) {
         traceEventGcStats_(cap, heap_capset, gen,
                            copied, slop, fragmentation,
                            par_n_threads, par_max_copied, par_tot_copied);
     }
-    dtraceEventGcStats(heap_capset, gens,
-                       copies, slop, fragmentation,
+    dtraceEventGcStats(heap_capset, gen,
+                       copied, slop, fragmentation,
                        par_n_threads, par_max_copied, par_tot_copied);
 }
 
 INLINE_HEADER void traceEventHeapInfo(CapsetID    heap_capset   STG_UNUSED,
                                       nat         gens          STG_UNUSED,
-                                      lnat        maxHeapSize   STG_UNUSED,
-                                      lnat        allocAreaSize STG_UNUSED,
-                                      lnat        mblockSize    STG_UNUSED,
-                                      lnat        blockSize     STG_UNUSED)
+                                      W_        maxHeapSize   STG_UNUSED,
+                                      W_        allocAreaSize STG_UNUSED,
+                                      W_        mblockSize    STG_UNUSED,
+                                      W_        blockSize     STG_UNUSED)
 {
     if (RTS_UNLIKELY(TRACE_gc)) {
         traceEventHeapInfo_(heap_capset, gens,
@@ -624,7 +688,7 @@ INLINE_HEADER void traceEventHeapInfo(CapsetID    heap_capset   STG_UNUSED,
 
 INLINE_HEADER void traceEventHeapAllocated(Capability *cap         STG_UNUSED,
                                            CapsetID    heap_capset STG_UNUSED,
-                                           lnat        allocated   STG_UNUSED)
+                                           W_        allocated   STG_UNUSED)
 {
     traceHeapEvent(cap, EVENT_HEAP_ALLOCATED, heap_capset, allocated);
     dtraceEventHeapAllocated((EventCapNo)cap->no, heap_capset, allocated);
@@ -632,7 +696,7 @@ INLINE_HEADER void traceEventHeapAllocated(Capability *cap         STG_UNUSED,
 
 INLINE_HEADER void traceEventHeapSize(Capability *cap         STG_UNUSED,
                                       CapsetID    heap_capset STG_UNUSED,
-                                      lnat        heap_size   STG_UNUSED)
+                                      W_        heap_size   STG_UNUSED)
 {
     traceHeapEvent(cap, EVENT_HEAP_SIZE, heap_capset, heap_size);
     dtraceEventHeapSize(heap_capset, heap_size);
@@ -640,7 +704,7 @@ INLINE_HEADER void traceEventHeapSize(Capability *cap         STG_UNUSED,
 
 INLINE_HEADER void traceEventHeapLive(Capability *cap         STG_UNUSED,
                                       CapsetID    heap_capset STG_UNUSED,
-                                      lnat        heap_live   STG_UNUSED)
+                                      W_        heap_live   STG_UNUSED)
 {
     traceHeapEvent(cap, EVENT_HEAP_LIVE, heap_capset, heap_live);
     dtraceEventHeapLive(heap_capset, heap_live);
@@ -770,6 +834,49 @@ INLINE_HEADER void traceEventSparkGC(Capability *cap STG_UNUSED)
     dtraceSparkGc((EventCapNo)cap->no);
 }
 
+INLINE_HEADER void traceTaskCreate(Task       *task STG_UNUSED,
+                                   Capability *cap  STG_UNUSED)
+{
+    ASSERT(task->cap == cap);
+    // TODO: asserting task->cap == NULL would be much stronger
+    // (the intention being that the task structure is just created and empty)
+    // but would require large changes of traceTaskCreate calls.
+    ASSERT(cap != NULL);
+    // A new task gets associated with a cap. We also record
+    // the kernel thread id of the task, which should never change.
+    if (RTS_UNLIKELY(TRACE_sched)) {
+        traceTaskCreate_(task, cap);
+    }
+    dtraceTaskCreate(serialisableTaskId(task),
+                     (EventCapNo)cap->no,
+                     kernelThreadId());
+}
+
+INLINE_HEADER void traceTaskMigrate(Task       *task    STG_UNUSED,
+                                    Capability *cap     STG_UNUSED,
+                                    Capability *new_cap STG_UNUSED)
+{
+    ASSERT(task->cap == cap);
+    ASSERT(cap != NULL);
+    ASSERT(cap != new_cap);
+    ASSERT(new_cap != NULL);
+    // A task migrates from a cap to another.
+    if (RTS_UNLIKELY(TRACE_sched)) {
+        traceTaskMigrate_(task, cap, new_cap);
+    }
+    dtraceTaskMigrate(serialisableTaskId(task), (EventCapNo)cap->no,
+                                                (EventCapNo)new_cap->no);
+}
+
+INLINE_HEADER void traceTaskDelete(Task *task STG_UNUSED)
+{
+    ASSERT(task->cap != NULL);
+    if (RTS_UNLIKELY(TRACE_sched)) {
+        traceTaskDelete_(task);
+    }
+    dtraceTaskDelete(serialisableTaskId(task));
+}
+
 #include "EndPrivate.h"
 
 #endif /* TRACE_H */