CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
MovingAverage.h
Go to the documentation of this file.
1
9#if !defined(_MOVINGAVERAGE_H_)
10#define _MOVINGAVERAGE_H_
11
12#include "Stats.h"
13#include "PsyTime.h"
14
15namespace cmlabs {
16
18struct StatEntry {
19 uint64 count;
20 double value;
21};
22
67public:
69 static bool UnitTest();
70
72 MovingAverage(uint32 binTimeMS = 100, uint16 binCount = 600);
74
84 bool add(double val, uint32 count = 1, uint64 time = GetTimeNow());
85
90 bool getThroughput(uint32 ms, double& valPerSec, double& countPerSec, uint64 now = 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() );
102
107 bool getAverage(uint32 ms, double& val, uint64& count, uint64 now = GetTimeNow());
109 bool getAverageMulti(
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());
114
118 bool getSum(uint32 ms, double& val, uint64& count, uint64 now = GetTimeNow());
120 bool getSumMulti(
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());
125
128 bool getTotal(double& val, uint64& count);
129
131 std::string getPerfXML(uint32 binMS = 1000, uint32 binNum = 60);
133 std::string getPerfJSON(uint32 binMS = 1000, uint32 binNum = 60);
134
135protected:
138
139 uint32 binTime;
140 uint32 binCount;
145 // uint64 totalTime;
146
150 bool shiftBins(uint64 now);
151};
152
153
154} // namespace cmlabs
155
156#endif //_MOVINGAVERAGE_H_
157
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.
Definition Utils.h:463
uint64 GetTimeNow()
Return the current absolute time (µs since year 0) according to the TMC.
Definition PsyTime.cpp:69
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.