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

Side by Side Diff: cc/frame_rate_counter.cc

Issue 11272042: improvements of the FPS counter in the HUDLayer (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 1 month 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 unified diff | Download patch
OLDNEW
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
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 bool intervalTooFast = schedulerAllowsDoubleFrames && intervalBetweenConsecu tiveFrames.InSecondsF() < kFrameTooFast; 74 bool intervalTooFast = schedulerAllowsDoubleFrames && intervalBetweenConsecu tiveFrames.InSecondsF() < kFrameTooFast;
75 bool intervalTooSlow = intervalBetweenConsecutiveFrames.InSecondsF() > kFram eTooSlow; 75 bool intervalTooSlow = intervalBetweenConsecutiveFrames.InSecondsF() > kFram eTooSlow;
76 return intervalTooFast || intervalTooSlow; 76 return intervalTooFast || intervalTooSlow;
77 } 77 }
78 78
79 bool FrameRateCounter::isBadFrame(int frameNumber) const 79 bool FrameRateCounter::isBadFrame(int frameNumber) const
80 { 80 {
81 return isBadFrameInterval(frameInterval(frameNumber)); 81 return isBadFrameInterval(frameInterval(frameNumber));
82 } 82 }
83 83
84 void FrameRateCounter::getAverageFPSAndStandardDeviation(double& averageFPS, dou ble& standardDeviation) const 84 void FrameRateCounter::getAverageFPSAndStandardDeviation(double& averageFPS, dou ble& standardDeviation) const
egraether 2012/10/26 00:06:52 I refactored this method, because it was hard to r
85 { 85 {
86 int frame = m_currentFrameNumber - 1; 86 int frameNumber = m_currentFrameNumber - 1;
87 int frameCount = 0;
88 double fpsVarianceNumerator = 0;
89
87 averageFPS = 0; 90 averageFPS = 0;
88 int averageFPSCount = 0; 91 standardDeviation = 0;
89 double fpsVarianceNumerator = 0;
90 92
91 // Walk backwards through the samples looking for a run of good frame 93 // Walk backwards through the samples looking for a run of good frame
92 // timings from which to compute the mean and standard deviation. 94 // timings from which to compute the mean and standard deviation.
93 // 95 //
94 // Slow frames occur just because the user is inactive, and should be 96 // Slow frames occur just because the user is inactive, and should be
95 // ignored. Fast frames are ignored if the scheduler is in single-thread 97 // ignored. Fast frames are ignored if the scheduler is in single-thread
96 // mode in order to represent the true frame rate in spite of the fact that 98 // mode in order to represent the true frame rate in spite of the fact that
97 // the first few swapbuffers happen instantly which skews the statistics 99 // the first few swapbuffers happen instantly which skews the statistics
98 // too much for short lived animations. 100 // too much for short lived animations.
99 // 101 //
100 // isBadFrame encapsulates the frame too slow/frame too fast logic. 102 // isBadFrame encapsulates the frame too slow/frame too fast logic.
101 while (1) { 103
102 if (!isBadFrame(frame)) { 104 // Go through all available historical data.
103 averageFPSCount++; 105 while (frameIndex(frameNumber) != frameIndex(m_currentFrameNumber) && frameN umber >= 0) {
104 base::TimeDelta secForLastFrame = m_timeStampHistory[frameIndex(fram e)] - 106 base::TimeDelta delta = frameInterval(frameNumber);
105 m_timeStampHistory[frameIndex(fram e - 1)]; 107
106 double x = 1.0 / secForLastFrame.InSecondsF(); 108 if (!isBadFrameInterval(delta)) {
109 frameCount++;
110 double x = 1.0 / delta.InSecondsF();
107 double deltaFromAverage = x - averageFPS; 111 double deltaFromAverage = x - averageFPS;
108 // Change with caution - numerics. http://en.wikipedia.org/wiki/Stan dard_deviation 112 // Change with caution - numerics. http://en.wikipedia.org/wiki/Stan dard_deviation
109 averageFPS = averageFPS + deltaFromAverage / averageFPSCount; 113 averageFPS += deltaFromAverage / frameCount;
110 fpsVarianceNumerator = fpsVarianceNumerator + deltaFromAverage * (x - averageFPS); 114 fpsVarianceNumerator += deltaFromAverage * (x - averageFPS);
111 } 115 } else if (frameCount)
112 if (averageFPSCount && isBadFrame(frame)) {
113 // We've gathered a run of good samples, so stop. 116 // We've gathered a run of good samples, so stop.
114 break; 117 break;
115 } 118 frameNumber--;
116 --frame;
117 if (frameIndex(frame) == frameIndex(m_currentFrameNumber) || frame < 0) {
118 // We've gone through all available historical data, so stop.
119 break;
120 }
121 } 119 }
122 120
123 standardDeviation = sqrt(fpsVarianceNumerator / averageFPSCount); 121 if (frameCount)
egraether 2012/10/26 00:06:52 This is a fix for a divide by zero error. It made
122 standardDeviation = sqrt(fpsVarianceNumerator / frameCount);
124 } 123 }
125 124
126 base::TimeTicks FrameRateCounter::timeStampOfRecentFrame(int n) 125 base::TimeTicks FrameRateCounter::timeStampOfRecentFrame(int n) const
127 { 126 {
128 DCHECK(n >= 0); 127 DCHECK(n >= 0);
129 DCHECK(n < kTimeStampHistorySize); 128 DCHECK(n < kTimeStampHistorySize);
130 int desiredIndex = (frameIndex(m_currentFrameNumber) + n) % kTimeStampHistor ySize; 129 int desiredIndex = (frameIndex(m_currentFrameNumber) + n) % kTimeStampHistor ySize;
131 return m_timeStampHistory[desiredIndex]; 130 return m_timeStampHistory[desiredIndex];
132 } 131 }
133 132
134 } // namespace cc 133 } // namespace cc
135 134
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698