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

DurationStatCollector.h

Go to the documentation of this file.
00001 /****************** <VPR heading BEGIN do not edit this line> *****************
00002  *
00003  * VR Juggler Portable Runtime
00004  *
00005  * Original Authors:
00006  *   Allen Bierbaum, Patrick Hartling, Kevin Meinert, Carolina Cruz-Neira
00007  *
00008  * -----------------------------------------------------------------
00009  * File:          $RCSfile: DurationStatCollector.h,v $
00010  * Date modified: $Date: 2003/02/21 22:59:36 $
00011  * Version:       $Revision: 1.7 $
00012  * -----------------------------------------------------------------
00013  *
00014  ****************** <VPR heading END do not edit this line> ******************/
00015 
00016 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
00017  *
00018  * VR Juggler is (C) Copyright 1998-2003 by Iowa State University
00019  *
00020  * Original Authors:
00021  *   Allen Bierbaum, Christopher Just,
00022  *   Patrick Hartling, Kevin Meinert,
00023  *   Carolina Cruz-Neira, Albert Baker
00024  *
00025  * This library is free software; you can redistribute it and/or
00026  * modify it under the terms of the GNU Library General Public
00027  * License as published by the Free Software Foundation; either
00028  * version 2 of the License, or (at your option) any later version.
00029  *
00030  * This library is distributed in the hope that it will be useful,
00031  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00032  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00033  * Library General Public License for more details.
00034  *
00035  * You should have received a copy of the GNU Library General Public
00036  * License along with this library; if not, write to the
00037  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00038  * Boston, MA 02111-1307, USA.
00039  *
00040  *************** <auto-copyright.pl END do not edit this line> ***************/
00041 
00042 #ifndef _VPR_DURATION_STAT_COLLECTOR_H_
00043 #define _VPR_DURATION_STAT_COLLECTOR_H_
00044 
00045 #include <vpr/vprConfig.h>
00046 #include <vpr/Util/SampleLimitedStatCollector.h>
00047 
00048 namespace vpr
00049 {
00050 
00051 class DurationStatCollector : public SampleLimitedStatCollector<double, false>
00052 {
00053 public:
00054    DurationStatCollector(vpr::Interval::Unit units = vpr::Interval::Sec, unsigned sampleLimit = 100)
00055     : SampleLimitedStatCollector<double, false>(sampleLimit)
00056    {
00057       mUnits = units;
00058       mStartTimeNeededNext = true;
00059    }
00060 
00061    void startSample()
00062    {
00063       vprASSERT(mStartTimeNeededNext);
00064       mStartTimeNeededNext = false;
00065 
00066       mSampleStartTime.setNow();
00067       //std::cout << "sta: " << mSampleStartTime.usec() << "\n";
00068    }
00069 
00070    void stopSample()
00071    {
00072       vprASSERT(!mStartTimeNeededNext);
00073       mStartTimeNeededNext = true;
00074 
00075       // Compute time difference
00076       mSampleStopTime.setNow();
00077       //std::cout << "sto: " << mSampleStopTime.usec() << "\n";
00078       vpr::Interval diff(mSampleStopTime - mSampleStartTime);
00079       //std::cout << "d: " << diff.usec() << "\n";
00080       double sample(0.0f);
00081 
00082       switch(mUnits)
00083       {
00084       case vpr::Interval::Sec:
00085          sample = diff.secf();
00086          break;
00087       case vpr::Interval::Msec:
00088          sample = diff.msecf();
00089          break;
00090       case vpr::Interval::Usec:
00091          sample = diff.usecf();
00092          break;
00093       default:
00094          vprASSERT(false && "Invalid units");
00095          break;
00096       }
00097 
00098       //std::cout << "s: " << sample << "\n";
00099       addSample(sample);
00100    }
00101 
00102 protected:
00103    vpr::Interval::Unit  mUnits;
00104 
00105    vpr::Interval  mSampleStartTime;
00106    vpr::Interval  mSampleStopTime;
00107 
00108    bool mStartTimeNeededNext;       // For helping with debugging
00109 };
00110 
00111 }; // namespace
00112 
00113 #endif

Generated on Sun May 2 14:43:01 2004 for VR Juggler Portable Runtime by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002