Class: Barnes::Instruments::RubyGC
- Inherits:
-
Object
- Object
- Barnes::Instruments::RubyGC
- Defined in:
- lib/barnes/instruments/ruby_gc.rb
Constant Summary collapse
- COUNTERS =
{ :count => :'GC.count', :major_gc_count => :'GC.major_count', :minor_gc_count => :'GC.minor_gc_count' }
- GAUGE_COUNTERS =
{}
Instance Method Summary collapse
-
#initialize(sample_rate) ⇒ RubyGC
constructor
A new instance of RubyGC.
- #instrument!(state, counters, gauges) ⇒ Object
- #start!(state) ⇒ Object
Constructor Details
#initialize(sample_rate) ⇒ RubyGC
Returns a new instance of RubyGC.
53 54 55 56 |
# 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 |
Instance Method Details
#instrument!(state, counters, gauges) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# 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) ⇒ Object
58 59 60 |
# File 'lib/barnes/instruments/ruby_gc.rb', line 58 def start!(state) state[:ruby_gc] = GC.stat end |