# Heap profiling with nhc98

Heap profiling allows a programmer to see how heap space is being used within their program. This can enable space "leaks" to be identified, and their causes tracked down.

### To obtain a heap profile of a computation:

1. Compile all modules of the program with the `-p` option; also specify `-p` at link-time. Using `hmake -p` does all the necessary compiling and linking automatically. eg. to compile `MyProg.hs` and everything it depends on for heap profiling simply use `hmake -p MyProg`

2. Run the program with additional runtime arguments: e.g. `./MyProg +RTS -p -RTS` to output "producer" heap profile data to the file `MyProg.hp`

3. Convert the raw profile data to a PostScript graph with the utility hp2graph, and view it in your favorite viewer.

### Heap profiling options

`-isize` | set the profiling interval to `size` (in number of allocations, or in seconds)
`-p` | select producer profiling
`-c` | select construction profiling
`-m` | select per-module profiling
`-r[num]` | select retainer profiling - num is maximum retainer set size (default=1)
`-l` | select lifetime profiling
`-b` | select biographical profiling
`-pnames` | restrict profile to named producers
`-cnames` | restrict profile to named constructions
`-mnames` | restrict profile to named modules
`-rnames` | restrict profile to named retainers (default=1)
`-lnums` | restrict profile to numbered lifetimes (min-, -max, or min-max)
`-bname` | restrict profile to named biographical phase (lag, drag, void, or use)

The first occurrence of any of the options pcmrbl determines the primary form of the profile. Subsequent pcmrbl options introduce restrictions on the profile, for instance -p -c: asks for a producer profile restricted to producers of the `:' (list) construction. Restrictions are almost all orthogonal to each other, and you may have as many as you like. Except for biography and lifetime restrictions, the format is of a list of names, separated by commas. (In general, you may need to use quotes around the list to protect special characters from the shell.)

The latest updates to these pages are available on the WWW from `http://www.cs.york.ac.uk/fp/nhc98/`

York Functional Programming Group