From ed2abc4362e841967a3758baa199f88cf41496b2 Mon Sep 17 00:00:00 2001 From: tenderlove Date: Tue, 3 Jan 2017 22:42:10 +0000 Subject: Add `full` option to `ObjectSpace.dump_all` The `full` option includes all slots (even `T_NONE`) in the JSON output. This is to help with debugging heap fragmentation. Here is an example usage: ```ruby File.open('heap.json', 'w') do |f| ObjectSpace.dump_all(output: f, full: true) end ``` The `heap.json` file contains all slots, including empty slots. [Feature #13001] [ruby-core:78468] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57260 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/objspace/test_objspace.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test') diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb index 52558418bf..c05c8c9992 100644 --- a/test/objspace/test_objspace.rb +++ b/test/objspace/test_objspace.rb @@ -275,6 +275,19 @@ class TestObjSpace < Test::Unit::TestCase assert_match /"value":"foobar\h+"/, dump end + def test_dump_all_full + assert_in_out_err(%w[-robjspace], <<-'end;') do |output, error| + def dump_my_heap_please + ObjectSpace.dump_all(output: :stdout, full: true) + end + + dump_my_heap_please + end; + heap = output.find_all { |l| JSON.parse(l)['type'] == "NONE" } + assert_operator heap.length, :>, 0 + end + end + def test_dump_all entry = /"bytesize":11, "value":"TEST STRING", "encoding":"UTF-8", "file":"-", "line":4, "method":"dump_my_heap_please", "generation":/ -- cgit v1.2.3