This is a adaptation of some of the ObjectSpace.dump_all
analyisis scripts found in Sam Saffron's article on "Debugging memory leaks in Ruby":
https://samsaffron.com/archive/2015/03/31/debugging-memory-leaks-in-ruby
The input files are also generated in a similar fashion that is described in the blog post:
io=File.open("/tmp/my_dump", "w")
ObjectSpace.dump_all(output: io);
io.close
And assumes that you are currently running with ObjectSpace.trace_object_allocations_start
(see the post for more details).
That said, this script supports working with gzipped files, which is highly recommend that you zip up the output files that you do dump, as they are quite large (500MB a piece in my case).
There are two modes for the script:
Without any flag, the script will keep track of all object allocations and print out the counts, grouped by GC
generation.
The -g
/--generation
flag allows for displaying the more versbose output described in the post, which displays the counts of the currently allocated objects for a specific generation, grouped by line and line number.