class Amalgalite::ProfileSampler
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
Public Class Methods
new( name )
click to toggle source
create a new sampler with the given name
# File lib/amalgalite/profile_tap.rb, line 16 def initialize( name ) @name = name reset! end
Public Instance Methods
mean()
click to toggle source
return the mean of the data
# File lib/amalgalite/profile_tap.rb, line 50 def mean @sum / @n end
reset!()
click to toggle source
reset the internal state so it may be used again
# File lib/amalgalite/profile_tap.rb, line 24 def reset! @sum = 0.0 @sumsq = 0.0 @n = 0 @min = 0.0 @max = 0.0 end
sample( value )
click to toggle source
add a sample to the calculations
# File lib/amalgalite/profile_tap.rb, line 35 def sample( value ) @sum += value @sumsq += (value * value) if @n == 0 then @min = @max = value else @min = value if value < @min @max = value if value > @max end @n += 1 end
stddev()
click to toggle source
returns the standard deviation of the data
# File lib/amalgalite/profile_tap.rb, line 57 def stddev begin return 0.0 if ( 1 == @n ) Math.sqrt( (@sumsq - ( @sum * @sum / @n)) / (@n-1) ) rescue Errno::EDOM return 0.0 end end
to_a()
click to toggle source
return all the values as an array
# File lib/amalgalite/profile_tap.rb, line 69 def to_a [ @name, @sum, @sumsq, @n, mean, stddev, @min, @max ] end
to_h()
click to toggle source
return all the values as a hash
# File lib/amalgalite/profile_tap.rb, line 76 def to_h { 'name' => @name, 'n' => @n, 'sum' => @sum, 'sumsq' => @sumsq, 'mean' => mean, 'stddev' => stddev, 'min' => @min, 'max' => @max } end
to_s()
click to toggle source
return a string containing the sampler summary
# File lib/amalgalite/profile_tap.rb, line 85 def to_s "[%s] => sum: %d, sumsq: %d, n: %d, mean: %0.6f, stddev: %0.6f, min: %d, max: %d" % self.to_a end