Class: Amalgalite::ProfileSampler
- Inherits:
-
Object
- Object
- Amalgalite::ProfileSampler
- Defined in:
- lib/amalgalite/profile_tap.rb
Overview
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
Instance Method Summary collapse
-
#initialize(name) ⇒ ProfileSampler
constructor
create a new sampler with the given name.
-
#mean ⇒ Object
return the mean of the data.
-
#reset! ⇒ Object
reset the internal state so it may be used again.
-
#sample(value) ⇒ Object
add a sample to the calculations.
-
#stddev ⇒ Object
returns the standard deviation of the data.
-
#to_a ⇒ Object
return all the values as an array.
-
#to_h ⇒ Object
return all the values as a hash.
-
#to_s ⇒ Object
return a string containing the sampler summary.
Constructor Details
#initialize(name) ⇒ ProfileSampler
create a new sampler with the given name
16 17 18 19 |
# File 'lib/amalgalite/profile_tap.rb', line 16 def initialize( name ) @name = name reset! end |
Instance Method Details
#mean ⇒ Object
return the mean of the data
50 51 52 |
# File 'lib/amalgalite/profile_tap.rb', line 50 def mean @sum / @n end |
#reset! ⇒ Object
reset the internal state so it may be used again
24 25 26 27 28 29 30 |
# 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) ⇒ Object
add a sample to the calculations
35 36 37 38 39 40 41 42 43 44 45 |
# 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 ⇒ Object
returns the standard deviation of the data
57 58 59 60 61 62 63 64 |
# 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 ⇒ Object
return all the values as an array
69 70 71 |
# File 'lib/amalgalite/profile_tap.rb', line 69 def to_a [ @name, @sum, @sumsq, @n, mean, stddev, @min, @max ] end |
#to_h ⇒ Object
return all the values as a hash
76 77 78 79 80 |
# 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 ⇒ Object
return a string containing the sampler summary
85 86 87 |
# 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 |