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

The Tracker class provides synchronized access to a collection of related samplers.

Methods

coalesce   mark   new   periodically_run   reset   sample   stop   sync   tick   time  

Attributes

stats  [R] 

Public Class methods

Create a new Tracker instance. An optional boolean can be passed in to change the "threadsafe" value of the tracker. By default all trackers are created to be threadsafe.

Public Instance methods

Coalesce the samplers from the other tracker into this one. The other tracker is not modified by this method.

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

Only this tracker is locked when the coalescing is happening. It is left to the user to lock the other tracker if that is the desired behavior. This is a deliberate choice in order to prevent deadlock situations where two threads are contending on the same mutex.

Mark the named event sampler. The sampler will be created if it does not exist.

Periodically execute the given block at the given period. The tracker will be locked while the block is executing.

This method is useful for logging statistics at given interval.

Example

   periodically_run( 300 ) {
     logger = Logging::Logger['stats']
     tracker.each {|sampler| logger << sampler.to_s}
     tracker.reset
   }

Reset all the samplers managed by this tracker.

Add the given value to the named event sampler. The sampler will be created if it does not exist.

Stop the current periodic runner if present.

Obtains an exclusive lock, runs the block, and releases the lock when the block completes. This method is re-entrant so that a single thread can call sync multiple times without hanging the thread.

Tick the named event sampler. The sampler will be created if it does not exist.

Time the execution of the given block and store the results in the named event sampler. The sampler will be created if it does not exist.

[Validate]