Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Examples  

vpr::SampleLimitedStatCollector Class Template Reference

Statistics collection class. More...

#include <SampleLimitedStatCollector.h>

Inheritance diagram for vpr::SampleLimitedStatCollector:

Inheritance graph
[legend]
Collaboration diagram for vpr::SampleLimitedStatCollector:

Collaboration graph
[legend]
List of all members.

Public Methods

 SampleLimitedStatCollector (unsigned sampleLimit=100)
 Constructor. More...

void reset ()
void addSample (const TYPE sample)
TYPE getTotal () const
vpr::Uint32 getNumSamples () const
double getMean ()
 Return Mean (value/second). More...

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:
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 66 of file SampleLimitedStatCollector.h.


Constructor & Destructor Documentation

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

Constructor.

Parameters:
staMaxTime  The max age for samples in the sta computation

Definition at line 72 of file SampleLimitedStatCollector.h.

00073    {
00074       mSTASampleLimit = sampleLimit;
00075       reset();
00076    }


Member Function Documentation

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

Definition at line 78 of file SampleLimitedStatCollector.h.

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

00079    {
00080       mCurTotal = 0;
00081       mSampleCount = 0;
00082 
00083       mMaxSTA = 0.0;
00084       mRunningSTATotal = 0.0f;
00085       mPrevSample1 = 0;
00086       mPrevSample2 = 0;
00087 
00088       mCurSampleIndex = 0;
00089       mSampleBuffer.clear();
00090       mSampleBuffer.resize(mSTASampleLimit);
00091    }

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

Definition at line 145 of file SampleLimitedStatCollector.h.

References getSTA, vpr::DateTime::setNow, vpr::Interval::setNow, and vprASSERT.

00146 {
00147    mCurTotal += sample;
00148    mSampleCount += 1;
00149 
00150    vpr::Interval cur_time;
00151 
00152    if(TimeBased)
00153    {
00154       cur_time.setNow();                     // Set current time
00155 
00156       // Set Init time
00157       if(mSampleCount == 1)              // First send -- INIT TIMES
00158       {
00159          mInitialSampleTime.setNow();    // Initialize first read time
00160       }
00161 
00162       mPrevSampleTime1 = mPrevSampleTime2;      // Time of last 2 samples (mPrevST1 < mPrevSt2)
00163       mPrevSampleTime2 = cur_time;
00164    }
00165 
00166    // Update recent sample values for INST average
00167    mPrevSample1 = mPrevSample2;
00168    mPrevSample2 = sample;
00169 
00170    // Add value to sample buffer
00171    mRunningSTATotal += sample;                           // Add on new value
00172    mRunningSTATotal -= mSampleBuffer[mCurSampleIndex].first;   // Subtract off old value (note: this is 0 when not set yet)
00173    mSampleBuffer[mCurSampleIndex] = std::pair<TYPE,vpr::Interval>(sample, cur_time);
00174 
00175    // Goto next index
00176    ++mCurSampleIndex;
00177    if(mCurSampleIndex == mSTASampleLimit)
00178    {  mCurSampleIndex = 0; }
00179    vprASSERT(mCurSampleIndex < mSTASampleLimit && "Should never get larger then SampleLimit");
00180 
00181    // --- UPDATE MAXES ---- //
00182    double sta_value = getSTA();
00183    if(sta_value > mMaxSTA)                        // Check for new max
00184    {  mMaxSTA = sta_value; }
00185 }

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

Definition at line 95 of file SampleLimitedStatCollector.h.

00096    { return mCurTotal; }

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

Definition at line 97 of file SampleLimitedStatCollector.h.

00098    { return mSampleCount; }

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

Return Mean (value/second).

Definition at line 188 of file SampleLimitedStatCollector.h.

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

Referenced by print.

