Class: Takwimu::Instruments::RubyGC

Inherits:
Object
  • Object
show all
Defined in:
lib/takwimu/instruments/ruby_gc.rb

Constant Summary collapse

COUNTERS =
{
  :count => :'GC.count',
  :major_gc_count => :'GC.major_count',
  :minor_gc_count => :'GC.minor_gc_count',
  :heap_allocated_pages => :'GC.heap_allocated_pages',
  :heap_sorted_length => :'GC.heap_sorted_length',
  :heap_allocatable_pages => :'GC.heap_allocatable_pages',
  :heap_available_slots => :'GC.heap_available_slots',
  :heap_live_slots => :'GC.heap_live_slots',
  :heap_free_slots => :'GC.heap_free_slots',
  :heap_final_slots => :'GC.heap_final_slots',
  :heap_marked_slots => :'GC.heap_marked_slots',
  :heap_swept_slots => :'GC.heap_swept_slots',
  :heap_eden_pages => :'GC.heap_eden_pages',
  :heap_tomb_pages => :'GC.heap_tomb_pages',
  :total_allocated_pages => :'GC.total_allocated_pages',
  :total_freed_pages => :'GC.total_freed_pages',
  :total_allocated_objects => :'GC.total_allocated_objects',
  :total_freed_objects => :'GC.total_freed_objects',
  :malloc_increase_bytes => :'GC.malloc_increase_bytes',
  :malloc_increase_bytes_limit => :'GC.malloc_increase_bytes_limit',
  :remembered_wb_unprotected_objects => :'GC.remembered_wb_unprotected_objects',
  :remembered_wb_unprotected_objects_limit => :'GC.remembered_wb_unprotected_objects_limit',
  :old_objects => :'GC.old_objects',
  :old_objects_limit => :'GC.old_objects_limit',
  :oldmalloc_increase_bytes => :'GC.oldmalloc_increase_bytes',
  :oldmalloc_increase_bytes_limit => :'GC.oldmalloc_increase_bytes_limit'
}
GAUGE_COUNTERS =
{}

Instance Method Summary collapse

Constructor Details

#initialize(sample_rate) ⇒ RubyGC

Returns a new instance of RubyGC.



77
78
79
80
# File 'lib/takwimu/instruments/ruby_gc.rb', line 77

def initialize(sample_rate)
  # see header for an explanation of how this sample_rate is used
  @sample_rate = sample_rate
end

Instance Method Details

#instrument!(state, counters, gauges, timers) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/takwimu/instruments/ruby_gc.rb', line 86

def instrument!(state, counters, gauges, timers)
  last = state[:ruby_gc]
  cur = state[:ruby_gc] = GC.stat

  COUNTERS.each do |stat, metric|
    counters[metric] = cur[stat] - last[stat] if cur.include? stat
  end

  # special treatment gauges
  GAUGE_COUNTERS.each do |stat, metric|
    if cur.include? stat
      val = cur[stat] - last[stat] if cur.include? stat
      gauges[metric] = val * (1/@sample_rate)
    end
  end

  # the rest of the gauges
  cur.each do |k, v|
    unless GAUGE_COUNTERS.include? k
      gauges[:"GC.#{k}"] = v
    end
  end
end

#start!(state) ⇒ Object



82
83
84
# File 'lib/takwimu/instruments/ruby_gc.rb', line 82

def start!(state)
  state[:ruby_gc] = GC.stat
end