@@ -75,7 +75,7 @@ def garbage_collect
75
75
GC . start
76
76
end
77
77
78
- def self . stat ( option = nil )
78
+ def self . stat ( key = nil )
79
79
time , count , minor_count , major_count , unknown_count , heap , memory_pool_names , memory_pool_info = Primitive . gc_stat
80
80
used , committed , init , max = heap
81
81
@@ -96,34 +96,36 @@ def self.stat(option = nil)
96
96
}
97
97
stat . default = 0
98
98
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
121
123
end
122
124
end
123
125
end
124
126
125
- if option
126
- stat [ option ]
127
+ if key
128
+ stat [ key ]
127
129
else
128
130
stat
129
131
end
0 commit comments