Class: IndexerTiming
- Inherits:
-
Object
- Object
- IndexerTiming
- Defined in:
- indexer/app/lib/indexer_timing.rb
Instance Method Summary collapse
-
#add(metric, val) ⇒ Object
-
#initialize ⇒ IndexerTiming
constructor
A new instance of IndexerTiming.
-
#time_block(metric) ⇒ Object
-
#to_s ⇒ Object
-
#total=(ms) ⇒ Object
Constructor Details
#initialize ⇒ IndexerTiming
Returns a new instance of IndexerTiming.
2 3 4 |
# File 'indexer/app/lib/indexer_timing.rb', line 2 def initialize @metrics = {} end |
Instance Method Details
#add(metric, val) ⇒ Object
6 7 8 9 |
# File 'indexer/app/lib/indexer_timing.rb', line 6 def add(metric, val) @metrics[metric] ||= 0 @metrics[metric] += val.to_i end |
#time_block(metric) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'indexer/app/lib/indexer_timing.rb', line 30 def time_block(metric) start_time = Time.now begin yield ensure add(metric, ((Time.now.to_f * 1000) - (start_time.to_f * 1000))) end end |
#to_s ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'indexer/app/lib/indexer_timing.rb', line 11 def to_s subtotal = @metrics.values.inject(0) {|a, b| a + b} if @total # If we have a total, report any difference between the total and the # numbers we have. add(:other, @total - subtotal) else # Otherwise, just tally up our numbers to determine the total. @total = subtotal end "#{@total.to_i} ms (#{@metrics.map {|k, v| "#{k}: #{v}"}.join('; ')})" end |
#total=(ms) ⇒ Object
26 27 28 |
# File 'indexer/app/lib/indexer_timing.rb', line 26 def total=(ms) @total = ms end |