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

Side by Side Diff: cc/frame_rate_counter.cc

Issue 11028021: cc: Improve frame/commit accounting (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Address comments Created 8 years, 2 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 unified diff | Download patch
« no previous file with comments | « cc/frame_rate_counter.h ('k') | cc/layer_tree_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
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
17 const double CCFrameRateCounter::kFrameTooSlow = 1.0 / 12.0;
18 const double CCFrameRateCounter::kDroppedFrameTime = 1.0 / 50.0;
19
20 // safeMod works on -1, returning m-1 in that case. 16 // safeMod works on -1, returning m-1 in that case.
21 static inline int safeMod(int number, int modulus) 17 static inline int safeMod(int number, int modulus)
22 { 18 {
23 return (number + modulus) % modulus; 19 return (number + modulus) % modulus;
24 } 20 }
25 21
26 // static 22 // static
27 scoped_ptr<CCFrameRateCounter> CCFrameRateCounter::create() { 23 scoped_ptr<CCFrameRateCounter> CCFrameRateCounter::create() {
28 return make_scoped_ptr(new CCFrameRateCounter()); 24 return make_scoped_ptr(new CCFrameRateCounter());
29 } 25 }
30 26
27 void CCFrameRateCounter::setTimebaseAndInterval(base::TimeTicks timebase, base:: TimeDelta interval)
28 {
29 if (interval != m_interval) {
30 base::TimeTicks now = base::TimeTicks::Now();
31 m_vsyncCount = currentVsyncCount(now);
32 m_intervalChangedTime = now;
33 m_interval = interval;
34 }
35
36 m_frameTooFastSeconds = 0.8 * interval.InSecondsF();
37 m_frameTooSlowSeconds = 1.0 / 12.0;
38 }
39
31 inline base::TimeDelta CCFrameRateCounter::frameInterval(int frameNumber) const 40 inline base::TimeDelta CCFrameRateCounter::frameInterval(int frameNumber) const
32 { 41 {
33 return m_timeStampHistory[frameIndex(frameNumber)] - 42 return m_timeStampHistory[frameIndex(frameNumber)] -
34 m_timeStampHistory[frameIndex(frameNumber - 1)]; 43 m_timeStampHistory[frameIndex(frameNumber - 1)];
35 } 44 }
36 45
37 inline int CCFrameRateCounter::frameIndex(int frameNumber) const 46 inline int CCFrameRateCounter::frameIndex(int frameNumber) const
38 { 47 {
39 return safeMod(frameNumber, kTimeStampHistorySize); 48 return safeMod(frameNumber, kTimeStampHistorySize);
40 } 49 }
41 50
42 CCFrameRateCounter::CCFrameRateCounter() 51 CCFrameRateCounter::CCFrameRateCounter()
43 : m_currentFrameNumber(1) 52 : m_frameTooFastSeconds(0)
44 , m_droppedFrameCount(0) 53 , m_frameTooSlowSeconds(0)
54 , m_vsyncCount(0)
55 , m_currentFrameNumber(1)
45 { 56 {
46 m_timeStampHistory[0] = base::TimeTicks::Now(); 57 m_timeStampHistory[0] = base::TimeTicks::Now();
47 m_timeStampHistory[1] = m_timeStampHistory[0]; 58 m_timeStampHistory[1] = m_timeStampHistory[0];
48 for (int i = 2; i < kTimeStampHistorySize; i++) 59 for (int i = 2; i < kTimeStampHistorySize; i++)
49 m_timeStampHistory[i] = base::TimeTicks(); 60 m_timeStampHistory[i] = base::TimeTicks();
50 } 61 }
51 62
52 void CCFrameRateCounter::markBeginningOfFrame(base::TimeTicks timestamp) 63 void CCFrameRateCounter::markBeginningOfFrame(base::TimeTicks timestamp)
53 { 64 {
54 m_timeStampHistory[frameIndex(m_currentFrameNumber)] = timestamp; 65 m_timeStampHistory[frameIndex(m_currentFrameNumber)] = timestamp;
55 base::TimeDelta frameIntervalSeconds = frameInterval(m_currentFrameNumber); 66 base::TimeDelta frameIntervalSeconds = frameInterval(m_currentFrameNumber);
56 67
57 if (CCProxy::hasImplThread() && m_currentFrameNumber > 0) { 68 if (CCProxy::hasImplThread() && m_currentFrameNumber > 0) {
58 double drawDelayMs = frameIntervalSeconds.InMillisecondsF(); 69 double drawDelayMs = frameIntervalSeconds.InMillisecondsF();
59 WebKit::Platform::current()->histogramCustomCounts("Renderer4.Compositor ThreadImplDrawDelay", static_cast<int>(drawDelayMs), 1, 120, 60); 70 WebKit::Platform::current()->histogramCustomCounts("Renderer4.Compositor ThreadImplDrawDelay", static_cast<int>(drawDelayMs), 1, 120, 60);
60 } 71 }
61 72
62 if (!isBadFrameInterval(frameIntervalSeconds) &&
63 frameIntervalSeconds.InSecondsF() > kDroppedFrameTime)
64 ++m_droppedFrameCount;
65 } 73 }
66 74
67 void CCFrameRateCounter::markEndOfFrame() 75 void CCFrameRateCounter::markEndOfFrame()
68 { 76 {
69 m_currentFrameNumber += 1; 77 m_currentFrameNumber += 1;
70 } 78 }
71 79
72 bool CCFrameRateCounter::isBadFrameInterval(base::TimeDelta intervalBetweenConse cutiveFrames) const 80 bool CCFrameRateCounter::isBadFrameInterval(base::TimeDelta intervalBetweenConse cutiveFrames) const
73 { 81 {
82 ASSERT(m_interval != base::TimeDelta());
74 bool schedulerAllowsDoubleFrames = !CCProxy::hasImplThread(); 83 bool schedulerAllowsDoubleFrames = !CCProxy::hasImplThread();
75 bool intervalTooFast = schedulerAllowsDoubleFrames && intervalBetweenConsecu tiveFrames.InSecondsF() < kFrameTooFast; 84 bool intervalTooFast = schedulerAllowsDoubleFrames && intervalBetweenConsecu tiveFrames.InSecondsF() < m_frameTooFastSeconds;
76 bool intervalTooSlow = intervalBetweenConsecutiveFrames.InSecondsF() > kFram eTooSlow; 85 bool intervalTooSlow = intervalBetweenConsecutiveFrames.InSecondsF() > m_fra meTooSlowSeconds;
77 return intervalTooFast || intervalTooSlow; 86 return intervalTooFast || intervalTooSlow;
78 } 87 }
79 88
80 bool CCFrameRateCounter::isBadFrame(int frameNumber) const 89 bool CCFrameRateCounter::isBadFrame(int frameNumber) const
81 { 90 {
82 return isBadFrameInterval(frameInterval(frameNumber)); 91 return isBadFrameInterval(frameInterval(frameNumber));
83 } 92 }
84 93
94 int64_t CCFrameRateCounter::currentVsyncCount(base::TimeTicks now) const
95 {
96 int64_t vsyncCount = m_vsyncCount;
97 if (m_interval != base::TimeDelta())
98 vsyncCount += (now - m_intervalChangedTime + (m_interval/2)) / m_interva l;
99 return vsyncCount;
100 }
101
85 void CCFrameRateCounter::getAverageFPSAndStandardDeviation(double& averageFPS, d ouble& standardDeviation) const 102 void CCFrameRateCounter::getAverageFPSAndStandardDeviation(double& averageFPS, d ouble& standardDeviation) const
86 { 103 {
87 int frame = m_currentFrameNumber - 1; 104 int frame = m_currentFrameNumber - 1;
88 averageFPS = 0; 105 averageFPS = 0;
89 int averageFPSCount = 0; 106 int averageFPSCount = 0;
90 double fpsVarianceNumerator = 0; 107 double fpsVarianceNumerator = 0;
91 108
92 // Walk backwards through the samples looking for a run of good frame 109 // Walk backwards through the samples looking for a run of good frame
93 // timings from which to compute the mean and standard deviation. 110 // timings from which to compute the mean and standard deviation.
94 // 111 //
(...skipping 29 matching lines...) Expand all
124 standardDeviation = sqrt(fpsVarianceNumerator / averageFPSCount); 141 standardDeviation = sqrt(fpsVarianceNumerator / averageFPSCount);
125 } 142 }
126 143
127 base::TimeTicks CCFrameRateCounter::timeStampOfRecentFrame(int n) 144 base::TimeTicks CCFrameRateCounter::timeStampOfRecentFrame(int n)
128 { 145 {
129 ASSERT(n >= 0 && n < kTimeStampHistorySize); 146 ASSERT(n >= 0 && n < kTimeStampHistorySize);
130 int desiredIndex = (frameIndex(m_currentFrameNumber) + n) % kTimeStampHistor ySize; 147 int desiredIndex = (frameIndex(m_currentFrameNumber) + n) % kTimeStampHistor ySize;
131 return m_timeStampHistory[desiredIndex]; 148 return m_timeStampHistory[desiredIndex];
132 } 149 }
133 150
151 void CCFrameRateCounter::renderingStats(CCRenderingStats* stats) const
152 {
153 ASSERT(m_interval != base::TimeDelta());
154
155 base::TimeTicks now = base::TimeTicks::Now();
156 stats->vsyncCount = currentVsyncCount(now);
157 stats->rendererFrameCount = m_currentFrameNumber - 1;
158 stats->droppedFrameCount = stats->vsyncCount - stats->rendererFrameCount;
159 }
160
134 } // namespace cc 161 } // namespace cc
135 162
OLDNEW
« no previous file with comments | « cc/frame_rate_counter.h ('k') | cc/layer_tree_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698