NCGMonad: Add MonadUnique NatM instance
[ghc.git] / rts / Trace.h
index 58ce43d..ccdad7a 100644 (file)
@@ -28,7 +28,7 @@ void initTracing (void);
 void endTracing  (void);
 void freeTracing (void);
 void resetTracing (void);
-void tracingAddCapapilities (nat from, nat to);
+void tracingAddCapapilities (uint32_t from, uint32_t to);
 
 #endif /* TRACING */
 
@@ -45,23 +45,23 @@ enum CapsetType { CapsetTypeCustom = CAPSET_TYPE_CUSTOM,
 // Message classes
 // -----------------------------------------------------------------------------
 
-// debugging flags, set with +RTS -D<something>
-extern int DEBUG_sched;
-extern int DEBUG_interp;
-extern int DEBUG_weak;
-extern int DEBUG_gccafs;
-extern int DEBUG_gc;
-extern int DEBUG_block_alloc;
-extern int DEBUG_sanity;
-extern int DEBUG_stable;
-extern int DEBUG_stm;
-extern int DEBUG_prof;
-extern int DEBUG_gran;
-extern int DEBUG_par;
-extern int DEBUG_linker;
-extern int DEBUG_squeeze;
-extern int DEBUG_hpc;
-extern int DEBUG_sparks;
+// shorthand for RtsFlags.DebugFlags.<blah>, useful with debugTrace()
+#define DEBUG_sched       RtsFlags.DebugFlags.scheduler
+#define DEBUG_interp      RtsFlags.DebugFlags.interp
+#define DEBUG_weak        RtsFlags.DebugFlags.weak
+#define DEBUG_gccafs      RtsFlags.DebugFlags.gccafs
+#define DEBUG_gc          RtsFlags.DebugFlags.gc
+#define DEBUG_block_alloc RtsFlags.DebugFlags.alloc
+#define DEBUG_sanity      RtsFlags.DebugFlags.sanity
+#define DEBUG_stable      RtsFlags.DebugFlags.stable
+#define DEBUG_stm         RtsFlags.DebugFlags.stm
+#define DEBUG_prof        RtsFlags.DebugFlags.prof
+#define DEBUG_gran        RtsFlags.DebugFlags.gran
+#define DEBUG_par         RtsFlags.DebugFlags.par
+#define DEBUG_linker      RtsFlags.DebugFlags.linker
+#define DEBUG_squeeze     RtsFlags.DebugFlags.squeeze
+#define DEBUG_hpc         RtsFlags.DebugFlags.hpc
+#define DEBUG_sparks      RtsFlags.DebugFlags.sparks
 
 // events
 extern int TRACE_sched;
@@ -69,6 +69,7 @@ extern int TRACE_gc;
 extern int TRACE_spark_sampled;
 extern int TRACE_spark_full;
 /* extern int TRACE_user; */  // only used in Trace.c
+extern int TRACE_cap;
 
 // -----------------------------------------------------------------------------
 // Posting events
@@ -77,7 +78,7 @@ extern int TRACE_spark_full;
 // the not-taken case to be as efficient as possible, a simple
 // test-and-jump, and with inline functions gcc seemed to move some of
 // the instructions from the branch up before the test.
-// 
+//
 // -----------------------------------------------------------------------------
 
 #ifdef DEBUG
@@ -87,7 +88,7 @@ void traceEnd (void);
 
 #ifdef TRACING
 
-/* 
+/*
  * Record a scheduler event
  */
 #define traceSchedEvent(cap, tag, tso, other)   \
@@ -100,10 +101,10 @@ void traceEnd (void);
         traceSchedEvent_(cap, tag, tso, info1, info2); \
     }
 
-void traceSchedEvent_ (Capability *cap, EventTypeNum tag, 
+void traceSchedEvent_ (Capability *cap, EventTypeNum tag,
                        StgTSO *tso, StgWord info1, StgWord info2);
 
-/* 
+/*
  * Record a GC event
  */
 #define traceGcEvent(cap, tag)    \
@@ -113,7 +114,7 @@ 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)   \
@@ -123,7 +124,7 @@ void traceGcEvent_ (Capability *cap, EventTypeNum tag);
 
 void traceGcEventAtT_ (Capability *cap, StgWord64 ts, EventTypeNum tag);
 
