| Class | Amalgalite::ProfileSampler |
| In: |
lib/amalgalite/profile_tap.rb
|
| Parent: | Object |
A ProfileSampler is a sampler of profile times. It aggregates up profile events that happen for the same source. It is based upon the RFuzz::Sampler class from the rfuzz gem
reset the internal state so it may be used again
# File lib/amalgalite/profile_tap.rb, line 24
24: def reset!
25: @sum = 0.0
26: @sumsq = 0.0
27: @n = 0
28: @min = 0.0
29: @max = 0.0
30: end
add a sample to the calculations
# File lib/amalgalite/profile_tap.rb, line 35
35: def sample( value )
36: @sum += value
37: @sumsq += (value * value)
38: if @n == 0 then
39: @min = @max = value
40: else
41: @min = value if value < @min
42: @max = value if value > @max
43: end
44: @n += 1
45: end
returns the standard deviation of the data
# File lib/amalgalite/profile_tap.rb, line 57
57: def stddev
58: begin
59: Math.sqrt( (@sumsq - ( @sum * @sum / @n)) / (@n-1) )
60: rescue Errno::EDOM
61: return 0.0
62: end
63: end
return all the values as an array
# File lib/amalgalite/profile_tap.rb, line 68
68: def to_a
69: [ @name, @sum, @sumsq, @n, mean, stddev, @min, @max ]
70: end