ghc-heap-view

Extract the heap representation of Haskell values and thunks

Version on this page:0.5.7
LTS Haskell 9.21:0.5.10
Stackage Nightly 2017-07-25:0.5.9
Latest on Hackage:0.6.4.1

See all snapshots ghc-heap-view appears in

BSD-3-Clause licensed by Joachim Breitner, Dennis Felsing
Maintained by Joachim Breitner
This version can be pinned in stack with:ghc-heap-view-0.5.7@sha256:5e6b492fa4eb725f511e88ca0a4d9655a4fd61e19564dfa63ce53b0d286bdb8c,3318

Module documentation for 0.5.7

This library provides functions to introspect the Haskell heap, for example to investigate sharing and lazy evaluation. As this is tied to the internals of the compiler,it only works with specific versions. Currently, GHC 7.4 through 7.10 should be supported.

It has been inspired by (and taken code from) the vacuum package and the GHCi debugger, but also allows to investiage thunks and other closures.

This package also provides a new GHCi-command, :printHeap, which allows you to inspect the current heap representation of a value, including sharing and cyclic references. To enable the command, you need to load the included ghci script or add it to ~/.ghci, as explained by cabal install. Once it is set up, you can do this:

> let value = "A Value"
> let x = (value, if head value == 'A' then value else "", cycle [True, False])
> :printHeap x
let x1 = _bco
    x21 = []
in (x1,_bco,_bco)
> length (take 100 (show x)) `seq` return () -- evaluate everything
> :printHeap x
let x1 = "A Value"
    x16 = True : False : x16
in (x1,x1,x16)

You can change the maximum recursion depth using :setPrintHeapDepth:

> :setPrintHeapDepth 3
> :printHeap x
let x1 = C# 'A' : ... : ...
in (x1,x1,True : ... : ...)

If the view is impaired by blackholes (written _bh), running System.Mem.performGC usually helps.

The work on this package has been supported by the Deutsche Telekom Stiftung (http://telekom-stiftung.de).