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

Methods

mean   new   reset!   sample   stddev   to_a   to_h   to_s  

Public Class methods

create a new sampler with the given name

[Source]

    # File lib/amalgalite/profile_tap.rb, line 16
16:     def initialize( name )
17:       @name = name
18:       reset!
19:     end

Public Instance methods

return the mean of the data

[Source]

    # File lib/amalgalite/profile_tap.rb, line 50
50:     def mean
51:       @sum / @n
52:     end

reset the internal state so it may be used again

[Source]

    # 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

[Source]

    # 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

[Source]

    # 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

[Source]

    # File lib/amalgalite/profile_tap.rb, line 68
68:     def to_a
69:       [ @name, @sum, @sumsq, @n, mean, stddev, @min, @max ]
70:     end

return all the values as a hash

[Source]

    # File lib/amalgalite/profile_tap.rb, line 75
75:     def to_h
76:       { 'name'    => @name,  'n' => @n,
77:         'sum'     => @sum,   'sumsq'   => @sumsq, 'mean'    => mean,
78:         'stddev'  => stddev, 'min'     => @min,   'max'     => @max }
79:     end

return a string containing the sampler summary

[Source]

    # File lib/amalgalite/profile_tap.rb, line 84
84:     def to_s
85:       "[%s] => sum: %d, sumsq: %d, n: %d, mean: %0.6f, stddev: %0.6f, min: %d, max: %d" % to_a
86:     end

[Validate]