summaryrefslogtreecommitdiff
path: root/test/objspace
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2020-07-28 12:58:49 +0200
committerAaron Patterson <aaron.patterson@gmail.com>2020-09-09 08:05:14 -0700
commitb49a8704143ce47de0472b6033fc5797aed21f52 (patch)
tree857f361ac78624430dc6a7b83f473eb13311c6dd /test/objspace
parent01828a955a2d776263bda84ee12d9ea922bbfa01 (diff)
downloadruby-b49a8704143ce47de0472b6033fc5797aed21f52.tar.gz
Add a :since option to dump_all
This is useful to see what a block of code allocated, e.g. ``` GC.start GC.disable ObjectSpace.trace_object_allocations do # run some code end gc_gen = GC.count allocations = ObjectSpace.dump_all(output: :file, since: gc_gen) GC.enable GC.start retentions = ObjectSpace.dump_all(output: :file, since: gc_gen) ```
Diffstat (limited to 'test/objspace')
-rw-r--r--test/objspace/test_objspace.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb
index 40f1c73a51..7405b8864d 100644
--- a/test/objspace/test_objspace.rb
+++ b/test/objspace/test_objspace.rb
@@ -336,6 +336,29 @@ class TestObjSpace < Test::Unit::TestCase
end
end
+ def test_dump_all_single_generation
+ assert_in_out_err(%w[-robjspace], "#{<<-"begin;"}\n#{<<-'end;'}") do |output, error|
+ begin;
+ def dump_my_heap_please
+ GC.start
+ ObjectSpace.trace_object_allocations_start
+ gc_gen = GC.count
+ puts gc_gen
+ @obj1 = Object.new
+ GC.start
+ @obj2 = Object.new
+ ObjectSpace.dump_all(output: :stdout, since: gc_gen)
+ end
+
+ dump_my_heap_please
+ end;
+ since = output.shift.to_i
+ assert_operator output.size, :>, 0
+ generations = output.map { |l| JSON.parse(l)["generation"] }.uniq.sort
+ assert_equal [since, since + 1], generations
+ end
+ end
+
def test_dump_addresses_match_dump_all_addresses
assert_in_out_err(%w[-robjspace], "#{<<-"begin;"}\n#{<<-'end;'}") do |output, error|
begin;