Safe Haskell | None |
---|---|
Language | Haskell2010 |
Make use of GHC's GC hook functionality from Haskell. This is still a very bare-bones API.
Synopsis
- setGCHook :: IO ()
- enableGClogging :: Bool -> IO ()
- getGCLog :: IO [Details]
- gcSetHookDelegate :: Ptr () -> IO ()
- data Details = Details {
- detTimestamp :: TimeSpec
- detGen :: Word32
- detThreads :: Word32
- detAllocatedBytes :: Word64
- detLiveBytes :: Word64
- detLargeObjectsBytes :: Word64
- detCompactBytes :: Word64
- detSlopBytes :: Word64
- detMemInUseBytes :: Word64
- detCopiedBytes :: Word64
- detParMaxCopiedBytes :: Word64
- detParBalancedCopiedBytes :: Word64
- detSyncElapsedNs :: Word64
- detCpuNs :: Word64
- detElapsedNs :: Word64
- detNonmovingGcSyncCpuNs :: Word64
- detNonmovingGcSyncElapsedNs :: Word64
- detNonmovingGcCpuNs :: Word64
- detNonmovingGcElapsedNs :: Word64
Documentation
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.
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 addc-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
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
.
Details | |
|