Class: Trashed::Meter
- Inherits:
-
Object
- Object
- Trashed::Meter
- Defined in:
- lib/trashed/meter.rb
Defined Under Namespace
Classes: ChangeInstrument, GaugeInstrument
Instance Attribute Summary collapse
-
#instruments ⇒ Object
readonly
Returns the value of attribute instruments.
Instance Method Summary collapse
-
#counts(name, &block) ⇒ Object
Counters increase, so we measure before/after differences.
-
#gauges(name, &block) ⇒ Object
Gauges measure point-in-time values.
-
#initialize ⇒ Meter
constructor
A new instance of Meter.
- #instrument(instrument) ⇒ Object
- #instrument!(state, timings, gauges) ⇒ Object
Constructor Details
#initialize ⇒ Meter
Returns a new instance of Meter.
5 6 7 8 |
# File 'lib/trashed/meter.rb', line 5 def initialize @timers = [] @gauges = [] end |
Instance Attribute Details
#instruments ⇒ Object (readonly)
Returns the value of attribute instruments.
3 4 5 |
# File 'lib/trashed/meter.rb', line 3 def instruments @instruments end |
Instance Method Details
#counts(name, &block) ⇒ Object
Counters increase, so we measure before/after differences. Time elapsed, memory growth, objects allocated, etc.
12 13 14 |
# File 'lib/trashed/meter.rb', line 12 def counts(name, &block) instrument ChangeInstrument.new(name, block) end |
#gauges(name, &block) ⇒ Object
Gauges measure point-in-time values. Heap size, live objects, GC count, etc.
18 19 20 |
# File 'lib/trashed/meter.rb', line 18 def gauges(name, &block) instrument GaugeInstrument.new(name, block) end |
#instrument(instrument) ⇒ Object
22 23 24 25 26 27 28 |
# 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) ⇒ Object
30 31 32 33 34 35 36 |
# 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 end |