Version 4 (modified by chak, 8 years ago) (diff)


Using DTrace with GHC

GHC 6.13 includes DTrace probes in the runtime system. Currently, these probes correspond to the events of the EventLog framework and are only available on Mac OS X (from Leopard onwards).

It is straight forward to extend the current implementation with additional probes, and due to the lightweight nature of DTrace, new probes could inspect the runtime system and running Haskell program in an even more fine-grained manner.

Probe description

The following probes are available:

create-thread (capability, tid)
Triggered when a new runtime thread is created. Reports the capability on which the thread is created and the new thread's thread id.
run-thread (capability, tid)
Indicates that the given thread starts to run on the specified capability.
stop-thread (capability, tid)
The identified thread stops execution on the given capability.
thread-runnable (capability, tid)
The given thread has just been appended to the run queue of the specified capability.
migrate-thread (cap, tid, new_cap)
The specified thread has just been moved from capability cap to new_cap, either because cap is sharing its run queue with new_cap or because the migration was explicitly requested.
run-spark (capability, tid)
We are about to convert a spark into a new parallel thread. The capability and thread are those determining the spark and converting it, not the thread id of the new spark.

Probe definition

The provider is defined as follows:

provider HaskellEvent {

  // scheduler events
  probe create__thread (EventCapNo, EventThreadID);
  probe run__thread (EventCapNo, EventThreadID);
  probe stop__thread (EventCapNo, EventThreadID, EventThreadStatus);
  probe thread__runnable (EventCapNo, EventThreadID);
  probe migrate__thread (EventCapNo, EventThreadID, EventCapNo);
  probe run__spark (EventCapNo, EventThreadID);
  probe steal__spark (EventCapNo, EventThreadID, EventCapNo);
  probe shutdown (EventCapNo);
  probe thread_wakeup (EventCapNo, EventThreadID, EventCapNo);
  probe gc__start (EventCapNo);
  probe gc__end (EventCapNo);
  probe request__seq__gc (EventCapNo);
  probe request__par__gc (EventCapNo);
  probe create__spark__thread (EventCapNo, EventThreadID);

  // other events
  probe startup (EventCapNo);
  probe user__msg (EventCapNo, char *);
  probe gc__idle (EventCapNo);
  probe gc__work (EventCapNo);
  probe gc__done (EventCapNo);


where we have

typedef uint32_t EventThreadID;
typedef uint16_t EventCapNo;
typedef uint16_t EventThreadStatus;

The two events EVENT_LOG_MSG and EVENT_BLOCK_MARKER are not supported. The former doesn't appear to be used and the latter appears to be an artefact of the event log file format.


User-space DTrace probes are implemented differently on Mac OS X than in the original DTrace implementation; see under the heading BUILDING CODE CONTAINING USDT PROBES in the Mac OS X dtrace man page. Nevertheless, it shouldn't be too hard to enable these probes on other platforms, too.