Class: NewRelic::Agent::VM::CRubyVM

Inherits:
Object
  • Object
show all
Defined in:
lib/new_relic/agent/vm/c_ruby_vm.rb

Instance Method Summary collapse

Instance Method Details

#gather_constant_cache_invalidationsObject



63
64
65
# File 'lib/new_relic/agent/vm/c_ruby_vm.rb', line 63

def gather_constant_cache_invalidations
  RubyVM.stat[RUBY_VERSION >= '3.2.0' ? :constant_cache_invalidations : :global_constant_state]
end

#gather_constant_cache_missesObject



67
68
69
# File 'lib/new_relic/agent/vm/c_ruby_vm.rb', line 67

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/c_ruby_vm.rb', line 34

def gather_derived_stats(snap)
  stat = GC.stat
  snap.total_allocated_object = stat.fetch(:total_allocated_objects, nil)
  snap.major_gc_count = stat.fetch(:major_gc_count, nil)
  snap.minor_gc_count = stat.fetch(:minor_gc_count, nil)
  snap.heap_live = stat.fetch(:heap_live_slots, nil)
  snap.heap_free = stat.fetch(:heap_free_slots, nil)
end

#gather_gc_runs(snap) ⇒ Object



30
31
32
# File 'lib/new_relic/agent/vm/c_ruby_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/c_ruby_vm.rb', line 25

def gather_gc_stats(snap)
  gather_gc_runs(snap) if supports?(:gc_runs)
  gather_derived_stats(snap)
end

#gather_gc_time(snap) ⇒ Object



43
44
45
46
47
# File 'lib/new_relic/agent/vm/c_ruby_vm.rb', line 43

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



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/new_relic/agent/vm/c_ruby_vm.rb', line 49

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/c_ruby_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



71
72
73
# File 'lib/new_relic/agent/vm/c_ruby_vm.rb', line 71

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

#snapshotObject



12
13
14
15
16
# File 'lib/new_relic/agent/vm/c_ruby_vm.rb', line 12

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

#supports?(key) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/new_relic/agent/vm/c_ruby_vm.rb', line 75

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