-/* 
+/*
  * Record a heap event
  */
 #define traceHeapEvent(cap, tag, heap_capset, info1) \
@@ -133,26 +134,26 @@ void traceGcEventAtT_ (Capability *cap, StgWord64 ts, 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);
+                          uint32_t  gens,
+                          W_        maxHeapSize,
+                          W_        allocAreaSize,
+                          W_        mblockSize,
+                          W_        blockSize);
 
 void traceEventGcStats_  (Capability *cap,
                           CapsetID    heap_capset,
-                          nat         gen,
-                          lnat        copied,
-                          lnat        slop,
-                          lnat        fragmentation,
-                          nat         par_n_threads,
-                          lnat        par_max_copied,
-                          lnat        par_tot_copied);
-
-/* 
+                          uint32_t  gen,
+                          W_        copied,
+                          W_        slop,
+                          W_        fragmentation,
+                          uint32_t  par_n_threads,
+                          W_        par_max_copied,
+                          W_        par_tot_copied);
+
+/*
  * Record a spark event
  */
 #define traceSparkEvent(cap, tag)         \
@@ -171,7 +172,7 @@ void traceSparkEvent_ (Capability *cap, EventTypeNum tag, StgWord info1);
 // ##__VA_ARGS syntax is a gcc extension, which allows the variable
 // argument list to be empty (see gcc docs for details).
 
-/* 
+/*
  * Emit a trace message on a particular Capability
  */
 #define traceCap(class, cap, msg, ...)          \
@@ -181,7 +182,7 @@ void traceSparkEvent_ (Capability *cap, EventTypeNum tag, StgWord info1);
 
 void traceCap_(Capability *cap, char *msg, ...);
 
-/* 
+/*
  * Emit a trace message
  */
 #define trace(class, msg, ...)                  \
@@ -191,13 +192,19 @@ void traceCap_(Capability *cap, char *msg, ...);
 
 void trace_(char *msg, ...);
 
-/* 
+/*
  * A message or event emitted by the program
  * Used by Debug.Trace.{traceEvent, traceEventIO}
  */
 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
  */
@@ -205,7 +212,7 @@ void traceThreadLabel_(Capability *cap,
                        StgTSO     *tso,
                        char       *label);
 
-/* 
+/*
  * Emit a debug message (only when DEBUG is defined)
  */
 #ifdef DEBUG
