Class: RFuzz::StatsTracker

Inherits:
Object
  • Object
show all
Defined in:
lib/rfuzz/stats.rb

Overview

When registered as the notifier for a client it tracks the times for each part of the request. Rather than subclassing RFuzz::Notifier it uses a method_missing to record the even timings.

You can dump it with to_s, or you can access the StatsTracker.stats hash to read the RFuzz::Sampler objects related to each event.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStatsTracker

Returns a new instance of StatsTracker.



123
124
125
126
# File 'lib/rfuzz/stats.rb', line 123

def initialize
  @stats = {}
  @error_count = 0
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(event, *args) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/rfuzz/stats.rb', line 141

def method_missing(event, *args)
  case args[0]
  when :begins
    mark(:request) if event == :connect
    mark(event)
  when :ends
    sample(:request) if event == :close
    sample(event)
  when :error
    sample(:request)
    @error_count += 1
  end
end

Instance Attribute Details

#statsObject (readonly)

Returns the value of attribute stats.



121
122
123
# File 'lib/rfuzz/stats.rb', line 121

def stats
  @stats
end

Instance Method Details

#mark(event) ⇒ Object



128
129
130
131
# File 'lib/rfuzz/stats.rb', line 128

def mark(event)
  @stats[event] ||= RFuzz::Sampler.new(event)
  @stats[event].mark
end

#resetObject



137
138
139
# File 'lib/rfuzz/stats.rb', line 137

def reset
  @stats.each {|e,s| s.reset }
end

#sample(event) ⇒ Object



133
134
135
# File 'lib/rfuzz/stats.rb', line 133

def sample(event)
  @stats[event].tick
end

#to_sObject



155
156
157
# File 'lib/rfuzz/stats.rb', line 155

def to_s
  "#{@stats.values.join("\n")}\nErrors: #@error_count"
end