Skip to content

Commit c0f1ed4

Browse files
committed
GC.stat: avoid computing memory pool names stats if not needed
1 parent 138b990 commit c0f1ed4

File tree

1 file changed

+27
-25
lines changed
  • src/main/ruby/truffleruby/core

1 file changed

+27
-25
lines changed

src/main/ruby/truffleruby/core/gc.rb

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def garbage_collect
7575
GC.start
7676
end
7777

78-
def self.stat(option = nil)
78+
def self.stat(key = nil)
7979
time, count, minor_count, major_count, unknown_count, heap, memory_pool_names, memory_pool_info = Primitive.gc_stat
8080
used, committed, init, max = heap
8181

@@ -96,34 +96,36 @@ def self.stat(option = nil)
9696
}
9797
stat.default = 0
9898

99-
memory_pool_names.each_with_index do |memory_pool_name, i|
100-
# Populate memory pool specific stats
101-
info = memory_pool_info[i]
102-
if info
103-
stat[memory_pool_name] = data = {
104-
used: info[0],
105-
committed: info[1],
106-
init: info[2],
107-
max: info[3],
108-
peak_used: info[4],
109-
peak_committed: info[5],
110-
peak_init: info[6],
111-
peak_max: info[7],
112-
last_used: info[8],
113-
last_committed: info[9],
114-
last_init: info[10],
115-
last_max: info[11],
116-
}
117-
118-
# Calculate stats across memory pools for peak_/last_ (we already know the values for current usage)
119-
data.each_pair do |key, value|
120-
stat[key] += value if key.start_with?('peak_', 'last_')
99+
unless Primitive.object_kind_of?(key, Symbol) # memory_pool_names are Strings
100+
memory_pool_names.each_with_index do |memory_pool_name, i|
101+
# Populate memory pool specific stats
102+
info = memory_pool_info[i]
103+
if info
104+
stat[memory_pool_name] = data = {
105+
used: info[0],
106+
committed: info[1],
107+
init: info[2],
108+
max: info[3],
109+
peak_used: info[4],
110+
peak_committed: info[5],
111+
peak_init: info[6],
112+
peak_max: info[7],
113+
last_used: info[8],
114+
last_committed: info[9],
115+
last_init: info[10],
116+
last_max: info[11],
117+
}
118+
119+
# Calculate stats across memory pools for peak_/last_ (we already know the values for current usage)
120+
data.each_pair do |k,v|
121+
stat[k] += v if k.start_with?('peak_', 'last_')
122+
end
121123
end
122124
end
123125
end
124126

125-
if option
126-
stat[option]
127+
if key
128+
stat[key]
127129
else
128130
stat
129131
end

0 commit comments

Comments
 (0)