Class Logging::Stats::Sampler
In: lib/logging/stats.rb
Parent: Object

A very simple little class for doing some basic fast statistics sampling. You feed it either samples of numeric data you want measured or you call Sampler#tick to get it to add a time delta between the last time you called it. When you‘re done either call sum, sumsq, num, min, max, mean or sd to get the information. The other option is to just call to_s and see everything.

It does all of this very fast and doesn‘t take up any memory since the samples are not stored but instead all the values are calculated on the fly.

Methods

coalesce   keys   mark   mean   new   reset   sample   sd   tick   to_a   to_hash   to_s  

Attributes

last  [R] 
max  [R] 
min  [R] 
name  [R] 
num  [R] 
sum  [R] 
sumsq  [R] 

Public Class methods

Class method that returns the headers that a CSV file would have for the values that this stats object is using.

Create a new sampler.

Public Instance methods

Coalesce the statistics from the other sampler into this one. The other sampler is not modified by this method.

Coalescing the same two samplers mutliple times should only be done if one of the samplers is reset between calls to this method. Otherwise statistics will be counted multiple times.

You can just call tick repeatedly if you need the delta times between a set of sample periods, but many times you actually want to sample how long something takes between a start/end period. Call mark at the beginning and then tick at the end you‘ll get this kind of measurement. Don‘t mix mark/tick and tick sampling together or the measurement will be meaningless.

Calculates and returns the mean for the data passed so far.

Resets the internal counters so you can start sampling again.

Adds a sampling to the calculations.

Calculates the standard deviation of the data so far.

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 = Sampler.new("do_stuff")
 10000.times { do_stuff(); t.tick }
 t.dump("time")

An array of the values: [name,sum,sumsq,num,mean,sd,min,max]

Returns statistics in a common format.

[Validate]