not 100% this rate calculation is right, but might be better than before?
This commit is contained in:
@@ -477,10 +477,13 @@ void asynStreamGeneratorDriver::processEvents() {
|
|||||||
// uint32. It does support int64 though.. so we start with that
|
// uint32. It does support int64 though.. so we start with that
|
||||||
epicsInt32 *counts = new epicsInt32[this->num_channels];
|
epicsInt32 *counts = new epicsInt32[this->num_channels];
|
||||||
|
|
||||||
|
const uint64_t minRateSamplePeriod = 100'000'000ll;
|
||||||
|
const size_t rateAverageWindow = 20;
|
||||||
size_t countDiffsPtr = 0;
|
size_t countDiffsPtr = 0;
|
||||||
epicsInt32 *rates = new epicsInt32[this->num_channels];
|
epicsInt32 *rates = new epicsInt32[this->num_channels];
|
||||||
epicsInt32 *countDiff = new epicsInt32[this->num_channels];
|
epicsInt32 *countDiff = new epicsInt32[this->num_channels];
|
||||||
epicsInt32 *countDiffs = new epicsInt32[this->num_channels * 10];
|
epicsInt32 *countDiffs = new epicsInt32[this->num_channels * rateAverageWindow];
|
||||||
|
uint64_t *timeSpans = new uint64_t[this->num_channels];
|
||||||
epicsTimeStamp lastRateUpdate = epicsTime::getCurrent();
|
epicsTimeStamp lastRateUpdate = epicsTime::getCurrent();
|
||||||
|
|
||||||
asynStatus status = asynSuccess;
|
asynStatus status = asynSuccess;
|
||||||
@@ -613,23 +616,30 @@ void asynStreamGeneratorDriver::processEvents() {
|
|||||||
// Careful changing any of these magic numbers until I clean this up
|
// Careful changing any of these magic numbers until I clean this up
|
||||||
// as you might end up calculating the wrong rate
|
// as you might end up calculating the wrong rate
|
||||||
epicsTimeStamp currentTime = epicsTime::getCurrent();
|
epicsTimeStamp currentTime = epicsTime::getCurrent();
|
||||||
if (epicsTimeDiffInNS(¤tTime, &lastRateUpdate) > 100'000'000ll) {
|
if (epicsTimeDiffInNS(¤tTime, &lastRateUpdate) > minRateSamplePeriod) {
|
||||||
|
timeSpans[countDiffsPtr] = epicsTimeDiffInNS(¤tTime, &lastRateUpdate);
|
||||||
|
|
||||||
|
uint64_t totalTime = 0;
|
||||||
|
for (size_t i = 0; i <= rateAverageWindow; ++i) {
|
||||||
|
totalTime += timeSpans[i];
|
||||||
|
}
|
||||||
|
|
||||||
lastRateUpdate = currentTime;
|
lastRateUpdate = currentTime;
|
||||||
|
|
||||||
for (size_t i = 0; i <= this->num_channels; ++i) {
|
for (size_t i = 0; i <= this->num_channels; ++i) {
|
||||||
countDiffs[i * 10 + countDiffsPtr] = countDiff[i];
|
countDiffs[i * rateAverageWindow + countDiffsPtr] = countDiff[i];
|
||||||
|
|
||||||
uint64_t cnt = 0;
|
uint64_t cnt = 0;
|
||||||
for (size_t j = 0; j <= 10; ++j) {
|
for (size_t j = 0; j <= rateAverageWindow; ++j) {
|
||||||
cnt += countDiffs[i * 10 + j];
|
cnt += countDiffs[i * rateAverageWindow + j];
|
||||||
}
|
}
|
||||||
rates[i] =
|
rates[i] =
|
||||||
cnt; // would / 10 to average than * 10 as want per second
|
cnt / (totalTime * 1e-9);
|
||||||
|
|
||||||
countDiff[i] = 0;
|
countDiff[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
countDiffsPtr = (countDiffsPtr + 1) % 10;
|
countDiffsPtr = (countDiffsPtr + 1) % rateAverageWindow;
|
||||||
|
|
||||||
if (countDiffsPtr % 5 == 0) {
|
if (countDiffsPtr % 5 == 0) {
|
||||||
lock();
|
lock();
|
||||||
|
|||||||
Reference in New Issue
Block a user