ghc-gc-hook-0.2.1.0: GHC garbage collection hook
Safe HaskellNone
LanguageHaskell2010

GHC.GC_Hook

Description

Make use of GHC's GC hook functionality from Haskell. This is still a very bare-bones API.

Synopsis

Documentation

setGCHook :: IO () Source #

Initialise the GC hook. Note: to use getGCLog you first need to also call enableGClogging True.

enableGClogging :: Bool -> IO () Source #

Enable or disable GC logging. If the argument is true, logging is enabled; if the argument is false, any pending logs are cleared and logging is disabled from now on.

getGCLog :: IO [Details] Source #

Get the log of Details structures up until now; also clears the log. You will never get the same structure twice.

Note: This is not entirely atomic. If you call this function concurrently, it is possible that alternatingly, some events go to one getGCLog call and other events go to the other call.

gcSetHookDelegate :: Ptr () -> IO () Source #

Set a C function to be called after every GC. Use this in the following manner:

  • Create a file cbits/something.c in your project (the actual file name doesn't matter), and add c-sources: cbits/something.c (and, if you wish, cc-options: -Wall) to the stanza of the correct component in your .cabal file.
  • Put the following in it: (The function names are unimportant.)
#include "Rts.h"

// the static is unnecessary, but neat
static void my_delegate_function(const struct GCDetails_ *d) {
    // put your code here
}

void* get_my_delegate_ptr(void) {
    return my_delegate_function;
}
  • Use the following in Haskell:
{-# LANGUAGE ForeignFunctionInterface #-}
import Foreign.Ptr (Ptr)
foreign import ccall "get_my_delegate_ptr" c_get_my_delegate_ptr :: IO (Ptr ())
-- ...
do funptr <- c_get_my_delegate_ptr
   gcSetHookDelegate funptr

data Details Source #

GC details as given to the GC hook installed by setGCHook. The only field that is not contained in GCDetails_ provided by the GHC RTS is detTimestamp, which is the time at which the GC was finished. The GC start time can probably be computed by subtracting detElapsedNs from this.

The documentation of the fields (other than detTimestamp) is copied from GHC rts/include/RtsAPI.h.

Constructors

Details 

Fields

Instances

Instances details
Show Details Source # 
Instance details

Defined in GHC.GC_Hook