Show
Ignore:
Timestamp:
12/07/07 08:53:56 (5 years ago)
Author:
coji
Message:

lang/ruby/ssb: refactored TimeStamp?

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/ruby/ssb/trunk/libs/ssb/time_stamper.rb

    r1870 r2704  
    88module SSB 
    99  class TimeStamper 
    10     def initialize 
     10    attr_reader :log 
     11 
     12    # { span_label => [stamp_from, stamp_to], ... } 
     13    def initialize(span_defs = nil) 
     14      @span_defs = Hash.new 
     15      @span_defs.update(span_defs) unless span_defs.nil? 
    1116      @log = Hash.new 
    1217    end 
    1318 
    14     def stamp(label) 
    15       @log[label] = Time.now 
    16       @log[label] 
     19    def span_labels 
     20      @span_defs.keys 
    1721    end 
    1822 
    19     def diff(from, to) 
    20       ((self[to].to_f - self[from].to_f)*1000).to_i 
     23    def span(label) 
     24      diff(@span_defs[label][0], @span_defs[label][1]) 
     25    end 
     26 
     27    def stamp(stamp, time = Time.now) 
     28      @log[stamp] = time 
     29    end 
     30 
     31    def diff(stamp_from, stamp_to) 
     32      ((@log[stamp_to].to_f - @log[stamp_from].to_f)*1000).to_i 
    2133    end 
    2234 
     
    2840      @log[label] 
    2941    end 
     42 
     43    def method_missing(msg, *args) 
     44      if span_labels.include?(msg.to_sym) 
     45        span(msg.to_sym) 
     46      else 
     47        #super 
     48      end 
     49    end 
    3050  end 
    3151end