Class | Mongrel::Stats |
In: |
lib/mongrel/stats.rb
lib/mongrel/stats.rb |
Parent: | Object |
max | [R] | |
max | [R] | |
min | [R] | |
min | [R] | |
n | [R] | |
n | [R] | |
sum | [R] | |
sum | [R] | |
sumsq | [R] | |
sumsq | [R] |
Resets the internal counters so you can start sampling again.
# File lib/mongrel/stats.rb, line 25 25: def reset 26: @sum = 0.0 27: @sumsq = 0.0 28: @last_time = Time.new 29: @n = 0.0 30: @min = 0.0 31: @max = 0.0 32: end
Resets the internal counters so you can start sampling again.
# File lib/mongrel/stats.rb, line 25 25: def reset 26: @sum = 0.0 27: @sumsq = 0.0 28: @last_time = Time.new 29: @n = 0.0 30: @min = 0.0 31: @max = 0.0 32: end
Adds a sampling to the calculations.
# File lib/mongrel/stats.rb, line 35 35: def sample(s) 36: @sum += s 37: @sumsq += s * s 38: if @n == 0 39: @min = @max = s 40: else 41: @min = s if @min > s 42: @max = s if @max < s 43: end 44: @n+=1 45: end
Adds a sampling to the calculations.
# File lib/mongrel/stats.rb, line 35 35: def sample(s) 36: @sum += s 37: @sumsq += s * s 38: if @n == 0 39: @min = @max = s 40: else 41: @min = s if @min > s 42: @max = s if @max < s 43: end 44: @n+=1 45: end
Calculates the standard deviation of the data so far.
# File lib/mongrel/stats.rb, line 64 64: def sd 65: # (sqrt( ((s).sumsq - ( (s).sum * (s).sum / (s).n)) / ((s).n-1) )) 66: begin 67: return Math.sqrt( (@sumsq - ( @sum * @sum / @n)) / (@n-1) ) 68: rescue Errno::EDOM 69: return 0.0 70: end 71: end
Calculates the standard deviation of the data so far.
# File lib/mongrel/stats.rb, line 64 64: def sd 65: # (sqrt( ((s).sumsq - ( (s).sum * (s).sum / (s).n)) / ((s).n-1) )) 66: begin 67: return Math.sqrt( (@sumsq - ( @sum * @sum / @n)) / (@n-1) ) 68: rescue Errno::EDOM 69: return 0.0 70: end 71: end
Adds a time delta between now and the last time you called this. This will give you the average time between two activities.
An example is:
t = Stats.new("do_stuff") 10000.times { do_stuff(); t.tick } t.dump("time")
# File lib/mongrel/stats.rb, line 83 83: def tick 84: now = Time.now 85: sample(now - @last_time) 86: @last_time = now 87: end
Adds a time delta between now and the last time you called this. This will give you the average time between two activities.
An example is:
t = Stats.new("do_stuff") 10000.times { do_stuff(); t.tick } t.dump("time")
# File lib/mongrel/stats.rb, line 83 83: def tick 84: now = Time.now 85: sample(now - @last_time) 86: @last_time = now 87: end