From d7009f76ef8a7b96e73471561cf9c4863902e438 Mon Sep 17 00:00:00 2001 From: tmm1 Date: Thu, 28 Nov 2013 07:40:35 +0000 Subject: * gc.c: Expose details about last garbage collection via GC.stat. * gc.c (gc_stat): Add :last_collection_flags for reason/trigger/type of last GC run. * gc.c (gc_prof_sweep_timer_stop): Record HAVE_FINALIZE GPR even without GC_PROFILE_MORE_DETAIL. * gc.c (gc_profile_flags): Add GC::Profiler.decode_flags to make sense of GC.stat[:last_collection_flags] * test/ruby/test_gc.rb (class TestGc): Test for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43893 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_gc.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_gc.rb b/test/ruby/test_gc.rb index 0d101f609b..2668582ed8 100644 --- a/test/ruby/test_gc.rb +++ b/test/ruby/test_gc.rb @@ -79,6 +79,26 @@ class TestGc < Test::Unit::TestCase assert_equal(count[:FREE], stat[:heap_free_slot]) end + def test_gc_reason + 100_000.times{ "a" + "b" } + assert_equal({:gc_by => :newobj}, + GC::Profiler.decode_flags(GC.stat[:last_collection_flags])) + end + + def test_gc_reason_method + GC.start + assert_equal({:major_by=>:nofree, :gc_by=>:method, :immediate_sweep=>true}, + GC::Profiler.decode_flags(GC.stat[:last_collection_flags])) + end + + def test_gc_reason_stress + GC.stress = true + assert_equal({:major_by=>:stress, :gc_by=>:malloc, :immediate_sweep=>true}, + GC::Profiler.decode_flags(GC.stat[:last_collection_flags])) + ensure + GC.stress = false + end + def test_singleton_method assert_in_out_err(%w[--disable-gems], <<-EOS, [], [], "[ruby-dev:42832]") GC.stress = true -- cgit v1.2.3