Profile and monitor in real time
The heap profile report file <program>.hp
is generated as the program executes, so it's perfectly fine to take a snapshot of the file at any time and visualize it with hp2ps, even if the program is still busy executing. Because very basic heap profiling (-hT
) is possible without having compiled with profiling support, it is possible to produce running heap profiles with a very small overhead.
Increasing the sample interval -i
to something relatively big, such as a couple of seconds, it is very feasible to extract heap profiles from long-running programs even in production environments.
A quick-and-dirty trick that isn't for the light-hearted is the -S
Runtime System option. This option prints garbage collector statistics every time a cleanup takes place, in realtime. This includes bytes allocated, bytes copied, bytes live, time elapsed, and how long the garbage collector took. To make some sense of the output, it might make sense to limit the...