@@ -226,7 +233,7 @@ void traceThreadLabel_(Capability *cap,
 #define debugTraceCap(class, cap, str, ...) /* nothing */
 #endif
 
-/* 
+/*
  * Emit a message/event describing the state of a thread
  */
 #define traceThreadStatus(class, tso)           \
@@ -236,23 +243,25 @@ void traceThreadLabel_(Capability *cap,
 
 void traceThreadStatus_ (StgTSO *tso);
 
-void traceEventStartup_ (int n_caps);
-
 /*
  * Events for describing capabilities and capability sets in the eventlog
- *
- * Note: unlike other events, these are not conditional on TRACE_sched or
- * similar because capabilities and capability sets are important
- * context for other events. Since other events depend on these events
- * then for simplicity we always emit them, rather than working out if
- * they're necessary . They should be very low volume.
  */
-void traceCapEvent (Capability   *cap,
+#define traceCapEvent(cap, tag)                 \
+    if (RTS_UNLIKELY(TRACE_cap)) {              \
+        traceCapEvent_(cap, tag);               \
+    }
+
+void traceCapEvent_ (Capability   *cap,
                     EventTypeNum  tag);
 
-void traceCapsetEvent (EventTypeNum tag,
-                       CapsetID     capset,
-                       StgWord      info);
+#define traceCapsetEvent(cap, capset, info)     \
+    if (RTS_UNLIKELY(TRACE_cap)) {              \
+        traceCapsetEvent_(cap, capset, info);   \
+    }
+
+void traceCapsetEvent_ (EventTypeNum tag,
+                        CapsetID     capset,
+                        StgWord      info);
 
 void traceWallClockTime_(void);
 
@@ -262,6 +271,29 @@ 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);
+
+void traceHeapProfBegin(StgWord8 profile_id);
+void traceHeapProfSampleBegin(StgInt era);
+void traceHeapProfSampleString(StgWord8 profile_id,
+                               const char *label, StgWord residency);
+#ifdef PROFILING
+void traceHeapProfCostCentre(StgWord32 ccID,
+                             const char *label,
+                             const char *module,
+                             const char *srcloc,
+                             StgBool is_caf);
+void traceHeapProfSampleCostCentre(StgWord8 profile_id,
+                                   CostCentreStack *stack, StgWord residency);
+#endif /* PROFILING */
+
 #else /* !TRACING */
 
 #define traceSchedEvent(cap, tag, tso, other) /* nothing */
@@ -283,12 +315,19 @@ void traceSparkCounters_ (Capability *cap,
 #define debugTraceCap(class, cap, str, ...) /* nothing */
 #define traceThreadStatus(class, tso) /* nothing */
 #define traceThreadLabel_(cap, tso, label) /* nothing */
-INLINE_HEADER void traceEventStartup_ (int n_caps STG_UNUSED) {};
 #define traceCapEvent(cap, tag) /* nothing */
 #define traceCapsetEvent(tag, capset, info) /* nothing */
 #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 */
+#define traceHeapProfBegin(profile_id) /* nothing */
+#define traceHeapProfCostCentre(ccID, label, module, srcloc, is_caf) /* nothing */
+#define traceHeapProfSampleBegin(era) /* nothing */
+#define traceHeapProfSampleCostCentre(profile_id, stack, residency) /* nothing */
+#define traceHeapProfSampleString(profile_id, label, residency) /* nothing */
 
 #endif /* TRACING */
 
@@ -298,6 +337,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) */
 
@@ -331,9 +371,6 @@ void dtraceUserMsgWrapper(Capability *cap, char *msg);
     HASKELLEVENT_CREATE_SPARK_THREAD(cap, spark_tid)
 #define dtraceThreadLabel(cap, tso, label)              \
     HASKELLEVENT_THREAD_LABEL(cap, tso, label)
-INLINE_HEADER void dtraceStartup (int num_caps) {
-    HASKELLEVENT_STARTUP(num_caps);
-}
 #define dtraceCapCreate(cap)                            \
     HASKELLEVENT_CAP_CREATE(cap)
 #define dtraceCapDelete(cap)                            \
@@ -344,6 +381,8 @@ 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)                               \
@@ -352,7 +391,6 @@ INLINE_HEADER void dtraceStartup (int num_caps) {
     HASKELLEVENT_GC_DONE(cap)
 #define dtraceGcGlobalSync(cap)                         \
     HASKELLEVENT_GC_GLOBAL_SYNC(cap)
-/* FIXME: leads to a validate failure on OS X (Lion)
 #define dtraceEventGcStats(heap_capset, gens,           \
                            copies, slop, fragmentation, \
                            par_n_threads,               \
@@ -362,7 +400,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)           \
@@ -377,20 +415,6 @@ INLINE_HEADER void dtraceStartup (int num_caps) {
     HASKELLEVENT_HEAP_SIZE(heap_capset, size)
 #define dtraceEventHeapLive(heap_capset, live)          \
     HASKELLEVENT_HEAP_LIVE(heap_capset, live)
- */
-#define dtraceEventGcStats(heap_capset, gens,           \
-                           copies, slop, fragmentation, \
-                           par_n_threads,               \
-                           par_max_copied,              \
-                           par_tot_copied)              
-#define dtraceHeapInfo(heap_capset, gens,               \
-                       maxHeapSize, allocAreaSize,      \
-                       mblockSize, blockSize)           
-#define dtraceEventHeapAllocated(cap, heap_capset,      \
-                                 allocated)             
-#define dtraceEventHeapSize(heap_capset, size)          
-#define dtraceEventHeapLive(heap_capset, live)          
 #define dtraceCapsetCreate(capset, capset_type)         \
     HASKELLEVENT_CAPSET_CREATE(capset, capset_type)
 #define dtraceCapsetDelete(capset)                      \
@@ -415,6 +439,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) */
 
