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 #ifndef CCFrameRateCounter_h | 5 #ifndef CCFrameRateCounter_h |
6 #define CCFrameRateCounter_h | 6 #define CCFrameRateCounter_h |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
11 | 11 |
12 namespace cc { | 12 namespace cc { |
13 | 13 |
14 // This class maintains a history of timestamps, and provides functionality to | 14 // This class maintains a history of timestamps, and provides functionality to |
15 // intelligently compute average frames per second (and standard deviation). | 15 // intelligently compute average frames per second (and standard deviation). |
16 class FrameRateCounter { | 16 class FrameRateCounter { |
17 public: | 17 public: |
18 static scoped_ptr<FrameRateCounter> create(); | 18 static scoped_ptr<FrameRateCounter> create(); |
19 | 19 |
20 void markBeginningOfFrame(base::TimeTicks timestamp); | 20 void markBeginningOfFrame(base::TimeTicks timestamp); |
21 void markEndOfFrame(); | 21 void markEndOfFrame(); |
22 int currentFrameNumber() const { return m_currentFrameNumber; } | 22 int currentFrameNumber() const { return m_currentFrameNumber; } |
23 void getAverageFPSAndStandardDeviation(double& averageFPS, double& standardD eviation) const; | 23 void getAverageFPSAndStandardDeviation(double& averageFPS, double& standardD eviation) const; |
24 int timeStampHistorySize() const { return kTimeStampHistorySize; } | 24 int timeStampHistorySize() const { return kTimeStampHistorySize; } |
25 | 25 |
26 // n = 0 returns the oldest frame retained in the history, | 26 // n = 0 returns the oldest frame retained in the history, |
27 // while n = timeStampHistorySize() - 1 returns the timestamp most recent fr ame. | 27 // while n = timeStampHistorySize() - 1 returns the timestamp most recent fr ame. |
28 base::TimeTicks timeStampOfRecentFrame(int n); | 28 base::TimeTicks timeStampOfRecentFrame(int n) const; |
29 | 29 |
30 // This is a heuristic that can be used to ignore frames in a reasonable way . Returns | 30 // This is a heuristic that can be used to ignore frames in a reasonable way . Returns |
31 // true if the given frame interval is too fast or too slow, based on consta nt thresholds. | 31 // true if the given frame interval is too fast or too slow, based on consta nt thresholds. |
32 bool isBadFrameInterval(base::TimeDelta intervalBetweenConsecutiveFrames) co nst; | 32 bool isBadFrameInterval(base::TimeDelta intervalBetweenConsecutiveFrames) co nst; |
33 | 33 |
34 int droppedFrameCount() const { return m_droppedFrameCount; } | 34 int droppedFrameCount() const { return m_droppedFrameCount; } |
35 | 35 |
36 private: | 36 private: |
37 FrameRateCounter(); | 37 FrameRateCounter(); |
38 | 38 |
39 base::TimeDelta frameInterval(int frameNumber) const; | 39 base::TimeDelta frameInterval(int frameNumber) const; |
40 int frameIndex(int frameNumber) const; | 40 int frameIndex(int frameNumber) const; |
41 bool isBadFrame(int frameNumber) const; | 41 bool isBadFrame(int frameNumber) const; |
42 | 42 |
43 // Two thresholds (measured in seconds) that describe what is considered to be a "no-op frame" that should not be counted. | 43 // Two thresholds (measured in seconds) that describe what is considered to be a "no-op frame" that should not be counted. |
44 // - if the frame is too fast, then given our compositor implementation, the frame probably was a no-op and did not draw. | 44 // - if the frame is too fast, then given our compositor implementation, the frame probably was a no-op and did not draw. |
45 // - if the frame is too slow, then there is probably not animating content, so we should not pollute the average. | 45 // - if the frame is too slow, then there is probably not animating content, so we should not pollute the average. |
46 static const double kFrameTooFast; | 46 static const double kFrameTooFast; |
47 static const double kFrameTooSlow; | 47 static const double kFrameTooSlow; |
48 | 48 |
49 // If a frame takes longer than this threshold (measured in seconds) then we | 49 // If a frame takes longer than this threshold (measured in seconds) then we |
50 // (naively) assume that it missed a screen refresh; that is, we dropped a f rame. | 50 // (naively) assume that it missed a screen refresh; that is, we dropped a f rame. |
51 // FIXME: Determine this threshold based on monitor refresh rate, crbug.com/ 138642. | 51 // FIXME: Determine this threshold based on monitor refresh rate, crbug.com/ 138642. |
52 static const double kDroppedFrameTime; | 52 static const double kDroppedFrameTime; |
53 | 53 |
54 static const int kTimeStampHistorySize = 120; | 54 static const int kTimeStampHistorySize = 170; |
egraether
2012/10/26 00:06:52
I increased the number of samples in the graph so
| |
55 | 55 |
56 int m_currentFrameNumber; | 56 int m_currentFrameNumber; |
57 base::TimeTicks m_timeStampHistory[kTimeStampHistorySize]; | 57 base::TimeTicks m_timeStampHistory[kTimeStampHistorySize]; |
58 | 58 |
59 int m_droppedFrameCount; | 59 int m_droppedFrameCount; |
60 | 60 |
61 DISALLOW_COPY_AND_ASSIGN(FrameRateCounter); | 61 DISALLOW_COPY_AND_ASSIGN(FrameRateCounter); |
62 }; | 62 }; |
63 | 63 |
64 } // namespace cc | 64 } // namespace cc |
65 | 65 |
66 #endif | 66 #endif |
OLD | NEW |