Recently, Matthew Flatt added programmatic logging of garbage collection events in Racket. Based on this, I’ve built a tool for summarizing the GC behavior of Racket programs. Here’s an example of how to use it:
% racket -l gcstats -u my-program.rkt
This says to first require the
gcstats module before running
my-program.rkt. When you do this you’ll get a big printout after your program runs; below the fold, we’ll take a look at each line in detail.
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
To install, follow the instructions on the GitHub page.
Right now, the tool is preliminary, but useful. There are a few limitations:
- There are a few GCs before the tool starts — it can’t report anything about them.
- If you have multiple places, it will only report information from the initial place. Fixing this will require more information from Racket.
- The current architecture keeps too much info around during the run of the program. I hope to fix that soon.
Hopefully, this gives people some better information about how the Racket GC behaves. The output formatting and information gathered is inspired by similar output from the GHC runtime system. Read More