From 1450e0b5ac0a49aa1f0d1db521b293b18f6fa99c Mon Sep 17 00:00:00 2001 From: ko1 Date: Mon, 30 Sep 2013 08:17:30 +0000 Subject: * ext/objspace/object_tracing.c: add new 3 methods to control tracing. * ObjectSpace::trace_object_allocations_start * ObjectSpace::trace_object_allocations_stop * ObjectSpace::trace_object_allocations_clear And some refactoring. * test/objspace/test_objspace.rb: add a test for new methods. * NEWS: add a description for new methods. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43095 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/objspace/test_objspace.rb | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'test/objspace') diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb index c95670592d..133b1e90a4 100644 --- a/test/objspace/test_objspace.rb +++ b/test/objspace/test_objspace.rb @@ -109,7 +109,7 @@ class TestObjSpace < Test::Unit::TestCase eom end - def test_traceobject + def test_trace_object_allocations o0 = Object.new ObjectSpace.trace_object_allocations{ o1 = Object.new; line1 = __LINE__; c1 = GC.count @@ -139,4 +139,37 @@ class TestObjSpace < Test::Unit::TestCase assert_equal(__method__, ObjectSpace.allocation_method_id(o3)) } end + + def test_trace_object_allocations_start_stop_clear + begin + ObjectSpace.trace_object_allocations_start + begin + ObjectSpace.trace_object_allocations_start + begin + ObjectSpace.trace_object_allocations_start + obj0 = Object.new + ensure + ObjectSpace.trace_object_allocations_stop + obj1 = Object.new + end + ensure + ObjectSpace.trace_object_allocations_stop + obj2 = Object.new + end + ensure + ObjectSpace.trace_object_allocations_stop + obj3 = Object.new + end + + assert_equal(__FILE__, ObjectSpace.allocation_sourcefile(obj0)) + assert_equal(__FILE__, ObjectSpace.allocation_sourcefile(obj1)) + assert_equal(__FILE__, ObjectSpace.allocation_sourcefile(obj2)) + assert_equal(nil , ObjectSpace.allocation_sourcefile(obj3)) # after tracing + + ObjectSpace.trace_object_allocations_clear + assert_equal(nil, ObjectSpace.allocation_sourcefile(obj0)) + assert_equal(nil, ObjectSpace.allocation_sourcefile(obj1)) + assert_equal(nil, ObjectSpace.allocation_sourcefile(obj2)) + assert_equal(nil, ObjectSpace.allocation_sourcefile(obj3)) + end end -- cgit v1.2.3