@@ -430,8 +460,8 @@ INLINE_HEADER void dtraceStartup (int num_caps) {
 #define dtraceRequestParGc(cap)                         /* nothing */
 #define dtraceCreateSparkThread(cap, spark_tid)         /* nothing */
 #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 */
@@ -464,6 +494,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
 
@@ -476,30 +509,30 @@ INLINE_HEADER void dtraceStartup (int num_caps STG_UNUSED) {};
 //
 // Dtrace - dtrace probes are unconditionally added as probe activation is
 //   handled by the dtrace component of the kernel, and inactive probes are
-//   very cheap  usually, one no-op.  Consequently, dtrace can be used with
+//   very cheap - usually, one no-op.  Consequently, dtrace can be used with
 //   all flavours of the RTS.  In addition, we still support logging events to
 //   a file, even in the presence of dtrace.  This is, eg, useful when tracing
 //   on a server, but browsing trace information with ThreadScope on a local
 //   client.
-// 
+//
 // -----------------------------------------------------------------------------
 
-INLINE_HEADER void traceEventCreateThread(Capability *cap STG_UNUSED, 
+INLINE_HEADER void traceEventCreateThread(Capability *cap STG_UNUSED,
                                           StgTSO     *tso STG_UNUSED)
 {
     traceSchedEvent(cap, EVENT_CREATE_THREAD, tso, tso->stackobj->stack_size);
     dtraceCreateThread((EventCapNo)cap->no, (EventThreadID)tso->id);
 }
 
-INLINE_HEADER void traceEventRunThread(Capability *cap STG_UNUSED, 
+INLINE_HEADER void traceEventRunThread(Capability *cap STG_UNUSED,
                                        StgTSO     *tso STG_UNUSED)
 {
     traceSchedEvent(cap, EVENT_RUN_THREAD, tso, tso->what_next);
     dtraceRunThread((EventCapNo)cap->no, (EventThreadID)tso->id);
 }
 
-INLINE_HEADER void traceEventStopThread(Capability          *cap    STG_UNUSED, 
-                                        StgTSO              *tso    STG_UNUSED, 
+INLINE_HEADER void traceEventStopThread(Capability          *cap    STG_UNUSED,
+                                        StgTSO              *tso    STG_UNUSED,
                                         StgThreadReturnCode  status STG_UNUSED,
                                         StgWord32           info    STG_UNUSED)
 {
@@ -508,20 +541,9 @@ INLINE_HEADER void traceEventStopThread(Capability          *cap    STG_UNUSED,
                      (EventThreadStatus)status, (EventThreadID)info);
 }
 
-// needs to be EXTERN_INLINE as it is used in another EXTERN_INLINE function
-EXTERN_INLINE void traceEventThreadRunnable(Capability *cap STG_UNUSED, 
-                                            StgTSO     *tso STG_UNUSED);
-
-EXTERN_INLINE void traceEventThreadRunnable(Capability *cap STG_UNUSED, 
-                                            StgTSO     *tso STG_UNUSED)
-{
-    traceSchedEvent(cap, EVENT_THREAD_RUNNABLE, tso, 0);
-    dtraceThreadRunnable((EventCapNo)cap->no, (EventThreadID)tso->id);
-}
-
-INLINE_HEADER void traceEventMigrateThread(Capability *cap     STG_UNUSED, 
+INLINE_HEADER void traceEventMigrateThread(Capability *cap     STG_UNUSED,
                                            StgTSO     *tso     STG_UNUSED,
-                                           nat         new_cap STG_UNUSED)
+                                           uint32_t    new_cap STG_UNUSED)
 {
     traceSchedEvent(cap, EVENT_MIGRATE_THREAD, tso, new_cap);
     dtraceMigrateThread((EventCapNo)cap->no, (EventThreadID)tso->id,
@@ -531,9 +553,7 @@ INLINE_HEADER void traceEventMigrateThread(Capability *cap     STG_UNUSED,
 INLINE_HEADER void traceCapCreate(Capability *cap STG_UNUSED)
 {
     traceCapEvent(cap, EVENT_CAP_CREATE);
-/* FIXME: leads to a validate failure on OS X (Lion)
     dtraceCapCreate((EventCapNo)cap->no);
-    */
 }
 
 INLINE_HEADER void traceCapDelete(Capability *cap STG_UNUSED)
@@ -554,9 +574,9 @@ INLINE_HEADER void traceCapDisable(Capability *cap STG_UNUSED)
     dtraceCapDisable((EventCapNo)cap->no);
 }
 
-INLINE_HEADER void traceEventThreadWakeup(Capability *cap       STG_UNUSED, 
+INLINE_HEADER void traceEventThreadWakeup(Capability *cap       STG_UNUSED,
                                           StgTSO     *tso       STG_UNUSED,
-                                          nat         other_cap STG_UNUSED)
+                                          uint32_t    other_cap STG_UNUSED)
 {
     traceSchedEvent(cap, EVENT_THREAD_WAKEUP, tso, other_cap);
     dtraceThreadWakeup((EventCapNo)cap->no, (EventThreadID)tso->id,
@@ -632,37 +652,35 @@ INLINE_HEADER void traceEventGcDone(Capability *cap STG_UNUSED)
 INLINE_HEADER void traceEventGcGlobalSync(Capability *cap STG_UNUSED)
 {
     traceGcEvent(cap, EVENT_GC_GLOBAL_SYNC);
-/* FIXME: leads to a validate failure on OS X (Lion)
     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,
-                                     nat         par_n_threads  STG_UNUSED,
-                                     lnat        par_max_copied STG_UNUSED,
-                                     lnat        par_tot_copied STG_UNUSED)
+                                     uint32_t    gen            STG_UNUSED,
+                                     W_        copied         STG_UNUSED,
+                                     W_        slop           STG_UNUSED,
+                                     W_        fragmentation  STG_UNUSED,
+                                     uint32_t  par_n_threads  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)
+                                      uint32_t  gens          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,
@@ -676,7 +694,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);
@@ -684,7 +702,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);
@@ -692,29 +710,12 @@ 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);
 }
 
-/* TODO: at some point we should remove this event, it's covered by
- * the cap create/delete events.
- */
-INLINE_HEADER void traceEventStartup(void)
-{
-    int n_caps;
-#ifdef THREADED_RTS
-    // XXX n_capabilities hasn't been initialised yet
-    n_caps = RtsFlags.ParFlags.nNodes;
-#else
-    n_caps = 1;
-#endif
-
-    traceEventStartup_(n_caps);
-    dtraceStartup(n_caps);
-}
-
 INLINE_HEADER void traceCapsetCreate(CapsetID   capset      STG_UNUSED,
                                      CapsetType capset_type STG_UNUSED)
 {
@@ -729,14 +730,14 @@ INLINE_HEADER void traceCapsetDelete(CapsetID capset STG_UNUSED)
 }
 
 INLINE_HEADER void traceCapsetAssignCap(CapsetID capset STG_UNUSED,
-                                        nat      capno  STG_UNUSED)
+                                        uint32_t capno  STG_UNUSED)
 {
     traceCapsetEvent(EVENT_CAPSET_ASSIGN_CAP, capset, capno);
     dtraceCapsetAssignCap(capset, capno);
 }
 
 INLINE_HEADER void traceCapsetRemoveCap(CapsetID capset STG_UNUSED,
-                                        nat      capno  STG_UNUSED)
+                                        uint32_t capno  STG_UNUSED)
 {
     traceCapsetEvent(EVENT_CAPSET_REMOVE_CAP, capset, capno);
     dtraceCapsetRemoveCap(capset, capno);
@@ -755,7 +756,7 @@ INLINE_HEADER void traceOSProcessInfo(void)
      * is available to DTrace directly */
 }
 
-INLINE_HEADER void traceEventCreateSparkThread(Capability  *cap      STG_UNUSED, 
+INLINE_HEADER void traceEventCreateSparkThread(Capability  *cap      STG_UNUSED,
                                                StgThreadID spark_tid STG_UNUSED)
 {
     traceSparkEvent2(cap, EVENT_CREATE_SPARK_THREAD, spark_tid);
@@ -804,7 +805,7 @@ INLINE_HEADER void traceEventSparkRun(Capability *cap STG_UNUSED)
 }
 
 INLINE_HEADER void traceEventSparkSteal(Capability *cap STG_UNUSED,
-                                        nat         victim_cap STG_UNUSED)
+                                        uint32_t    victim_cap STG_UNUSED)
 {
     traceSparkEvent2(cap, EVENT_SPARK_STEAL, victim_cap);
     dtraceSparkSteal((EventCapNo)cap->no, (EventCapNo)victim_cap);
@@ -822,6 +823,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 */