Class: Twingly::Metrics::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/twingly/metrics/timer.rb

Defined Under Namespace

Classes: Context

Instance Method Summary collapse

Constructor Details

#initialize(histogram = Twingly::Metrics::Histogram.new_exponentially_decaying) ⇒ Timer

Returns a new instance of Timer.



27
28
29
30
# File 'lib/twingly/metrics/timer.rb', line 27

def initialize(histogram = Twingly::Metrics::Histogram.new_exponentially_decaying)
  @meter     = Twingly::Metrics::Meter.new
  @histogram = histogram
end

Instance Method Details

#clearObject



32
33
34
35
# File 'lib/twingly/metrics/timer.rb', line 32

def clear
  @meter.clear
  @histogram.clear
end

#countObject



61
62
63
# File 'lib/twingly/metrics/timer.rb', line 61

def count
  @histogram.count
end

#fifteen_minute_rateObject



77
78
79
# File 'lib/twingly/metrics/timer.rb', line 77

def fifteen_minute_rate
  @meter.fifteen_minute_rate
end

#five_minute_rateObject



73
74
75
# File 'lib/twingly/metrics/timer.rb', line 73

def five_minute_rate
  @meter.five_minute_rate
end

#maxObject



89
90
91
# File 'lib/twingly/metrics/timer.rb', line 89

def max
  @histogram.max
end

#meanObject



93
94
95
# File 'lib/twingly/metrics/timer.rb', line 93

def mean
  @histogram.mean
end

#mean_rateObject



81
82
83
# File 'lib/twingly/metrics/timer.rb', line 81

def mean_rate
  @meter.mean_rate
end

#minObject



85
86
87
# File 'lib/twingly/metrics/timer.rb', line 85

def min
  @histogram.min
end

#one_minute_rateObject



69
70
71
# File 'lib/twingly/metrics/timer.rb', line 69

def one_minute_rate
  @meter.one_minute_rate
end

#snapshotObject



57
58
59
# File 'lib/twingly/metrics/timer.rb', line 57

def snapshot
  @histogram.snapshot
end

#stddevObject



97
98
99
# File 'lib/twingly/metrics/timer.rb', line 97

def stddev
  @histogram.stddev
end

#stopObject



101
102
103
# File 'lib/twingly/metrics/timer.rb', line 101

def stop
  @meter.stop
end

#sumObject



65
66
67
# File 'lib/twingly/metrics/timer.rb', line 65

def sum
  @histogram.sum
end

#time(callable = nil, &block) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/twingly/metrics/timer.rb', line 44

def time(callable = nil, &block)
  callable ||= block
  context = Context.new(self)

  return context if callable.nil?

  begin
    callable.call
  ensure
    context.stop
  end
end

#update(duration) ⇒ Object



37
38
39
40
41
42
# File 'lib/twingly/metrics/timer.rb', line 37

def update(duration)
  return unless duration >= 0

  @meter.mark
  @histogram.update(duration)
end