class OneApm::Support::VM::MriVM

Public Instance Methods

gather_gc_stats(snap) click to toggle source
# File lib/one_apm/support/vm/mri_vm.rb, line 23
def gather_gc_stats(snap)
  if supports?(:gc_runs)
    snap.gc_runs = GC.count
  end

  if GC.respond_to?(:stat)
    gc_stats = GC.stat
    snap.total_allocated_object = gc_stats[:total_allocated_objects] || gc_stats[:total_allocated_object]
    snap.major_gc_count = gc_stats[:major_gc_count]
    snap.minor_gc_count = gc_stats[:minor_gc_count]
    snap.heap_live = gc_stats[:heap_live_slots] || gc_stats[:heap_live_slot] || gc_stats[:heap_live_num]
    snap.heap_free = gc_stats[:heap_free_slots] || gc_stats[:heap_free_slot] || gc_stats[:heap_free_num]
  end
end
gather_gc_time(snap) click to toggle source
# File lib/one_apm/support/vm/mri_vm.rb, line 38
def gather_gc_time(snap)
  if supports?(:gc_total_time)
    snap.gc_total_time = OneApm::Manager.agent.monotonic_gc_profiler.total_time_s
  end
end
gather_ruby_vm_stats(snap) click to toggle source
# File lib/one_apm/support/vm/mri_vm.rb, line 44
def gather_ruby_vm_stats(snap)
  if supports?(:method_cache_invalidations)
    vm_stats = RubyVM.stat
    snap.method_cache_invalidations = vm_stats[:global_method_state]
    snap.constant_cache_invalidations = vm_stats[:global_constant_state]
  end
end
gather_stats(snap) click to toggle source
# File lib/one_apm/support/vm/mri_vm.rb, line 16
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) click to toggle source
# File lib/one_apm/support/vm/mri_vm.rb, line 52
def gather_thread_stats(snap)
  snap.thread_count = Thread.list.size
end
snapshot() click to toggle source
# File lib/one_apm/support/vm/mri_vm.rb, line 10
def snapshot
  snap = Snapshot.new
  gather_stats(snap)
  snap
end
supports?(key) click to toggle source
# File lib/one_apm/support/vm/mri_vm.rb, line 56
def supports?(key)
  case key
  when :gc_runs
    RUBY_VERSION >= '1.9.2'
  when :gc_total_time
    OneApm::LanguageSupport.gc_profiler_enabled?
  when :total_allocated_object
    RUBY_VERSION >= '2.0.0'
  when :major_gc_count
    RUBY_VERSION >= '2.1.0'
  when :minor_gc_count
    RUBY_VERSION >= '2.1.0'
  when :heap_live
    RUBY_VERSION >= '1.9.3'
  when :heap_free
    RUBY_VERSION >= '1.9.3'
  when :method_cache_invalidations
    RUBY_VERSION >= '2.1.0'
  when :constant_cache_invalidations
    RUBY_VERSION >= '2.1.0'
  when :thread_count
    true
  else
    false
  end
end