class Barnes::Instruments::RubyGC

Constants

COUNTERS
GAUGE_COUNTERS

Public Class Methods

new(sample_rate) click to toggle source
# File lib/barnes/instruments/ruby_gc.rb, line 53
def initialize(sample_rate)
  # see header for an explanation of how this sample_rate is used
  @sample_rate = sample_rate
end

Public Instance Methods

instrument!(state, counters, gauges) click to toggle source
# File lib/barnes/instruments/ruby_gc.rb, line 62
def instrument!(state, counters, gauges)
  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) click to toggle source
# File lib/barnes/instruments/ruby_gc.rb, line 58
def start!(state)
  state[:ruby_gc] = GC.stat
end