00189 {
00190    if(0 == mCurTotal)
00191       return 0.0f;
00192 
00193    double mean_result(0.0);
00194 
00195    if(TimeBased)
00196    {
00197       vpr::DateTime cur_date_time, diff_date_time;
00198       double diff_secs;
00199 
00200       cur_date_time.setNow();
00201       diff_date_time = cur_date_time - mInitialSampleTime;
00202       diff_secs = diff_date_time.getSecondsf();
00203 
00204       mean_result = double(mCurTotal)/diff_secs;
00205    }
00206    else
00207    {
00208       mean_result = double(mCurTotal)/double(mSampleCount);
00209    }
00210 
00211    return mean_result;
00212 }

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

Definition at line 215 of file SampleLimitedStatCollector.h.

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

00216 {
00217    double inst_average(0.0);
00218 
00219    if(TimeBased)
00220    {
00221       //
00222       //     |
00223       //     |                  |
00224       //     |                  |
00225       // mPrevTime1        mPrevTime2             cur_time
00226       vpr::Interval cur_time, diff_time;
00227       double diff_sec;                       // Num secs different in send times
00228       cur_time.setNow();                     // Set current time
00229       diff_time = cur_time - mPrevSampleTime1;     // Get time to compute the average over
00230       diff_sec = diff_time.secf();
00231 
00232       // Compute -- INST BANDWIDTH
00233       if(diff_sec > 0)
00234       {
00235         inst_average = double(mPrevSample1 + mPrevSample2)/diff_sec;
00236       }
00237 
00238       // Haven't had sample in quite a while, so clamp to zero.
00239       if(diff_time > this->mSTAMaxTime)
00240       {
00241          inst_average = 0.0;
00242       }
00243    }
00244    else
00245    {
00246       // Just approximate it with the average of the last two entries
00247       inst_average = double(mPrevSample1 + mPrevSample2)/2.0;
00248    }
00249 
00250    return inst_average;
00251 }

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

Definition at line 254 of file SampleLimitedStatCollector.h.

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

Referenced by addSample.

00255 {
00256    // Compute -- STA BANDWIDTH
00257    double sta_value(0.0f);
00258 
00259    if(mSampleBuffer.size() > 0)
00260    {
00261       if(TimeBased)
00262       {
00263          vpr::Interval cur_time, diff_time;
00264          double diff_sec;                       // Num secs different in send times
00265          cur_time.setNow();                     // Set current time
00266 
00267          vpr::Interval first_sample_time( mSampleBuffer.back().second );
00268          diff_time = cur_time - first_sample_time;
00269          diff_sec = diff_time.secf();
00270          sta_value = mRunningSTATotal/diff_sec;
00271       }
00272       else
00273       {
00274          sta_value = mRunningSTATotal/double(mSampleBuffer.size());      // Compute as average of the buffered samples
00275       }
00276    }
00277 
00278    return sta_value;
00279 }

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

Definition at line 104 of file SampleLimitedStatCollector.h.

00105    {  return mMaxSTA; }

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

Definition at line 126 of file SampleLimitedStatCollector.h.

References getMean, vpr::DateTime::getMinutesf, and vpr::Interval::secf.

00127 {
00128    out << "type: " << typeid(TYPE).name() << "   time based:" << ( TimeBased ? "Y" : "N" ) << std::endl
00129        << "total: " << mCurTotal << "   samples:" << mSampleCount << std::endl
00130        << "mean: " << getMean() << "    sampleLimit:" << mSTASampleLimit << std::endl
00131        << "Initial Sample Time:" << mInitialSampleTime.getMinutesf() << std::endl
00132        << "prev sampTime: " << mPrevSampleTime1.secf() << "s   prev sampTime2:" << mPrevSampleTime2.secf() << std::endl
00133        << "prev samp: " << mPrevSample1 << "   prev samp2:" << mPrevSample2 << std::endl
00134        << " --- data --- time --- " << std::endl;
00135 
00136    for(typename std::vector< std::pair<TYPE,vpr::Interval> >::iterator i = mSampleBuffer.begin();
00137        i!= mSampleBuffer.end(); ++i)
00138    {
00139       out << (*i).first << "   " << (*i).second.msec() << "ms\n";
00140    }
00141 }


The documentation for this class was generated from the following file:
Generated on Sun May 2 14:47:18 2004 for VR Juggler Portable Runtime by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002