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

Side by Side Diff: cc/frame_rate_counter.h

Issue 11817011: cc: add RingBuffer class for timestamp storing in FrameRateCounter (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: switched to FrameRateCounter has a RingBuffer Created 7 years, 11 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
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 CC_FRAME_RATE_COUNTER_H_ 5 #ifndef CC_FRAME_RATE_COUNTER_H_
6 #define CC_FRAME_RATE_COUNTER_H_ 6 #define CC_FRAME_RATE_COUNTER_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 #include "cc/ring_buffer.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. 16 // intelligently compute average frames per second.
16 class FrameRateCounter { 17 class FrameRateCounter {
17 public: 18 public:
18 static scoped_ptr<FrameRateCounter> create(bool hasImplThread); 19 static scoped_ptr<FrameRateCounter> create(bool hasImplThread);
19 20
20 void markBeginningOfFrame(base::TimeTicks timestamp); 21 int currentFrameNumber() const { return m_ringBuffer.CurrentIndex(); }
21 void markEndOfFrame(); 22 int droppedFrameCount() const { return m_droppedFrameCount; }
22 int currentFrameNumber() const { return m_currentFrameNumber; } 23 int timeStampHistorySize() const { return m_ringBuffer.BufferSize(); }
23 double getAverageFPS() const; 24
24 int timeStampHistorySize() const { return kTimeStampHistorySize; } 25 void saveTimeStamp(base::TimeTicks timestamp);
25 26
26 // n = 0 returns the oldest frame retained in the history, 27 // n = 0 returns the oldest frame retained in the history,
27 // while n = timeStampHistorySize() - 1 returns the timestamp most recent fr ame. 28 // while n = timeStampHistorySize() - 1 returns the timestamp most recent fr ame.
28 // FIXME: Returns most recent timestamp for n = 0 when called between markBe ginningOfFrame and markEndOfFrame calls.
29 base::TimeTicks timeStampOfRecentFrame(int n) const; 29 base::TimeTicks timeStampOfRecentFrame(int n) const;
30 30
31 // This is a heuristic that can be used to ignore frames in a reasonable way . Returns 31 // This is a heuristic that can be used to ignore frames in a reasonable way . Returns
32 // true if the given frame interval is too fast or too slow, based on consta nt thresholds. 32 // true if the given frame interval is too fast or too slow, based on consta nt thresholds.
33 bool isBadFrameInterval(base::TimeDelta intervalBetweenConsecutiveFrames) co nst; 33 bool isBadFrameInterval(base::TimeDelta intervalBetweenConsecutiveFrames) co nst;
34 34
35 int droppedFrameCount() const { return m_droppedFrameCount; } 35 void getMinAndMaxFPS(double& minFPS, double& maxFPS) const;
36 double getAverageFPS() const;
36 37
37 private: 38 private:
38 explicit FrameRateCounter(bool hasImplThread); 39 explicit FrameRateCounter(bool hasImplThread);
39 40
40 base::TimeDelta frameInterval(int frameNumber) const; 41 base::TimeDelta recentFrameInterval(int n) const;
41 int frameIndex(int frameNumber) const;
42 bool isBadFrame(int frameNumber) const;
43 42
44 // 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.
45 // - 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.
46 // - 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.
47 static const double kFrameTooFast; 46 static const double kFrameTooFast;
48 static const double kFrameTooSlow; 47 static const double kFrameTooSlow;
49 48
50 // 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
51 // (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.
52 // 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.
53 static const double kDroppedFrameTime; 52 static const double kDroppedFrameTime;
54 53
55 static const int kTimeStampHistorySize = 130; 54 RingBuffer<base::TimeTicks, 130> m_ringBuffer;
egraether 2013/01/10 02:32:09 FrameRateCounter now has a RingBuffer. I solved th
56 55
57 bool m_hasImplThread; 56 bool m_hasImplThread;
58
59 int m_currentFrameNumber;
60 base::TimeTicks m_timeStampHistory[kTimeStampHistorySize];
61
62 int m_droppedFrameCount; 57 int m_droppedFrameCount;
63 58
64 DISALLOW_COPY_AND_ASSIGN(FrameRateCounter); 59 DISALLOW_COPY_AND_ASSIGN(FrameRateCounter);
65 }; 60 };
66 61
67 } // namespace cc 62 } // namespace cc
68 63
69 #endif // CC_FRAME_RATE_COUNTER_H_ 64 #endif // CC_FRAME_RATE_COUNTER_H_
OLDNEW
« no previous file with comments | « cc/cc.gyp ('k') | cc/frame_rate_counter.cc » ('j') | cc/frame_rate_counter.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698