vpr::SampleLimitedStatCollector< TYPE, TimeBased > Class Template Reference

Statistics collection class. More...

#include <vpr/Util/SampleLimitedStatCollector.h>

Collaboration diagram for vpr::SampleLimitedStatCollector< TYPE, TimeBased >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 SampleLimitedStatCollector (const unsigned int sampleLimit=100)
 Constructor.
void reset ()
void addSample (const TYPE sample)
TYPE getTotal () const
vpr::Uint32 getNumSamples () const
double getMean ()
 Return Mean (value/second).
double getInstAverage ()
double getSTA ()
double getMaxSTA () const
void print (std::ostream &out)

Detailed Description

template<class TYPE, bool TimeBased>
class vpr::SampleLimitedStatCollector< TYPE, TimeBased >

Statistics collection class.

STA: Short Term Average (a time-limited average)

Parameters:
TYPE The sample type.
TimeBased Should the return values be per second or just "normal" stats? This is basically the difference between discrete and continuous values (or interpretation of the values).

Definition at line 69 of file SampleLimitedStatCollector.h.


Constructor & Destructor Documentation

template<class TYPE, bool TimeBased>
vpr::SampleLimitedStatCollector< TYPE, TimeBased >::SampleLimitedStatCollector ( const unsigned int  sampleLimit = 100  )  [inline]

Constructor.

Parameters:
sampleLimit The max age for samples in the sta computation.

Definition at line 77 of file SampleLimitedStatCollector.h.

00078    {
00079       mSTASampleLimit = sampleLimit;
00080       reset();
00081    }


Member Function Documentation

template<class TYPE, bool TimeBased>
void vpr::SampleLimitedStatCollector< TYPE, TimeBased >::reset (  )  [inline]

Definition at line 83 of file SampleLimitedStatCollector.h.

Referenced by vpr::SampleLimitedStatCollector< double, false >::SampleLimitedStatCollector().

00084    {
00085       mCurTotal = 0;
00086       mSampleCount = 0;
00087 
00088       mMaxSTA = 0.0;
00089       mRunningSTATotal = 0.0f;
00090       mPrevSample1 = 0;
00091       mPrevSample2 = 0;
00092 
00093       mCurSampleIndex = 0;
00094       mSampleBuffer.clear();
00095       mSampleBuffer.resize(mSTASampleLimit);
00096    }

template<class TYPE, bool TimeBased>
void vpr::SampleLimitedStatCollector< TYPE, TimeBased >::addSample ( const TYPE  sample  ) 

Definition at line 162 of file SampleLimitedStatCollector.h.

References vpr::SampleLimitedStatCollector< TYPE, TimeBased >::getSTA(), vpr::DateTime::setNow(), vpr::Interval::setNow(), and vprASSERT.

00163 {
00164    mCurTotal += sample;
00165    mSampleCount += 1;
00166 
00167    vpr::Interval cur_time;
00168 
00169    if(TimeBased)
00170    {
00171       cur_time.setNow();                     // Set current time
00172 
00173       // Set Init time
00174       if(mSampleCount == 1)              // First send -- INIT TIMES
00175       {
00176          mInitialSampleTime.setNow();    // Initialize first read time
00177       }
00178 
00179       mPrevSampleTime1 = mPrevSampleTime2;      // Time of last 2 samples (mPrevST1 < mPrevSt2)
00180       mPrevSampleTime2 = cur_time;
00181    }
00182 
00183    // Update recent sample values for INST average
00184    mPrevSample1 = mPrevSample2;
00185    mPrevSample2 = sample;
00186 
00187    // Add value to sample buffer
00188    mRunningSTATotal += sample;                           // Add on new value
00189    mRunningSTATotal -= mSampleBuffer[mCurSampleIndex].first;   // Subtract off old value (note: this is 0 when not set yet)
00190    mSampleBuffer[mCurSampleIndex] = std::pair<TYPE,vpr::Interval>(sample, cur_time);
00191 
00192    // Goto next index
00193    ++mCurSampleIndex;
00194    if(mCurSampleIndex == mSTASampleLimit)
00195    {
00196       mCurSampleIndex = 0;
00197    }
00198    vprASSERT(mCurSampleIndex < mSTASampleLimit && "Should never get larger then SampleLimit");
00199 
00200    // --- UPDATE MAXES ---- //
00201    double sta_value = getSTA();
00202    if(sta_value > mMaxSTA)                        // Check for new max
00203    {
00204       mMaxSTA = sta_value;
00205    }
00206 }

template<class TYPE, bool TimeBased>
TYPE vpr::SampleLimitedStatCollector< TYPE, TimeBased >::getTotal (  )  const [inline]

Definition at line 100 of file SampleLimitedStatCollector.h.

00101    {
00102       return mCurTotal;
00103    }

template<class TYPE, bool TimeBased>
vpr::Uint32 vpr::SampleLimitedStatCollector< TYPE, TimeBased >::getNumSamples (  )  const [inline]

Definition at line 105 of file SampleLimitedStatCollector.h.

00106    {
00107       return mSampleCount;
00108    }

template<class TYPE, bool TimeBased>
double vpr::SampleLimitedStatCollector< TYPE, TimeBased >::getMean (  ) 

Return Mean (value/second).

Definition at line 209 of file SampleLimitedStatCollector.h.

References vpr::DateTime::getSecondsf(), and vpr::DateTime::setNow().

Referenced by vpr::SampleLimitedStatCollector< TYPE, TimeBased >::print().

00210 {
00211    if(0 == mCurTotal)
00212    {
00213       return 0.0f;
00214    }
00215 
00216    double mean_result(0.0);
00217 
00218    if(TimeBased)
00219    {
00220       vpr::DateTime cur_date_time, diff_date_time;
00221       double diff_secs;
00222 
00223       cur_date_time.setNow();
00224       diff_date_time = cur_date_time - mInitialSampleTime;
00225       diff_secs = diff_date_time.getSecondsf();
00226 
00227       mean_result = double(mCurTotal)/diff_secs;
00228    }
00229    else
00230    {
00231       mean_result = double(mCurTotal)/double(mSampleCount);
00232    }
00233 
00234    return mean_result;
00235 }

template<class TYPE, bool TimeBased>
double vpr::SampleLimitedStatCollector< TYPE, TimeBased >::getInstAverage (  ) 

Definition at line 238 of file SampleLimitedStatCollector.h.

References vpr::Interval::secf(), and vpr::Interval::setNow().

00239 {
00240    double inst_average(0.0);
00241 
00242    if(TimeBased)
00243    {
00244       //
00245       //     |
00246       //     |                  |
00247       //     |                  |
00248       // mPrevTime1        mPrevTime2             cur_time
00249       vpr::Interval cur_time, diff_time;
00250       double diff_sec;                       // Num secs different in send times
00251       cur_time.setNow();                     // Set current time
00252       diff_time = cur_time - mPrevSampleTime1;     // Get time to compute the average over
00253       diff_sec = diff_time.secf();
00254 
00255       // Compute -- INST BANDWIDTH
00256       if(diff_sec > 0)
00257       {
00258         inst_average = double(mPrevSample1 + mPrevSample2)/diff_sec;
00259       }
00260 
00261       // Haven't had sample in quite a while, so clamp to zero.
00262       if(diff_time > this->mSTAMaxTime)
00263       {
00264          inst_average = 0.0;
00265       }
00266    }
00267    else
00268    {
00269       // Just approximate it with the average of the last two entries
00270       inst_average = double(mPrevSample1 + mPrevSample2)/2.0;
00271    }
00272 
00273    return inst_average;
00274 }

template<class TYPE, bool TimeBased>
double vpr::SampleLimitedStatCollector< TYPE, TimeBased >::getSTA (  ) 

Definition at line 277 of file SampleLimitedStatCollector.h.

References vpr::Interval::secf(), and vpr::Interval::setNow().

Referenced by vpr::SampleLimitedStatCollector< TYPE, TimeBased >::addSample().

00278 {
00279    // Compute -- STA BANDWIDTH
00280    double sta_value(0.0f);
00281 
00282    if(mSampleBuffer.size() > 0)
00283    {
00284       if(TimeBased)
00285       {
00286          vpr::Interval cur_time, diff_time;
00287          double diff_sec;                       // Num secs different in send times
00288          cur_time.setNow();                     // Set current time
00289 
00290          vpr::Interval first_sample_time( mSampleBuffer.back().second );
00291          diff_time = cur_time - first_sample_time;
00292          diff_sec = diff_time.secf();
00293          sta_value = mRunningSTATotal/diff_sec;
00294       }
00295       else
00296       {
00297          sta_value = mRunningSTATotal/double(mSampleBuffer.size());      // Compute as average of the buffered samples
00298       }
00299    }
00300 
00301    return sta_value;
00302 }

template<class TYPE, bool TimeBased>
double vpr::SampleLimitedStatCollector< TYPE, TimeBased >::getMaxSTA (  )  const [inline]

Definition at line 114 of file SampleLimitedStatCollector.h.

00115    {
00116       return mMaxSTA;
00117    }

template<class TYPE, bool TimeBased>
void vpr::SampleLimitedStatCollector< TYPE, TimeBased >::print ( std::ostream &  out  ) 

Definition at line 138 of file SampleLimitedStatCollector.h.

References vpr::SampleLimitedStatCollector< TYPE, TimeBased >::getMean(), vpr::DateTime::getMinutesf(), and vpr::Interval::secf().

00139 {
00140    out << "type: " << typeid(TYPE).name() << "   time based:"
00141        << (TimeBased ? "Y" : "N") << std::endl
00142        << "total: " << mCurTotal << "   samples:" << mSampleCount << std::endl
00143        << "mean: " << getMean() << "    sampleLimit:" << mSTASampleLimit
00144        << std::endl
00145        << "Initial Sample Time:" << mInitialSampleTime.getMinutesf()
00146        << std::endl
00147        << "prev sampTime: " << mPrevSampleTime1.secf() << "s   prev sampTime2:"
00148        << mPrevSampleTime2.secf() << std::endl
00149        << "prev samp: " << mPrevSample1 << "   prev samp2:" << mPrevSample2
00150        << std::endl
00151        << " --- data --- time --- " << std::endl;
00152 
00153    for ( typename std::vector< std::pair<TYPE,vpr::Interval> >::iterator i = mSampleBuffer.begin();
00154          i!= mSampleBuffer.end();
00155          ++i )
00156    {
00157       out << (*i).first << "   " << (*i).second.msec() << "ms\n";
00158    }
00159 }


The documentation for this class was generated from the following file:
Generated on Thu Jan 4 10:56:08 2007 for VR Juggler Portable Runtime by  doxygen 1.5.1