9 template <class TYPE
, uint32 COUNT
>
13 CStatistic(uint32 freq
=0) :
14 mSampleFrequency(freq
),
27 bool Sample(TYPE value
)
32 mLastSampleTime
= time(NULL
);
34 if (!mSampleFrequency
|| mLastSampleTime
+ mSampleFrequency
< (unsigned)time(NULL
))
37 mAggregateTotal
+= value
;
38 if (value
> mAggregateMaximum
)
39 mAggregateMaximum
= value
;
40 if (value
< mAggregateMinimum
)
41 mAggregateMinimum
= value
;
43 if (mAverageIndex
== COUNT
)
45 if (mAverageCount
> COUNT
)
46 mAverageTotal
-= mAverageData
[mAverageIndex
];
48 mAverageData
[mAverageIndex
++] = value
;
49 mAverageTotal
+= value
;
51 if (mAverageCount
< COUNT
)
63 TYPE
GetSample(uint32 age
= 0)
65 if (age
> mAverageCount
)
68 uint32 index
= mAverageIndex
;
70 index
= COUNT
- (age
- index
);
74 return mAverageData
[index
];
79 return (double)mAverageTotal
/mAverageCount
;
82 double GetAggregateAverage()
84 return (double)mAggregateTotal
/mSampleTotal
;
89 return mAggregateMaximum
;
94 return mAggregateMinimum
;
98 uint32 mSampleFrequency
;
99 time_t mLastSampleTime
;
102 TYPE mAggregateTotal
;
103 TYPE mAggregateMaximum
;
104 TYPE mAggregateMinimum
;
106 TYPE mAverageData
[COUNT
];
108 uint32 mAverageIndex
;
109 uint32 mAverageCount
;
112 class CStatisticTimer
115 CStatisticTimer(bool running
= true);
117 void Start() { if (mRunning
) return; mStart
= getTimer(); mRunning
= true; }
118 void Stop() { if (!mRunning
) return; mTotal
+= getTimer()-mStart
; mRunning
= false; }
119 void Reset() { mRunning
= false; mTotal
= 0; }
122 uint64
GetFraction(uint32 fraction
=1000);
133 #endif // STATISTICS_H