VR-Link API Documentation for HLA 1.3
vlPerformanceStats.h
Go to the documentation of this file.
00001 /******************************************************************************
00002 ** Copyright (c) 1992-2010 VT MAK
00003 ** All rights reserved.
00004 ******************************************************************************/
00010 #pragma once
00011 
00012 #include "vlUtil.h"
00013 #include <vector>
00014 
00015 #ifdef _WIN32
00016 #else
00017 #include <sys/time.h>
00018 #endif
00019 
00020 #ifdef DtUSE_UTILITIES_NAMESPACE
00021 namespace DtUSE_UTILITIES_NAMESPACE
00022 {
00023 #endif
00024 
00032 class DT_DLL_VLUTIL DtTimedSection
00033 {
00034 public:
00036    DtTimedSection();
00037    
00039    void start();
00040 
00042    void stop();
00043    
00049    double duration() const;
00050    
00051 protected:
00052 
00053    //Platform specific storage times, and additional members.
00054 #ifdef _WIN32
00055    typedef LARGE_INTEGER TimeValue;
00056    double myInverseFrequency;
00057 #else
00058     typedef timeval TimeValue;
00059     struct timezone tz;
00060  #endif
00061 
00062     TimeValue myStartVal;
00063     TimeValue myEndVal;
00064 };
00065 
00075 class DT_DLL_VLUTIL DtTimeStatistic
00076 {
00077 public:
00078 
00080    DtTimeStatistic();
00081 
00083    void addTime(double time);
00084 
00086    inline double last() const
00087    {
00088       return myLastTime;
00089    }
00090 
00092    inline double minimum() const 
00093    { 
00094       return myMinimum; 
00095    }
00096    
00099    inline double avg() const
00100    {
00101       // Calculate the average by taking the running Avg scaled by the max
00102       // count plus the current average scaled by the count/ over the total count;
00103       return (myLastSum + mySum) / (double)(myLastCount + myCount);
00104    }
00105    
00107    inline double maximum() const 
00108    { 
00109       return myMaximum; 
00110    }
00111 
00113    void reset();
00114 
00115 protected:
00116    double myLastTime;
00117    double myMinimum;
00118    double mySum;
00119    double myLastSum;
00120    double myMaximum;   
00121    unsigned int myCount;
00122    unsigned int myLastCount;
00123    static const int theMaxCount = 1000;
00124 };
00125 
00133 class DT_DLL_VLUTIL DtPerformanceStats
00134 {  
00135 public:
00136    //A vector of stats.
00137    typedef std::vector<DtTimeStatistic> TimeStats;
00138 
00139    //Create a time stat list.
00140    DtPerformanceStats();
00141    
00142    //Destroy a time stat list.
00143    ~DtPerformanceStats();
00144    
00146    void resetAllStats();
00147 
00149    inline void addTime(unsigned int id, double time)
00150    {
00151       stat(id).addTime(time);
00152    }
00153 
00155    inline double last(unsigned int id) const
00156    {
00157       return stat(id).last();
00158    }
00159 
00161    inline double minimum(unsigned int id) const 
00162    { 
00163       return stat(id).minimum();
00164    }
00165 
00167    inline double avg(unsigned int id) const
00168    {
00169       return stat(id).avg();
00170    }
00171 
00173    inline double maximum(unsigned int id) const 
00174    { 
00175       return stat(id).maximum(); 
00176    }
00177 
00186    DtTimeStatistic& stat(unsigned int statEnumIndex);
00187    const DtTimeStatistic& stat(unsigned int statEnumIndex) const;
00188    
00190 
00191    TimeStats& stats();
00192    const TimeStats& stats() const;
00194    
00195 protected:
00196    TimeStats myStats;
00197 };
00198 
00199 #ifdef DtUSE_UTILITIES_NAMESPACE
00200 }
00201 #endif
00202 

Document ID: Generated on Mon May 14 08:06:18 EDT 2012 from SVN revision 114750
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)