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

Unified Diff: components/scheduler/renderer/idle_time_estimator_unittest.cc

Issue 1411133003: A better idle time estimator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2526
Patch Set: Created 5 years, 1 month 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
Index: components/scheduler/renderer/idle_time_estimator_unittest.cc
diff --git a/components/scheduler/renderer/idle_time_estimator_unittest.cc b/components/scheduler/renderer/idle_time_estimator_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8f34944304e95e4db7347f6435df18d0aa56693c
--- /dev/null
+++ b/components/scheduler/renderer/idle_time_estimator_unittest.cc
@@ -0,0 +1,146 @@
+// Copyright 2015 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 "components/scheduler/renderer/idle_time_estimator.h"
+
+#include "base/test/simple_test_tick_clock.h"
+#include "cc/test/ordered_simple_task_runner.h"
+#include "components/scheduler/base/task_queue_manager.h"
+#include "components/scheduler/base/test_time_source.h"
+#include "components/scheduler/child/scheduler_task_runner_delegate_for_test.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace scheduler {
+
+class IdleTimeEstimatorForTest : public IdleTimeEstimator {
+ public:
+ IdleTimeEstimatorForTest(
+ const scoped_refptr<TaskQueue>& compositor_task_runner,
+ base::SimpleTestTickClock* clock,
+ int sample_count,
+ double estimation_percentile)
+ : IdleTimeEstimator(compositor_task_runner,
+ sample_count,
+ estimation_percentile) {
+ SetTimeSourceForTesting(make_scoped_ptr(new TestTimeSource(clock)));
+ }
+};
+
+class IdleTimeEstimatorTest : public testing::Test {
+ public:
+ IdleTimeEstimatorTest()
+ : frame_length_(base::TimeDelta::FromMilliseconds(16)) {}
+
+ ~IdleTimeEstimatorTest() override {}
+
+ void SetUp() override {
+ clock_.reset(new base::SimpleTestTickClock());
+ clock_->Advance(base::TimeDelta::FromMicroseconds(5000));
+ mock_task_runner_ = make_scoped_refptr(
+ new cc::OrderedSimpleTaskRunner(clock_.get(), false));
+ main_task_runner_ =
+ SchedulerTaskRunnerDelegateForTest::Create(mock_task_runner_);
+ manager_ = make_scoped_ptr(new TaskQueueManager(
+ main_task_runner_, "test.scheduler", "test.scheduler.debug"));
+ compositor_task_runner_ =
+ manager_->NewTaskQueue(TaskQueue::Spec("compositor_tq"));
+ estimator_.reset(new IdleTimeEstimatorForTest(compositor_task_runner_,
+ clock_.get(), 10, 50));
+ }
+
+ void SimulateFrameWithOneCompositorTask(int compositor_time) {
+ base::TimeDelta non_idle_time =
+ base::TimeDelta::FromMilliseconds(compositor_time);
+ base::PendingTask task(FROM_HERE, base::Closure());
+ estimator_->WillProcessTask(task);
+ clock_->Advance(non_idle_time);
+ estimator_->DidCommitFrameToCompositor();
+ estimator_->DidProcessTask(task);
+ if (non_idle_time < frame_length_)
+ clock_->Advance(frame_length_ - non_idle_time);
+ }
+
+ void SimulateFrameWithTwoCompositorTasks(int compositor_time1,
+ int compositor_time2) {
+ base::TimeDelta non_idle_time1 =
+ base::TimeDelta::FromMilliseconds(compositor_time1);
+ base::TimeDelta non_idle_time2 =
+ base::TimeDelta::FromMilliseconds(compositor_time2);
+ base::PendingTask task(FROM_HERE, base::Closure());
+ estimator_->WillProcessTask(task);
+ clock_->Advance(non_idle_time1);
+ estimator_->DidProcessTask(task);
+
+ estimator_->WillProcessTask(task);
+ clock_->Advance(non_idle_time2);
+ estimator_->DidCommitFrameToCompositor();
+ estimator_->DidProcessTask(task);
+
+ base::TimeDelta idle_time = frame_length_ - non_idle_time1 - non_idle_time2;
+ clock_->Advance(idle_time);
+ }
+
+ scoped_ptr<base::SimpleTestTickClock> clock_;
+ scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_;
+ scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner_;
+ scoped_ptr<TaskQueueManager> manager_;
+ scoped_refptr<TaskQueue> compositor_task_runner_;
+ scoped_ptr<IdleTimeEstimatorForTest> estimator_;
+ const base::TimeDelta frame_length_;
+};
+
+TEST_F(IdleTimeEstimatorTest, InitialTimeEstimateWithNoData) {
+ EXPECT_EQ(frame_length_, estimator_->GetExpectedIdleDuration(frame_length_));
+}
+
+TEST_F(IdleTimeEstimatorTest, BasicEstimation_SteadyState) {
+ SimulateFrameWithOneCompositorTask(5);
+ SimulateFrameWithOneCompositorTask(5);
+
+ EXPECT_EQ(base::TimeDelta::FromMilliseconds(11),
+ estimator_->GetExpectedIdleDuration(frame_length_));
+}
+
+TEST_F(IdleTimeEstimatorTest, BasicEstimation_Variable) {
+ SimulateFrameWithOneCompositorTask(5);
+ SimulateFrameWithOneCompositorTask(6);
+ SimulateFrameWithOneCompositorTask(7);
+ SimulateFrameWithOneCompositorTask(7);
+ SimulateFrameWithOneCompositorTask(7);
+ SimulateFrameWithOneCompositorTask(8);
+
+ // We expect it to return the median.
+ EXPECT_EQ(base::TimeDelta::FromMilliseconds(9),
+ estimator_->GetExpectedIdleDuration(frame_length_));
+}
+
+TEST_F(IdleTimeEstimatorTest, NoIdleTime) {
+ SimulateFrameWithOneCompositorTask(100);
+ SimulateFrameWithOneCompositorTask(100);
+
+ EXPECT_EQ(base::TimeDelta::FromMilliseconds(0),
+ estimator_->GetExpectedIdleDuration(frame_length_));
+}
+
+TEST_F(IdleTimeEstimatorTest, Clear) {
+ SimulateFrameWithOneCompositorTask(5);
+ SimulateFrameWithOneCompositorTask(5);
+
+ EXPECT_EQ(base::TimeDelta::FromMilliseconds(11),
+ estimator_->GetExpectedIdleDuration(frame_length_));
+ estimator_->Clear();
+
+ EXPECT_EQ(frame_length_, estimator_->GetExpectedIdleDuration(frame_length_));
+}
+
+TEST_F(IdleTimeEstimatorTest, Estimation_MultipleTasks) {
+ SimulateFrameWithTwoCompositorTasks(1, 4);
+ SimulateFrameWithTwoCompositorTasks(1, 4);
+
+ EXPECT_EQ(base::TimeDelta::FromMilliseconds(11),
+ estimator_->GetExpectedIdleDuration(frame_length_));
+}
+
+} // namespace scheduler
« no previous file with comments | « components/scheduler/renderer/idle_time_estimator.cc ('k') | components/scheduler/renderer/renderer_scheduler_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698