[racket] Gathering GC statistics for Racket programs

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Sat Oct 1 18:50:13 EDT 2011

Since Matthew added nice programmatic tools for understanding the
behavior of the GC, I've written a little tool to summarize the GC
behavior of your program.  You can find it on GitHub here:
https://github.com/samth/gcstats .  To install it, do this:

% git clone git://github.com/samth/gcstats.git
% raco link gcstats

Then you can do this:

% racket -l gcstats -u my-program.rkt

and you get output like this:

     39,703,916 bytes allocated in the heap
     28,890,688 bytes collected by GC
     17,083,432 bytes max heap size
     16,604,120 bytes max slop
     28,229,632 bytes peak total memory use

Generation 0:       5 collections,       32ms,    31.71ms elapsed
Generation 1:       0 collections,        0ms,        0ms elapsed

INIT  time       256 ms
MUT   time       132 ms (    129.98 ms elapsed)
GC    time        32 ms (     31.71 ms elapsed)
TOTAL time       420 ms (    417.69 ms elapsed)

%GC time       19.51%   ( 19.61% elapsed)

Alloc rate     300,787,242 bytes per MUT second

There are a few significant limitations at present:
1. There are a few GCs before the tool starts -- it can't report
anything about them.
2. If you have multiple places, it will do totally the wrong thing.
Fixing this will require a little more information from Racket.
3. The current architecture keeps too much info around during the run
of the program.  I hope to fix that soon.

The whole thing is inspired by the similar GHC reporting tools,
documented here:
.  The GHC tools report one more interesting piece of information,
which is how many bytes are copied by the GC.  I hope we can get the
information from the Racket GC at some point as well.
sam th
samth at ccs.neu.edu

Posted on the users mailing list.