Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1212)

Unified Diff: cc/frame_rate_counter.cc

Issue 11817011: cc: add RingBuffer class for timestamp storing in FrameRateCounter (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/frame_rate_counter.cc
diff --git a/cc/frame_rate_counter.cc b/cc/frame_rate_counter.cc
index c37956f78c8d06f0e2c1a68a611c9bce17ecf215..4ebd8b642dd8e5f079780437ac22f801cc25c0dc 100644
--- a/cc/frame_rate_counter.cc
+++ b/cc/frame_rate_counter.cc
@@ -4,7 +4,7 @@
#include "cc/frame_rate_counter.h"
-#include <cmath>
+#include <limits>
#include "base/metrics/histogram.h"
#include "cc/proxy.h"
@@ -15,12 +15,6 @@ const double FrameRateCounter::kFrameTooFast = 1.0 / 70.0; // measured in second
const double FrameRateCounter::kFrameTooSlow = 1.0 / 4.0;
const double FrameRateCounter::kDroppedFrameTime = 1.0 / 50.0;
-// safeMod works on -1, returning m-1 in that case.
-static inline int safeMod(int number, int modulus)
-{
- return (number + modulus) % modulus;
-}
-
// static
scoped_ptr<FrameRateCounter> FrameRateCounter::create(bool hasImplThread) {
return make_scoped_ptr(new FrameRateCounter(hasImplThread));
@@ -28,45 +22,32 @@ scoped_ptr<FrameRateCounter> FrameRateCounter::create(bool hasImplThread) {
inline base::TimeDelta FrameRateCounter::frameInterval(int frameNumber) const
{
- return m_timeStampHistory[frameIndex(frameNumber)] -
- m_timeStampHistory[frameIndex(frameNumber - 1)];
-}
-
-inline int FrameRateCounter::frameIndex(int frameNumber) const
-{
- return safeMod(frameNumber, kTimeStampHistorySize);
+ return m_buffer[bufferIndex(frameNumber)] - m_buffer[bufferIndex(frameNumber - 1)];
}
FrameRateCounter::FrameRateCounter(bool hasImplThread)
: m_hasImplThread(hasImplThread)
- , m_currentFrameNumber(1)
, m_droppedFrameCount(0)
{
- m_timeStampHistory[0] = base::TimeTicks::Now();
- m_timeStampHistory[1] = m_timeStampHistory[0];
- for (int i = 2; i < kTimeStampHistorySize; i++)
- m_timeStampHistory[i] = base::TimeTicks();
+ m_buffer[0] = m_buffer[1] = base::TimeTicks::Now();
+ m_currentIndex = 1;
+ for (int i = 2; i < bufferSize(); i++)
+ m_buffer[i] = base::TimeTicks();
}
-void FrameRateCounter::markBeginningOfFrame(base::TimeTicks timestamp)
+void FrameRateCounter::saveTimeStamp(base::TimeTicks timestamp)
{
- m_timeStampHistory[frameIndex(m_currentFrameNumber)] = timestamp;
- base::TimeDelta frameIntervalSeconds = frameInterval(m_currentFrameNumber);
+ saveToBuffer(timestamp);
+ base::TimeDelta frameIntervalSeconds = frameInterval(m_currentIndex);
- if (m_hasImplThread && m_currentFrameNumber > 0) {
+ if (m_hasImplThread && m_currentIndex > 0)
HISTOGRAM_CUSTOM_COUNTS("Renderer4.CompositorThreadImplDrawDelay", frameIntervalSeconds.InMilliseconds(), 1, 120, 60);
- }
if (!isBadFrameInterval(frameIntervalSeconds) &&
frameIntervalSeconds.InSecondsF() > kDroppedFrameTime)
++m_droppedFrameCount;
}
-void FrameRateCounter::markEndOfFrame()
-{
- m_currentFrameNumber += 1;
-}
-
bool FrameRateCounter::isBadFrameInterval(base::TimeDelta intervalBetweenConsecutiveFrames) const
{
double delta = intervalBetweenConsecutiveFrames.InSecondsF();
@@ -76,14 +57,30 @@ bool FrameRateCounter::isBadFrameInterval(base::TimeDelta intervalBetweenConsecu
return intervalTooFast || intervalTooSlow;
}
-bool FrameRateCounter::isBadFrame(int frameNumber) const
+void FrameRateCounter::getMinAndMaxFPS(double& minFPS, double& maxFPS) const
{
- return isBadFrameInterval(frameInterval(frameNumber));
+ minFPS = std::numeric_limits<double>::max();
+ maxFPS = 0;
+
+ for (int i = m_currentIndex - 1; i > 0 && bufferIndex(i) != bufferIndex(m_currentIndex); --i) {
+ base::TimeDelta delta = frameInterval(i);
+
+ if (isBadFrameInterval(delta))
+ continue;
+
+ double fps = 1.0 / delta.InSecondsF();
+
+ minFPS = std::min(fps, minFPS);
+ maxFPS = std::max(fps, maxFPS);
+ }
+
+ if (minFPS > maxFPS)
+ minFPS = maxFPS;
}
double FrameRateCounter::getAverageFPS() const
{
- int frameNumber = m_currentFrameNumber - 1;
+ int frameNumber = m_currentIndex - 1;
int frameCount = 0;
double frameTimesTotal = 0;
double averageFPS = 0;
@@ -99,7 +96,7 @@ double FrameRateCounter::getAverageFPS() const
//
// isBadFrameInterval encapsulates the frame too slow/frame too fast logic.
- while (frameIndex(frameNumber) != frameIndex(m_currentFrameNumber) && frameNumber >= 0 && frameTimesTotal < 1.0) {
+ while (bufferIndex(frameNumber) != bufferIndex(m_currentIndex) && frameNumber >= 0 && frameTimesTotal < 1.0) {
base::TimeDelta delta = frameInterval(frameNumber);
if (!isBadFrameInterval(delta)) {
@@ -117,12 +114,4 @@ double FrameRateCounter::getAverageFPS() const
return averageFPS;
}
-base::TimeTicks FrameRateCounter::timeStampOfRecentFrame(int n) const
-{
- DCHECK(n >= 0);
- DCHECK(n < kTimeStampHistorySize);
- int desiredIndex = (frameIndex(m_currentFrameNumber) + n) % kTimeStampHistorySize;
- return m_timeStampHistory[desiredIndex];
-}
-
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698