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

Side by Side Diff: cc/frame_rate_counter.cc

Issue 11369200: improving UI of FPS counter (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 "cc/frame_rate_counter.h" 5 #include "cc/frame_rate_counter.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "cc/proxy.h" 10 #include "cc/proxy.h"
11 11
12 namespace cc { 12 namespace cc {
13 13
14 const double FrameRateCounter::kFrameTooFast = 1.0 / 70.0; // measured in second s 14 const double FrameRateCounter::kFrameTooFast = 1.0 / 70.0; // measured in second s
15 const double FrameRateCounter::kFrameTooSlow = 1.0 / 12.0; 15 const double FrameRateCounter::kFrameTooSlow = 1.0;
egraether 2012/11/12 23:44:06 Reduced the kFrameTooSlow value so that only time
nduca 2012/11/13 00:51:46 How about .25 second? I'm thinking about pauses as
16 const double FrameRateCounter::kDroppedFrameTime = 1.0 / 50.0; 16 const double FrameRateCounter::kDroppedFrameTime = 1.0 / 50.0;
17 17
18 // safeMod works on -1, returning m-1 in that case. 18 // safeMod works on -1, returning m-1 in that case.
19 static inline int safeMod(int number, int modulus) 19 static inline int safeMod(int number, int modulus)
20 { 20 {
21 return (number + modulus) % modulus; 21 return (number + modulus) % modulus;
22 } 22 }
23 23
24 // static 24 // static
25 scoped_ptr<FrameRateCounter> FrameRateCounter::create(bool hasImplThread) { 25 scoped_ptr<FrameRateCounter> FrameRateCounter::create(bool hasImplThread) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 bool intervalTooFast = schedulerAllowsDoubleFrames ? delta < kFrameTooFast : delta <= 0.0; 74 bool intervalTooFast = schedulerAllowsDoubleFrames ? delta < kFrameTooFast : delta <= 0.0;
75 bool intervalTooSlow = delta > kFrameTooSlow; 75 bool intervalTooSlow = delta > kFrameTooSlow;
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 double FrameRateCounter::getAverageFPS() const
egraether 2012/11/12 23:44:06 Method returns now the average only. Standard devi
85 { 85 {
86 int frameNumber = m_currentFrameNumber - 1; 86 int frameNumber = m_currentFrameNumber - 1;
87 int frameCount = 0; 87 int frameCount = 0;
88 double fpsVarianceNumerator = 0; 88 double frameDeltas = 0;
89 89 double averageFPS = 0;
90 averageFPS = 0;
91 standardDeviation = 0;
92 90
93 // Walk backwards through the samples looking for a run of good frame 91 // Walk backwards through the samples looking for a run of good frame
94 // timings from which to compute the mean and standard deviation. 92 // timings from which to compute the mean.
95 // 93 //
96 // Slow frames occur just because the user is inactive, and should be 94 // Slow frames occur just because the user is inactive, and should be
97 // ignored. Fast frames are ignored if the scheduler is in single-thread 95 // ignored. Fast frames are ignored if the scheduler is in single-thread
98 // mode in order to represent the true frame rate in spite of the fact that 96 // mode in order to represent the true frame rate in spite of the fact that
99 // the first few swapbuffers happen instantly which skews the statistics 97 // the first few swapbuffers happen instantly which skews the statistics
100 // too much for short lived animations. 98 // too much for short lived animations.
101 // 99 //
102 // isBadFrame encapsulates the frame too slow/frame too fast logic. 100 // isBadFrameInterval encapsulates the frame too slow/frame too fast logic.
103 101
104 // Go through all available historical data. 102 while (frameIndex(frameNumber) != frameIndex(m_currentFrameNumber) && frameN umber >= 0 && frameDeltas < 1.0) {
egraether 2012/11/12 23:44:06 I added a check for a maximum time of 1 second, so
105 while (frameIndex(frameNumber) != frameIndex(m_currentFrameNumber) && frameN umber >= 0) {
106 base::TimeDelta delta = frameInterval(frameNumber); 103 base::TimeDelta delta = frameInterval(frameNumber);
107 104
108 if (!isBadFrameInterval(delta)) { 105 if (!isBadFrameInterval(delta)) {
109 frameCount++; 106 frameCount++;
110 double x = 1.0 / delta.InSecondsF(); 107 frameDeltas += delta.InSecondsF();
egraether 2012/11/12 23:44:06 This average calculation is wrong, because x is al
111 double deltaFromAverage = x - averageFPS;
112 // Change with caution - numerics. http://en.wikipedia.org/wiki/Stan dard_deviation
113 averageFPS += deltaFromAverage / frameCount;
114 fpsVarianceNumerator += deltaFromAverage * (x - averageFPS);
egraether 2012/11/12 23:44:06 The standard deviation calculation was thereon wro
115 } else if (frameCount) 108 } else if (frameCount)
116 // We've gathered a run of good samples, so stop.
117 break; 109 break;
110
118 frameNumber--; 111 frameNumber--;
119 } 112 }
120 113
121 if (frameCount) 114 if (frameCount)
122 standardDeviation = sqrt(fpsVarianceNumerator / frameCount); 115 averageFPS = frameCount / frameDeltas;
egraether 2012/11/12 23:44:06 The average needs to be calculated by total count
nduca 2012/11/13 00:51:46 frameDeltas is an oddly named var. Can you make be
116
117 return averageFPS;
123 } 118 }
124 119
125 base::TimeTicks FrameRateCounter::timeStampOfRecentFrame(int n) const 120 base::TimeTicks FrameRateCounter::timeStampOfRecentFrame(int n) const
126 { 121 {
127 DCHECK(n >= 0); 122 DCHECK(n >= 0);
128 DCHECK(n < kTimeStampHistorySize); 123 DCHECK(n < kTimeStampHistorySize);
129 int desiredIndex = (frameIndex(m_currentFrameNumber) + n) % kTimeStampHistor ySize; 124 int desiredIndex = (frameIndex(m_currentFrameNumber) + n) % kTimeStampHistor ySize;
130 return m_timeStampHistory[desiredIndex]; 125 return m_timeStampHistory[desiredIndex];
131 } 126 }
132 127
133 } // namespace cc 128 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698