Class: OneApm::Support::VM::MriVM

Inherits:
Object
  • Object
show all
Defined in:
lib/one_apm/support/vm/mri_vm.rb

Instance Method Summary collapse

Instance Method Details

#gather_gc_stats(snap) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 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) ⇒ Object



38
39
40
41
42
# 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) ⇒ Object



44
45
46
47
48
49
50
# 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) ⇒ Object



16
17
18
19
20
21
# 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) ⇒ Object



52
53
54
# File 'lib/one_apm/support/vm/mri_vm.rb', line 52

def gather_thread_stats(snap)
  snap.thread_count = Thread.list.size
end

#snapshotObject



10
11
12
13
14
# File 'lib/one_apm/support/vm/mri_vm.rb', line 10

def snapshot
  snap = Snapshot.new
  gather_stats(snap)
  snap
end

#supports?(key) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# 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