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

Unified Diff: cc/debug/lap_timer.cc

Issue 1531403002: Revert "Delete CC." (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/debug/lap_timer.h ('k') | cc/debug/paint_time_counter.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/debug/lap_timer.cc
diff --git a/cc/debug/lap_timer.cc b/cc/debug/lap_timer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..347e3a52d66a443ab401643de8d54e3aa0616f58
--- /dev/null
+++ b/cc/debug/lap_timer.cc
@@ -0,0 +1,81 @@
+// Copyright 2014 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.
+
+#include "cc/debug/lap_timer.h"
+
+#include "base/logging.h"
+
+namespace cc {
+
+namespace {
+
+base::TimeDelta Now() {
+ return base::ThreadTicks::IsSupported()
+ ? base::ThreadTicks::Now() - base::ThreadTicks()
+ : base::TimeTicks::Now() - base::TimeTicks();
+}
+
+} // namespace
+
+LapTimer::LapTimer(int warmup_laps,
+ base::TimeDelta time_limit,
+ int check_interval)
+ : warmup_laps_(warmup_laps),
+ remaining_warmups_(0),
+ remaining_no_check_laps_(0),
+ time_limit_(time_limit),
+ check_interval_(check_interval) {
+ DCHECK_GT(check_interval, 0);
+ Reset();
+}
+
+void LapTimer::Reset() {
+ accumulator_ = base::TimeDelta();
+ num_laps_ = 0;
+ remaining_warmups_ = warmup_laps_;
+ remaining_no_check_laps_ = check_interval_;
+ Start();
+}
+
+void LapTimer::Start() {
+ start_time_ = Now();
+}
+
+bool LapTimer::IsWarmedUp() { return remaining_warmups_ <= 0; }
+
+void LapTimer::NextLap() {
+ if (!IsWarmedUp()) {
+ --remaining_warmups_;
+ if (IsWarmedUp()) {
+ Start();
+ }
+ return;
+ }
+ ++num_laps_;
+ --remaining_no_check_laps_;
+ if (!remaining_no_check_laps_) {
+ base::TimeDelta now = Now();
+ accumulator_ += now - start_time_;
+ start_time_ = now;
+ remaining_no_check_laps_ = check_interval_;
+ }
+}
+
+bool LapTimer::HasTimeLimitExpired() { return accumulator_ >= time_limit_; }
+
+bool LapTimer::HasTimedAllLaps() { return !(num_laps_ % check_interval_); }
+
+float LapTimer::MsPerLap() {
+ DCHECK(HasTimedAllLaps());
+ return accumulator_.InMillisecondsF() / num_laps_;
+}
+
+float LapTimer::LapsPerSecond() {
+ DCHECK(HasTimedAllLaps());
+ return num_laps_ / accumulator_.InSecondsF();
+}
+
+int LapTimer::NumLaps() { return num_laps_; }
+
+} // namespace cc
« no previous file with comments | « cc/debug/lap_timer.h ('k') | cc/debug/paint_time_counter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698