| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "CCFrameRateCounter.h" | 7 #include "CCFrameRateCounter.h" |
| 8 | 8 |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 | 10 |
| 11 #include "CCProxy.h" | 11 #include "CCProxy.h" |
| 12 #include <public/Platform.h> | 12 #include <public/Platform.h> |
| 13 | 13 |
| 14 namespace cc { | 14 namespace cc { |
| 15 | 15 |
| 16 const double CCFrameRateCounter::kFrameTooFast = 1.0 / 70.0; // measured in seco
nds | 16 const double FrameRateCounter::kFrameTooFast = 1.0 / 70.0; // measured in second
s |
| 17 const double CCFrameRateCounter::kFrameTooSlow = 1.0 / 12.0; | 17 const double FrameRateCounter::kFrameTooSlow = 1.0 / 12.0; |
| 18 const double CCFrameRateCounter::kDroppedFrameTime = 1.0 / 50.0; | 18 const double FrameRateCounter::kDroppedFrameTime = 1.0 / 50.0; |
| 19 | 19 |
| 20 // safeMod works on -1, returning m-1 in that case. | 20 // safeMod works on -1, returning m-1 in that case. |
| 21 static inline int safeMod(int number, int modulus) | 21 static inline int safeMod(int number, int modulus) |
| 22 { | 22 { |
| 23 return (number + modulus) % modulus; | 23 return (number + modulus) % modulus; |
| 24 } | 24 } |
| 25 | 25 |
| 26 // static | 26 // static |
| 27 scoped_ptr<CCFrameRateCounter> CCFrameRateCounter::create() { | 27 scoped_ptr<FrameRateCounter> FrameRateCounter::create() { |
| 28 return make_scoped_ptr(new CCFrameRateCounter()); | 28 return make_scoped_ptr(new FrameRateCounter()); |
| 29 } | 29 } |
| 30 | 30 |
| 31 inline base::TimeDelta CCFrameRateCounter::frameInterval(int frameNumber) const | 31 inline base::TimeDelta FrameRateCounter::frameInterval(int frameNumber) const |
| 32 { | 32 { |
| 33 return m_timeStampHistory[frameIndex(frameNumber)] - | 33 return m_timeStampHistory[frameIndex(frameNumber)] - |
| 34 m_timeStampHistory[frameIndex(frameNumber - 1)]; | 34 m_timeStampHistory[frameIndex(frameNumber - 1)]; |
| 35 } | 35 } |
| 36 | 36 |
| 37 inline int CCFrameRateCounter::frameIndex(int frameNumber) const | 37 inline int FrameRateCounter::frameIndex(int frameNumber) const |
| 38 { | 38 { |
| 39 return safeMod(frameNumber, kTimeStampHistorySize); | 39 return safeMod(frameNumber, kTimeStampHistorySize); |
| 40 } | 40 } |
| 41 | 41 |
| 42 CCFrameRateCounter::CCFrameRateCounter() | 42 FrameRateCounter::FrameRateCounter() |
| 43 : m_currentFrameNumber(1) | 43 : m_currentFrameNumber(1) |
| 44 , m_droppedFrameCount(0) | 44 , m_droppedFrameCount(0) |
| 45 { | 45 { |
| 46 m_timeStampHistory[0] = base::TimeTicks::Now(); | 46 m_timeStampHistory[0] = base::TimeTicks::Now(); |
| 47 m_timeStampHistory[1] = m_timeStampHistory[0]; | 47 m_timeStampHistory[1] = m_timeStampHistory[0]; |
| 48 for (int i = 2; i < kTimeStampHistorySize; i++) | 48 for (int i = 2; i < kTimeStampHistorySize; i++) |
| 49 m_timeStampHistory[i] = base::TimeTicks(); | 49 m_timeStampHistory[i] = base::TimeTicks(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void CCFrameRateCounter::markBeginningOfFrame(base::TimeTicks timestamp) | 52 void FrameRateCounter::markBeginningOfFrame(base::TimeTicks timestamp) |
| 53 { | 53 { |
| 54 m_timeStampHistory[frameIndex(m_currentFrameNumber)] = timestamp; | 54 m_timeStampHistory[frameIndex(m_currentFrameNumber)] = timestamp; |
| 55 base::TimeDelta frameIntervalSeconds = frameInterval(m_currentFrameNumber); | 55 base::TimeDelta frameIntervalSeconds = frameInterval(m_currentFrameNumber); |
| 56 | 56 |
| 57 if (CCProxy::hasImplThread() && m_currentFrameNumber > 0) { | 57 if (Proxy::hasImplThread() && m_currentFrameNumber > 0) { |
| 58 double drawDelayMs = frameIntervalSeconds.InMillisecondsF(); | 58 double drawDelayMs = frameIntervalSeconds.InMillisecondsF(); |
| 59 WebKit::Platform::current()->histogramCustomCounts("Renderer4.Compositor
ThreadImplDrawDelay", static_cast<int>(drawDelayMs), 1, 120, 60); | 59 WebKit::Platform::current()->histogramCustomCounts("Renderer4.Compositor
ThreadImplDrawDelay", static_cast<int>(drawDelayMs), 1, 120, 60); |
| 60 } | 60 } |
| 61 | 61 |
| 62 if (!isBadFrameInterval(frameIntervalSeconds) && | 62 if (!isBadFrameInterval(frameIntervalSeconds) && |
| 63 frameIntervalSeconds.InSecondsF() > kDroppedFrameTime) | 63 frameIntervalSeconds.InSecondsF() > kDroppedFrameTime) |
| 64 ++m_droppedFrameCount; | 64 ++m_droppedFrameCount; |
| 65 } | 65 } |
| 66 | 66 |
| 67 void CCFrameRateCounter::markEndOfFrame() | 67 void FrameRateCounter::markEndOfFrame() |
| 68 { | 68 { |
| 69 m_currentFrameNumber += 1; | 69 m_currentFrameNumber += 1; |
| 70 } | 70 } |
| 71 | 71 |
| 72 bool CCFrameRateCounter::isBadFrameInterval(base::TimeDelta intervalBetweenConse
cutiveFrames) const | 72 bool FrameRateCounter::isBadFrameInterval(base::TimeDelta intervalBetweenConsecu
tiveFrames) const |
| 73 { | 73 { |
| 74 bool schedulerAllowsDoubleFrames = !CCProxy::hasImplThread(); | 74 bool schedulerAllowsDoubleFrames = !Proxy::hasImplThread(); |
| 75 bool intervalTooFast = schedulerAllowsDoubleFrames && intervalBetweenConsecu
tiveFrames.InSecondsF() < kFrameTooFast; | 75 bool intervalTooFast = schedulerAllowsDoubleFrames && intervalBetweenConsecu
tiveFrames.InSecondsF() < kFrameTooFast; |
| 76 bool intervalTooSlow = intervalBetweenConsecutiveFrames.InSecondsF() > kFram
eTooSlow; | 76 bool intervalTooSlow = intervalBetweenConsecutiveFrames.InSecondsF() > kFram
eTooSlow; |
| 77 return intervalTooFast || intervalTooSlow; | 77 return intervalTooFast || intervalTooSlow; |
| 78 } | 78 } |
| 79 | 79 |
| 80 bool CCFrameRateCounter::isBadFrame(int frameNumber) const | 80 bool FrameRateCounter::isBadFrame(int frameNumber) const |
| 81 { | 81 { |
| 82 return isBadFrameInterval(frameInterval(frameNumber)); | 82 return isBadFrameInterval(frameInterval(frameNumber)); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void CCFrameRateCounter::getAverageFPSAndStandardDeviation(double& averageFPS, d
ouble& standardDeviation) const | 85 void FrameRateCounter::getAverageFPSAndStandardDeviation(double& averageFPS, dou
ble& standardDeviation) const |
| 86 { | 86 { |
| 87 int frame = m_currentFrameNumber - 1; | 87 int frame = m_currentFrameNumber - 1; |
| 88 averageFPS = 0; | 88 averageFPS = 0; |
| 89 int averageFPSCount = 0; | 89 int averageFPSCount = 0; |
| 90 double fpsVarianceNumerator = 0; | 90 double fpsVarianceNumerator = 0; |
| 91 | 91 |
| 92 // Walk backwards through the samples looking for a run of good frame | 92 // Walk backwards through the samples looking for a run of good frame |
| 93 // timings from which to compute the mean and standard deviation. | 93 // timings from which to compute the mean and standard deviation. |
| 94 // | 94 // |
| 95 // Slow frames occur just because the user is inactive, and should be | 95 // Slow frames occur just because the user is inactive, and should be |
| (...skipping 21 matching lines...) Expand all Loading... |
| 117 --frame; | 117 --frame; |
| 118 if (frameIndex(frame) == frameIndex(m_currentFrameNumber) || frame < 0)
{ | 118 if (frameIndex(frame) == frameIndex(m_currentFrameNumber) || frame < 0)
{ |
| 119 // We've gone through all available historical data, so stop. | 119 // We've gone through all available historical data, so stop. |
| 120 break; | 120 break; |
| 121 } | 121 } |
| 122 } | 122 } |
| 123 | 123 |
| 124 standardDeviation = sqrt(fpsVarianceNumerator / averageFPSCount); | 124 standardDeviation = sqrt(fpsVarianceNumerator / averageFPSCount); |
| 125 } | 125 } |
| 126 | 126 |
| 127 base::TimeTicks CCFrameRateCounter::timeStampOfRecentFrame(int n) | 127 base::TimeTicks FrameRateCounter::timeStampOfRecentFrame(int n) |
| 128 { | 128 { |
| 129 ASSERT(n >= 0 && n < kTimeStampHistorySize); | 129 ASSERT(n >= 0 && n < kTimeStampHistorySize); |
| 130 int desiredIndex = (frameIndex(m_currentFrameNumber) + n) % kTimeStampHistor
ySize; | 130 int desiredIndex = (frameIndex(m_currentFrameNumber) + n) % kTimeStampHistor
ySize; |
| 131 return m_timeStampHistory[desiredIndex]; | 131 return m_timeStampHistory[desiredIndex]; |
| 132 } | 132 } |
| 133 | 133 |
| 134 } // namespace cc | 134 } // namespace cc |
| 135 | 135 |
| OLD | NEW |