Merge pull request #7677 from howard-stearns/RateCounter-adjustment

Don't truncate time when accumulating, and then divide by non-truncated.
This commit is contained in:
Chris Collins 2016-04-15 15:59:13 -07:00
commit 7b49552066

View file

@ -22,10 +22,10 @@ class RateCounter {
public:
void increment(size_t count = 1) {
auto now = usecTimestampNow();
auto currentIntervalMs = (uint32_t)((now - _start) / USECS_PER_MSEC);
if (currentIntervalMs > INTERVAL) {
float currentIntervalMs = (now - _start) / (float) USECS_PER_MSEC;
if (currentIntervalMs > (float) INTERVAL) {
float currentCount = _count;
float intervalSeconds = (float)currentIntervalMs / (float)MSECS_PER_SECOND;
float intervalSeconds = currentIntervalMs / (float) MSECS_PER_SECOND;
_rate = roundf(currentCount / intervalSeconds * _scale) / _scale;
_start = now;
_count = 0;