class Trashed::Meter

Attributes

instruments[R]

Public Class Methods

new() click to toggle source
# File lib/trashed/meter.rb, line 5
def initialize
  @timers = []
  @gauges = []
end

Public Instance Methods

counts(name, &block) click to toggle source

Counters increase, so we measure before/after differences. Time elapsed, memory growth, objects allocated, etc.

# File lib/trashed/meter.rb, line 12
def counts(name, &block)
  instrument ChangeInstrument.new(name, block)
end
gauges(name, &block) click to toggle source

Gauges measure point-in-time values. Heap size, live objects, GC count, etc.

# File lib/trashed/meter.rb, line 18
def gauges(name, &block)
  instrument GaugeInstrument.new(name, block)
end
instrument(instrument) click to toggle source
# File lib/trashed/meter.rb, line 22
def instrument(instrument)
  if instrument.respond_to?(:start)
    @timers << instrument
  else
    @gauges << instrument
  end
end
instrument!(state, timings, gauges) { || ... } click to toggle source
# File lib/trashed/meter.rb, line 30
def instrument!(state, timings, gauges)
  @timers.each { |i| i.start state, timings, gauges }
  yield.tap do
    @timers.reverse_each { |i| i.measure state, timings, gauges }
    @gauges.each { |i| i.measure state, timings, gauges }
  end