|
34 | 34 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
35 | 35 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
36 | 36 |
|
| 37 | +module Truffle::GCOperations |
| 38 | + KNOWN_KEYS = %i[ |
| 39 | + count |
| 40 | + time |
| 41 | + minor_gc_count |
| 42 | + major_gc_count |
| 43 | + unknown_count |
| 44 | + heap_available_slots |
| 45 | + heap_live_slots |
| 46 | + heap_free_slots |
| 47 | + used |
| 48 | + committed |
| 49 | + init |
| 50 | + max |
| 51 | + ] |
| 52 | + |
| 53 | + def self.stat_hash(key = nil) |
| 54 | + time, count, minor_count, major_count, unknown_count, heap, memory_pool_names, memory_pool_info = Primitive.gc_stat |
| 55 | + used, committed, init, max = heap |
| 56 | + |
| 57 | + # Initialize stat for statistics that come from memory pools, and populate it with some final stats (ordering similar to MRI) |
| 58 | + stat = { |
| 59 | + count: count, |
| 60 | + time: time, |
| 61 | + minor_gc_count: minor_count, |
| 62 | + major_gc_count: major_count, |
| 63 | + unknown_count: unknown_count, # if nonzero, major or minor count needs to be updated for this GC case |
| 64 | + heap_available_slots: committed, |
| 65 | + heap_live_slots: used, |
| 66 | + heap_free_slots: committed - used, |
| 67 | + used: used, |
| 68 | + committed: committed, |
| 69 | + init: init, |
| 70 | + max: max, |
| 71 | + } |
| 72 | + stat.default = 0 |
| 73 | + |
| 74 | + unless Primitive.object_kind_of?(key, Symbol) # memory_pool_names are Strings |
| 75 | + memory_pool_names.each_with_index do |memory_pool_name, i| |
| 76 | + # Populate memory pool specific stats |
| 77 | + info = memory_pool_info[i] |
| 78 | + if info |
| 79 | + stat[memory_pool_name] = data = { |
| 80 | + used: info[0], |
| 81 | + committed: info[1], |
| 82 | + init: info[2], |
| 83 | + max: info[3], |
| 84 | + peak_used: info[4], |
| 85 | + peak_committed: info[5], |
| 86 | + peak_init: info[6], |
| 87 | + peak_max: info[7], |
| 88 | + last_used: info[8], |
| 89 | + last_committed: info[9], |
| 90 | + last_init: info[10], |
| 91 | + last_max: info[11], |
| 92 | + } |
| 93 | + |
| 94 | + # Calculate stats across memory pools for peak_/last_ (we already know the values for current usage) |
| 95 | + data.each_pair do |k,v| |
| 96 | + stat[k] += v if k.start_with?('peak_', 'last_') |
| 97 | + end |
| 98 | + end |
| 99 | + end |
| 100 | + end |
| 101 | + |
| 102 | + if key |
| 103 | + stat[key] |
| 104 | + else |
| 105 | + stat |
| 106 | + end |
| 107 | + end |
| 108 | +end |
| 109 | + |
37 | 110 | module GC
|
38 | 111 | def self.run(force)
|
39 | 112 | start
|
@@ -76,58 +149,14 @@ def garbage_collect
|
76 | 149 | end
|
77 | 150 |
|
78 | 151 | def self.stat(key = nil)
|
79 |
| - time, count, minor_count, major_count, unknown_count, heap, memory_pool_names, memory_pool_info = Primitive.gc_stat |
80 |
| - used, committed, init, max = heap |
81 |
| - |
82 |
| - # Initialize stat for statistics that come from memory pools, and populate it with some final stats (ordering similar to MRI) |
83 |
| - stat = { |
84 |
| - count: count, |
85 |
| - time: time, |
86 |
| - minor_gc_count: minor_count, |
87 |
| - major_gc_count: major_count, |
88 |
| - unknown_count: unknown_count, # if nonzero, major or minor count needs to be updated for this GC case |
89 |
| - heap_available_slots: committed, |
90 |
| - heap_live_slots: used, |
91 |
| - heap_free_slots: committed - used, |
92 |
| - used: used, |
93 |
| - committed: committed, |
94 |
| - init: init, |
95 |
| - max: max, |
96 |
| - } |
97 |
| - stat.default = 0 |
98 |
| - |
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 |
123 |
| - end |
124 |
| - end |
125 |
| - end |
126 |
| - |
127 | 152 | if key
|
128 |
| - stat[key] |
| 153 | + if Truffle::GCOperations::KNOWN_KEYS.include?(key) |
| 154 | + Truffle::GCOperations.stat_hash(key) |
| 155 | + else |
| 156 | + 0 |
| 157 | + end |
129 | 158 | else
|
130 |
| - stat |
| 159 | + Truffle::GCOperations.stat_hash |
131 | 160 | end
|
132 | 161 | end
|
133 | 162 |
|
|
0 commit comments