Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
ObjectSpace#dump_all
# File tmp/rubies/ruby-3.3.0/ext/objspace/lib/objspace.rb, line 84
def dump_all(output: :file, full: false, since: nil, shapes: true)
out = case output
when :file, nil
require 'tempfile'
Tempfile.create(%w(rubyheap .json))
when :stdout
STDOUT
when :string
+''
when IO
output
else
raise ArgumentError, "wrong output option: #{output.inspect}"
end
shapes = 0 if shapes == true
ret = _dump_all(out, full, since, shapes)
return nil if output == :stdout
ret
end
Dump the contents of the ruby heap as JSON.
output argument is the same as for dump.
full must be a boolean. If true, all heap slots are dumped including the empty ones (T_NONE).
since must be a non-negative integer or nil.
If since is a positive integer, only objects of that generation and newer generations are dumped. The current generation can be accessed using GC::count. Objects that were allocated without object allocation tracing enabled are ignored. See ::trace_object_allocations for more information and examples.
If since is omitted or is nil, all objects are dumped.
shapes must be a boolean or a non-negative integer.
If shapes is a positive integer, only shapes newer than the provided shape id are dumped. The current shape_id can be accessed using RubyVM.stat(:next_shape_id).
If shapes is false, no shapes are dumped.
To only dump objects allocated past a certain point you can combine since and shapes:
ObjectSpace.trace_object_allocations GC.start gc_generation = GC.count shape_generation = RubyVM.stat(:next_shape_id) call_method_to_instrument ObjectSpace.dump_all(since: gc_generation, shapes: shape_generation)
This method is only expected to work with C Ruby. This is an experimental method and is subject to change. In particular, the function signature and output format are not guaranteed to be compatible in future versions of ruby.
Ruby version changes
-
3.2
-
ObjectSpace.dump_alldump shapes as well. GH-6868
-