From 59027959b8d3a8d7cd4e414f5d049e87b7ef1a85 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Wed, 1 Jul 2015 16:30:42 -0700 Subject: [PATCH] CR comments and fixing the average calculation --- interface/src/Application.cpp | 16 ++++++++------ interface/src/InterfaceLogging.cpp | 1 + interface/src/InterfaceLogging.h | 1 + libraries/shared/src/SimpleAverage.h | 33 ++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 libraries/shared/src/SimpleAverage.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 1f22b31c64..5241864100 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -91,6 +91,7 @@ #include #include #include +#include #include #include #include @@ -178,6 +179,7 @@ using namespace std; // Starfield information static unsigned STARFIELD_NUM_STARS = 50000; static unsigned STARFIELD_SEED = 1; +static uint8_t THROTTLED_IDLE_TIMER_DELAY = 2; const qint64 MAXIMUM_CACHE_SIZE = 10 * BYTES_PER_GIGABYTES; // 10GB @@ -1784,17 +1786,17 @@ void Application::checkFPS() { DependencyManager::get()->sendDomainServerCheckIn(); } -static SimpleMovingAverage interIdleDurations; -static uint64_t lastIdleEnd{ 0 }; - void Application::idle() { + static SimpleAverage interIdleDurations; + static uint64_t lastIdleEnd{ 0 }; + if (lastIdleEnd != 0) { uint64_t now = usecTimestampNow(); - interIdleDurations.updateAverage(now - lastIdleEnd); + interIdleDurations.update(now - lastIdleEnd); static uint64_t lastReportTime = now; - if ((now - lastReportTime) >= (1000 * 1000)) { + if ((now - lastReportTime) >= (USECS_PER_SECOND)) { int avgIdleDuration = (int)interIdleDurations.getAverage(); - qDebug() << "Average inter-idle time: " << avgIdleDuration << "s for " << interIdleDurations.getSampleCount() << " samples"; + qCDebug(interfaceapp_timing) << "Average inter-idle time: " << avgIdleDuration << "s for " << interIdleDurations.getCount() << " samples"; interIdleDurations.reset(); lastReportTime = now; } @@ -1845,7 +1847,7 @@ void Application::idle() { // After finishing all of the above work, restart the idle timer, allowing 2ms to process events. } - idleTimer->start(_glWidget->isThrottleRendering() ? 10 : 0); + idleTimer->start(_glWidget->isThrottleRendering() ? THROTTLED_IDLE_TIMER_DELAY : 0); } // check for any requested background downloads. diff --git a/interface/src/InterfaceLogging.cpp b/interface/src/InterfaceLogging.cpp index 18bc4e58e8..0afcb30c27 100644 --- a/interface/src/InterfaceLogging.cpp +++ b/interface/src/InterfaceLogging.cpp @@ -12,3 +12,4 @@ #include "InterfaceLogging.h" Q_LOGGING_CATEGORY(interfaceapp, "hifi.interface") +Q_LOGGING_CATEGORY(interfaceapp_timing, "hifi.interface.timing") diff --git a/interface/src/InterfaceLogging.h b/interface/src/InterfaceLogging.h index d1d92aa93d..be2ee73fba 100644 --- a/interface/src/InterfaceLogging.h +++ b/interface/src/InterfaceLogging.h @@ -15,5 +15,6 @@ #include Q_DECLARE_LOGGING_CATEGORY(interfaceapp) +Q_DECLARE_LOGGING_CATEGORY(interfaceapp_timing) #endif // hifi_InterfaceLogging_h diff --git a/libraries/shared/src/SimpleAverage.h b/libraries/shared/src/SimpleAverage.h new file mode 100644 index 0000000000..33ed9d84cc --- /dev/null +++ b/libraries/shared/src/SimpleAverage.h @@ -0,0 +1,33 @@ +// +// Created by Bradley Austin Davis on 2015/07/01. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#pragma once +#ifndef hifi_SimpleAverage_h +#define hifi_SimpleAverage_h + +template +class SimpleAverage { +public: + void update(T sample) { + _sum += sample; + ++_count; + } + void reset() { + _sum = 0; + _count = 0; + } + + int getCount() const { return _count; }; + T getAverage() const { return _sum / (T)_count; }; + +private: + int _count; + T _sum; +}; + +#endif