Class: NewRelic::Agent::VM::MriVM
- Inherits:
-
Object
- Object
- NewRelic::Agent::VM::MriVM
- Defined in:
- lib/new_relic/agent/vm/mri_vm.rb
Instance Method Summary collapse
- #derive_from_gc_stats(keys, stat) ⇒ Object
- #gather_constant_cache_invalidations ⇒ Object
- #gather_constant_cache_misses ⇒ Object
- #gather_derived_stats(snap) ⇒ Object
- #gather_gc_runs(snap) ⇒ Object
- #gather_gc_stats(snap) ⇒ Object
- #gather_gc_time(snap) ⇒ Object
- #gather_ruby_vm_stats(snap) ⇒ Object
- #gather_stats(snap) ⇒ Object
- #gather_thread_stats(snap) ⇒ Object
- #snapshot ⇒ Object
- #supports?(key) ⇒ Boolean
Instance Method Details
#derive_from_gc_stats(keys, stat) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/new_relic/agent/vm/mri_vm.rb', line 43 def derive_from_gc_stats(keys, stat) Array(keys).each do |key| value = stat[key] return value if value end nil end |
#gather_constant_cache_invalidations ⇒ Object
71 72 73 |
# File 'lib/new_relic/agent/vm/mri_vm.rb', line 71 def gather_constant_cache_invalidations RubyVM.stat[RUBY_VERSION >= '3.2.0' ? :constant_cache_invalidations : :global_constant_state] end |
#gather_constant_cache_misses ⇒ Object
75 76 77 |
# File 'lib/new_relic/agent/vm/mri_vm.rb', line 75 def gather_constant_cache_misses RubyVM.stat[:constant_cache_misses] end |
#gather_derived_stats(snap) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/new_relic/agent/vm/mri_vm.rb', line 34 def gather_derived_stats(snap) stat = GC.stat snap.total_allocated_object = derive_from_gc_stats(%i[total_allocated_objects total_allocated_object], stat) snap.major_gc_count = derive_from_gc_stats(:major_gc_count, stat) snap.minor_gc_count = derive_from_gc_stats(:minor_gc_count, stat) snap.heap_live = derive_from_gc_stats(%i[heap_live_slots heap_live_slot heap_live_num], stat) snap.heap_free = derive_from_gc_stats(%i[heap_free_slots heap_free_slot heap_free_num], stat) end |
#gather_gc_runs(snap) ⇒ Object
30 31 32 |
# File 'lib/new_relic/agent/vm/mri_vm.rb', line 30 def gather_gc_runs(snap) snap.gc_runs = GC.count end |
#gather_gc_stats(snap) ⇒ Object
25 26 27 28 |
# File 'lib/new_relic/agent/vm/mri_vm.rb', line 25 def gather_gc_stats(snap) gather_gc_runs(snap) if supports?(:gc_runs) gather_derived_stats(snap) if GC.respond_to?(:stat) end |
#gather_gc_time(snap) ⇒ Object
51 52 53 54 55 |
# File 'lib/new_relic/agent/vm/mri_vm.rb', line 51 def gather_gc_time(snap) return unless supports?(:gc_total_time) snap.gc_total_time = NewRelic::Agent.instance.monotonic_gc_profiler.total_time_s end |
#gather_ruby_vm_stats(snap) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/new_relic/agent/vm/mri_vm.rb', line 57 def gather_ruby_vm_stats(snap) if supports?(:method_cache_invalidations) snap.method_cache_invalidations = RubyVM.stat[:global_method_state] end if supports?(:constant_cache_invalidations) snap.constant_cache_invalidations = gather_constant_cache_invalidations end if supports?(:constant_cache_misses) snap.constant_cache_misses = gather_constant_cache_misses end end |
#gather_stats(snap) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/new_relic/agent/vm/mri_vm.rb', line 18 def gather_stats(snap) gather_gc_stats(snap) gather_ruby_vm_stats(snap) gather_thread_stats(snap) gather_gc_time(snap) end |
#gather_thread_stats(snap) ⇒ Object
79 80 81 |
# File 'lib/new_relic/agent/vm/mri_vm.rb', line 79 def gather_thread_stats(snap) snap.thread_count = Thread.list.size end |
#snapshot ⇒ Object
12 13 14 15 16 |
# File 'lib/new_relic/agent/vm/mri_vm.rb', line 12 def snapshot snap = Snapshot.new gather_stats(snap) snap end |
#supports?(key) ⇒ Boolean
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/new_relic/agent/vm/mri_vm.rb', line 83 def supports?(key) case key when :gc_runs, :total_allocated_object, :heap_live, :heap_free, :thread_count, :major_gc_count, :minor_gc_count, :constant_cache_invalidations true when :gc_total_time NewRelic::LanguageSupport.gc_profiler_enabled? when :method_cache_invalidations RUBY_VERSION < '3.0.0' when :constant_cache_misses RUBY_VERSION >= '3.2.0' else false end end |