9#if !defined(_MOVINGAVERAGE_H_)
10#define _MOVINGAVERAGE_H_
84 bool add(
double val, uint32 count = 1, uint64 time =
GetTimeNow());
98 uint32 ms1, uint32 ms2, uint32 ms3,
99 double& valPerSec1,
double& countPerSec1,
100 double& valPerSec2,
double& countPerSec2,
101 double& valPerSec3,
double& countPerSec3, uint64 now =
GetTimeNow() );
110 uint32 ms1, uint32 ms2, uint32 ms3,
111 double& avg1, uint64& count1,
112 double& avg2, uint64& count2,
113 double& avg3, uint64& count3, uint64 now =
GetTimeNow());
118 bool getSum(uint32 ms,
double& val, uint64& count, uint64 now =
GetTimeNow());
121 uint32 ms1, uint32 ms2, uint32 ms3,
122 double& sum1, uint64& count1,
123 double& sum2, uint64& count2,
124 double& sum3, uint64& count3, uint64 now =
GetTimeNow());
128 bool getTotal(
double& val, uint64& count);
131 std::string
getPerfXML(uint32 binMS = 1000, uint32 binNum = 60);
133 std::string
getPerfJSON(uint32 binMS = 1000, uint32 binNum = 60);
CMSDK time: µs-resolution 64-bit timestamps and the Time Mapping Constant (TMC).
Thread-safe running statistics over a sliding window of samples.
static bool UnitTest()
Self test.
bool shiftBins(uint64 now)
Advance the circular buffer so the bin containing now becomes current, zeroing expired bins.
bool getSum(uint32 ms, double &val, uint64 &count, uint64 now=GetTimeNow())
Value sum over the last ms milliseconds.
MovingAverage(uint32 binTimeMS=100, uint16 binCount=600)
Create a tracker.
bool getTotal(double &val, uint64 &count)
Lifetime totals since construction (not limited to the bin window).
uint32 binTime
Bin duration in µs (constructor's binTimeMS multiplied by 1000).
bool getSumMulti(uint32 ms1, uint32 ms2, uint32 ms3, double &sum1, uint64 &count1, double &sum2, uint64 &count2, double &sum3, uint64 &count3, uint64 now=GetTimeNow())
Sums for three windows in one locked pass; parameters parallel getThroughputMulti().
bool getAverageMulti(uint32 ms1, uint32 ms2, uint32 ms3, double &avg1, uint64 &count1, double &avg2, uint64 &count2, double &avg3, uint64 &count3, uint64 now=GetTimeNow())
Averages for three windows in one locked pass; parameters parallel getThroughputMulti().
std::string getPerfJSON(uint32 binMS=1000, uint32 binNum=60)
Render recent history as JSON performance bins.
bool add(double val, uint32 count=1, uint64 time=GetTimeNow())
Record a sample.
std::string getPerfXML(uint32 binMS=1000, uint32 binNum=60)
Render recent history as XML performance bins.
bool getThroughputMulti(uint32 ms1, uint32 ms2, uint32 ms3, double &valPerSec1, double &countPerSec1, double &valPerSec2, double &countPerSec2, double &valPerSec3, double &countPerSec3, uint64 now=GetTimeNow())
Compute throughput for three windows in one locked pass (cheaper than three getThroughput() calls).
bool getThroughput(uint32 ms, double &valPerSec, double &countPerSec, uint64 now=GetTimeNow())
Compute rates over the last ms milliseconds.
bool getAverage(uint32 ms, double &val, uint64 &count, uint64 now=GetTimeNow())
Average value over the last ms milliseconds.
Recursive mutual-exclusion lock, optionally named for cross-process use.
uint64 GetTimeNow()
Return the current absolute time (µs since year 0) according to the TMC.
Accumulated samples of one time bin: number of samples and their value sum.
double value
Sum of sample values in this bin.
uint64 count
Number of samples added to this bin.