diff options
author | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-18 06:54:27 +0000 |
---|---|---|
committer | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-18 06:54:27 +0000 |
commit | 6e84de2e71a4d6c9652ba3dd4471ff4f45ac8b27 (patch) | |
tree | 2d9eaa933544f87303d9cfb552c72fd96eb2a1a3 /cc/debug/frame_rate_counter.h | |
parent | 0fc818ec6e012243303de3e013037c8c0221c83f (diff) | |
download | chromium_src-6e84de2e71a4d6c9652ba3dd4471ff4f45ac8b27.zip chromium_src-6e84de2e71a4d6c9652ba3dd4471ff4f45ac8b27.tar.gz chromium_src-6e84de2e71a4d6c9652ba3dd4471ff4f45ac8b27.tar.bz2 |
Part 2 of cc/ directory shuffles: debug
Continuation of https://src.chromium.org/viewvc/chrome?view=rev&revision=188681
BUG=190824
TBR=enne@chromium.org
Review URL: https://codereview.chromium.org/12648008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188685 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/debug/frame_rate_counter.h')
-rw-r--r-- | cc/debug/frame_rate_counter.h | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/cc/debug/frame_rate_counter.h b/cc/debug/frame_rate_counter.h new file mode 100644 index 0000000..24d4926 --- /dev/null +++ b/cc/debug/frame_rate_counter.h @@ -0,0 +1,57 @@ +// Copyright 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CC_DEBUG_FRAME_RATE_COUNTER_H_ +#define CC_DEBUG_FRAME_RATE_COUNTER_H_ + +#include "base/basictypes.h" +#include "base/memory/scoped_ptr.h" +#include "base/time.h" +#include "cc/debug/ring_buffer.h" + +namespace cc { + +// This class maintains a history of timestamps, and provides functionality to +// intelligently compute average frames per second. +class FrameRateCounter { + public: + static scoped_ptr<FrameRateCounter> Create(bool has_impl_thread); + + int current_frame_number() const { return ring_buffer_.CurrentIndex(); } + int dropped_frame_count() const { return dropped_frame_count_; } + size_t time_stamp_history_size() const { return ring_buffer_.BufferSize(); } + + void SaveTimeStamp(base::TimeTicks timestamp); + + // n = 0 returns the oldest frame interval retained in the history, while n = + // time_stamp_history_size() - 1 returns the most recent frame interval. + base::TimeDelta RecentFrameInterval(size_t n) const; + + // This is a heuristic that can be used to ignore frames in a reasonable way. + // Returns true if the given frame interval is too fast or too slow, based on + // constant thresholds. + bool IsBadFrameInterval( + base::TimeDelta interval_between_consecutive_frames) const; + + void GetMinAndMaxFPS(double* min_fps, double* max_fps) const; + double GetAverageFPS() const; + + typedef RingBuffer<base::TimeTicks, 136> RingBufferType; + RingBufferType::Iterator begin() const { return ring_buffer_.Begin(); } + RingBufferType::Iterator end() const { return ring_buffer_.End(); } + + private: + explicit FrameRateCounter(bool has_impl_thread); + + RingBufferType ring_buffer_; + + bool has_impl_thread_; + int dropped_frame_count_; + + DISALLOW_COPY_AND_ASSIGN(FrameRateCounter); +}; + +} // namespace cc + +#endif // CC_DEBUG_FRAME_RATE_COUNTER_H_ |