mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
6a1a08c945
commit
1450e0b5ac
4 changed files with 168 additions and 39 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue