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

Side by Side Diff: cc/frame_rate_counter.h

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_controller.cc ('k') | cc/frame_rate_counter.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 #ifndef CCFrameRateCounter_h 5 #ifndef CCFrameRateCounter_h
6 #define CCFrameRateCounter_h 6 #define CCFrameRateCounter_h
7 7
8 #include "CCRenderingStats.h"
8 #include "base/basictypes.h" 9 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
10 #include "base/time.h" 11 #include "base/time.h"
11 12
12 namespace cc { 13 namespace cc {
13 14
14 // This class maintains a history of timestamps, and provides functionality to 15 // This class maintains a history of timestamps, and provides functionality to
15 // intelligently compute average frames per second (and standard deviation). 16 // intelligently compute average frames per second (and standard deviation).
16 class CCFrameRateCounter { 17 class CCFrameRateCounter {
17 public: 18 public:
18 static scoped_ptr<CCFrameRateCounter> create(); 19 static scoped_ptr<CCFrameRateCounter> create();
19 20
21 void setTimebaseAndInterval(base::TimeTicks timebase, base::TimeDelta interv al);
22
20 void markBeginningOfFrame(base::TimeTicks timestamp); 23 void markBeginningOfFrame(base::TimeTicks timestamp);
21 void markEndOfFrame(); 24 void markEndOfFrame();
22 int currentFrameNumber() const { return m_currentFrameNumber; } 25 int64_t currentFrameNumber() const { return m_currentFrameNumber; }
23 void getAverageFPSAndStandardDeviation(double& averageFPS, double& standardD eviation) const; 26 void getAverageFPSAndStandardDeviation(double& averageFPS, double& standardD eviation) const;
24 int timeStampHistorySize() const { return kTimeStampHistorySize; } 27 int timeStampHistorySize() const { return kTimeStampHistorySize; }
25 28
26 // n = 0 returns the oldest frame retained in the history, 29 // n = 0 returns the oldest frame retained in the history,
27 // while n = timeStampHistorySize() - 1 returns the timestamp most recent fr ame. 30 // while n = timeStampHistorySize() - 1 returns the timestamp most recent fr ame.
28 base::TimeTicks timeStampOfRecentFrame(int n); 31 base::TimeTicks timeStampOfRecentFrame(int n);
29 32
30 // This is a heuristic that can be used to ignore frames in a reasonable way . Returns 33 // 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. 34 // 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; 35 bool isBadFrameInterval(base::TimeDelta intervalBetweenConsecutiveFrames) co nst;
33 36
34 int droppedFrameCount() const { return m_droppedFrameCount; } 37 void renderingStats(CCRenderingStats* stats) const;
35 38
36 private: 39 private:
37 CCFrameRateCounter(); 40 CCFrameRateCounter();
38 41
39 base::TimeDelta frameInterval(int frameNumber) const; 42 base::TimeDelta frameInterval(int frameNumber) const;
40 int frameIndex(int frameNumber) const; 43 int frameIndex(int frameNumber) const;
41 bool isBadFrame(int frameNumber) const; 44 bool isBadFrame(int frameNumber) const;
45 int64_t currentVsyncCount(base::TimeTicks now) const;
46
47 static const int kTimeStampHistorySize = 120;
48
49 base::TimeTicks m_timeStampHistory[kTimeStampHistorySize];
42 50
43 // Two thresholds (measured in seconds) that describe what is considered to be a "no-op frame" that should not be counted. 51 // 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. 52 // - 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. 53 // - 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; 54 double m_frameTooFastSeconds;
47 static const double kFrameTooSlow; 55 double m_frameTooSlowSeconds;
48 56
49 // If a frame takes longer than this threshold (measured in seconds) then we 57 int64_t m_vsyncCount;
50 // (naively) assume that it missed a screen refresh; that is, we dropped a f rame. 58 int64_t m_currentFrameNumber;
51 // FIXME: Determine this threshold based on monitor refresh rate, crbug.com/ 138642. 59 bool m_active;
52 static const double kDroppedFrameTime; 60 base::TimeTicks m_activeTimestamp;
53 61 base::TimeTicks m_intervalChangedTime;
54 static const int kTimeStampHistorySize = 120; 62 base::TimeDelta m_interval;
55
56 int m_currentFrameNumber;
57 base::TimeTicks m_timeStampHistory[kTimeStampHistorySize];
58
59 int m_droppedFrameCount;
60 63
61 DISALLOW_COPY_AND_ASSIGN(CCFrameRateCounter); 64 DISALLOW_COPY_AND_ASSIGN(CCFrameRateCounter);
62 }; 65 };
63 66
64 } // namespace cc 67 } // namespace cc
65 68
66 #endif 69 #endif
OLDNEW
« no previous file with comments | « cc/frame_rate_controller.cc ('k') | cc/frame_rate_counter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698