aboutsummaryrefslogtreecommitdiffstats
path: root/gc.rb
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2022-01-04 08:59:32 -0500
committerPeter Zhu <peter@peterzhu.ca>2022-01-04 09:46:36 -0500
commit615e9b28658c5b44a4474e04a53b84ae83b8e3fd (patch)
tree90f2f045c6f4d1d65f8361ff59fa3593b395f701 /gc.rb
parente9a4cc02b491fc8a2936f51b9f94ddcd77dd67f7 (diff)
downloadruby-615e9b28658c5b44a4474e04a53b84ae83b8e3fd.tar.gz
[Feature #18364] Add GC.stat_heap to get stats for memory heaps
GC.stat_heap will return stats for memory heaps. This is used for the Variable Width Allocation feature.
Diffstat (limited to 'gc.rb')
-rw-r--r--gc.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/gc.rb b/gc.rb
index 887fc06d26..e9fb8f883b 100644
--- a/gc.rb
+++ b/gc.rb
@@ -205,6 +205,40 @@ module GC
Primitive.gc_stat hash_or_key
end
+ # call-seq:
+ # GC.stat_heap -> Hash
+ # GC.stat_heap(nil, hash) -> Hash
+ # GC.stat_heap(heap_name) -> Hash
+ # GC.stat_heap(heap_name, hash) -> Hash
+ # GC.stat_heap(heap_name, :key) -> Numeric
+ #
+ # Returns information for memory pools in the GC.
+ #
+ # If the first optional argument, +heap_name+, is passed in and not +nil+, it
+ # returns a +Hash+ containing information about the particular memory pool.
+ # Otherwise, it will return a +Hash+ with memory pool names as keys and
+ # a +Hash+ containing information about the memory pool as values.
+ #
+ # If the second optional argument, +hash_or_key+, is given as +Hash+, it will
+ # be overwritten and returned. This is intended to avoid the probe effect.
+ #
+ # If both optional arguments are passed in and the second optional argument is
+ # a symbol, it will return a +Numeric+ of the value for the particular memory
+ # pool.
+ #
+ # On CRuby, +heap_name+ is of the type +Integer+ but may be of type +String+
+ # on other implementations.
+ #
+ # The contents of the hash are implementation specific and may change in
+ # the future without notice.
+ #
+ # If the optional argument, hash, is given, it is overwritten and returned.
+ #
+ # This method is only expected to work on CRuby.
+ def self.stat_heap heap_name = nil, hash_or_key = nil
+ Primitive.gc_stat_heap heap_name, hash_or_key
+ end
+
# call-seq:
# GC.latest_gc_info -> {:gc_by=>:newobj}
# GC.latest_gc_info(hash) -> hash