summaryrefslogtreecommitdiff
path: root/test/objspace
diff options
context:
space:
mode:
authortmm1 <tmm1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-08 17:06:55 +0000
committertmm1 <tmm1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-08 17:06:55 +0000
commitd0d6e2ecfaf1cbf0b6c6095a1118ad375b2a0659 (patch)
treea98d7eaadb59e2bc67dba9b4cb2eb5210f194532 /test/objspace
parent6edaaf15e3fdcff35d3ec901a01969d575036ba9 (diff)
* ext/objspace/object_tracing.c: Add experimental methods to dump
objectspace as json: ObjectSpace.dump_all and ObjectSpace.dump(obj). These methods are useful for debugging reference leaks and memory growth in large ruby applications. [Bug #9026] [ruby-core:57893] [Fixes GH-423] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43585 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/objspace')
-rw-r--r--test/objspace/test_objspace.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb
index 5a0660e..aec4572 100644
--- a/test/objspace/test_objspace.rb
+++ b/test/objspace/test_objspace.rb
@@ -203,4 +203,31 @@ class TestObjSpace < Test::Unit::TestCase
end;
end
end
+
+ def test_dump
+ info = nil
+ ObjectSpace.trace_object_allocations do
+ str = "hello world"
+ info = ObjectSpace.dump(str)
+ end
+
+ assert_match /"type":"STRING"/, info
+ assert_match /"embedded":true, "bytesize":11, "value":"hello world", "encoding":"UTF-8"/, info
+ assert_match /"file":"#{Regexp.escape __FILE__}", "line":#{__LINE__-6}/, info
+ assert_match /"method":"test_dump"/, info
+ end
+
+ def test_dump_all
+ entry = /"value":"this is a test string", "encoding":"UTF-8", "file":"-", "line":4, "method":"dump_my_heap_please"/
+ assert_in_out_err(%w[-robjspace], <<-'end;', entry)
+ def dump_my_heap_please
+ ObjectSpace.trace_object_allocations_start
+ GC.start
+ "this is a test string".force_encoding("UTF-8")
+ ObjectSpace.dump_all(output: :stdout)
+ end
+
+ dump_my_heap_please
+ end;
+ end
end