This post originated from an RSS feed registered with Ruby Buzz
by Eric Hodel.
Original Post: Memory Inspector
Feed Title: Segment7
Feed URL: http://blog.segment7.net/articles.rss
Feed Description: Posts about and around Ruby, MetaRuby, ruby2c, ZenTest and work at The Robot Co-op.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Eric Hodel
Latest Posts From Segment7
Advertisement
I've hacked into gc.c and added an alternative to ObjectSpace.each_object
that gives you the contents of every heap slot in Ruby's memory space.
$ ./ruby -I ~/Work/p4/zss/src/RubyInline/dev/ ~/heapwalk.rb
[id, size, inspect]
0x001aa004 0x00000000 :__free
0x001aa018 0x00000000 :__free
0x001aa02c 0x00000000 :__free
0x001aa040 0x00000000 :__free
[the beginning is boring...]
0x001caa20 0x00000014 #<Class:Marshal>
0x001caa34 0x00000014 :__node
0x001caa48 0x00000014 :__node
0x001caa5c 0x0000000c Marshal
[but there's things like nodes, singleton classes, modules,]
0x001caae8 0x0000000c #<NoMemoryError: failed to allocate memory>
0x001caafc 0x0000002d "failed to allocate memory"
0x001cab10 0x00000014 []
[exceptions, strings, arrays and other objects,]
0x001ce5f8 0x00000014 :__iclass
[included Modules,]
0x001dad30 0x00000014 :__scope
[scopes, and some other stuff that's too hard to find]
It requires a hack to gc.c to gain access to the heap, but combined with Ryan's memory visualizer this might generate something usable.
Code will be available later I've audited my object size calculations (and have slept).
Read: Memory Inspector