OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "components/scheduler/renderer/idle_time_estimator.h" | 5 #include "components/scheduler/renderer/idle_time_estimator.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/test/simple_test_tick_clock.h" | 8 #include "base/test/simple_test_tick_clock.h" |
9 #include "cc/test/ordered_simple_task_runner.h" | 9 #include "cc/test/ordered_simple_task_runner.h" |
10 #include "components/scheduler/base/task_queue_manager.h" | 10 #include "components/scheduler/base/task_queue_manager.h" |
| 11 #include "components/scheduler/base/task_time_tracker.h" |
11 #include "components/scheduler/base/test_time_source.h" | 12 #include "components/scheduler/base/test_time_source.h" |
12 #include "components/scheduler/child/scheduler_tqm_delegate_for_test.h" | 13 #include "components/scheduler/child/scheduler_tqm_delegate_for_test.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 namespace scheduler { | 17 namespace scheduler { |
17 | 18 |
18 class IdleTimeEstimatorForTest : public IdleTimeEstimator { | 19 class IdleTimeEstimatorForTest : public IdleTimeEstimator { |
19 public: | 20 public: |
20 IdleTimeEstimatorForTest( | 21 IdleTimeEstimatorForTest( |
21 const scoped_refptr<TaskQueue>& compositor_task_runner, | 22 const scoped_refptr<TaskQueue>& compositor_task_runner, |
22 TestTimeSource* test_time_source, | 23 TestTimeSource* test_time_source, |
23 int sample_count, | 24 int sample_count, |
24 double estimation_percentile) | 25 double estimation_percentile) |
25 : IdleTimeEstimator(compositor_task_runner, | 26 : IdleTimeEstimator(compositor_task_runner, |
26 test_time_source, | 27 test_time_source, |
27 sample_count, | 28 sample_count, |
28 estimation_percentile) {} | 29 estimation_percentile) {} |
29 }; | 30 }; |
30 | 31 |
31 class IdleTimeEstimatorTest : public testing::Test { | 32 class IdleTimeEstimatorTest : public testing::Test { |
32 public: | 33 public: |
33 IdleTimeEstimatorTest() | 34 IdleTimeEstimatorTest() |
34 : frame_length_(base::TimeDelta::FromMilliseconds(16)) {} | 35 : frame_length_(base::TimeDelta::FromMilliseconds(16)), |
| 36 task_time_tracker_(nullptr) {} |
35 | 37 |
36 ~IdleTimeEstimatorTest() override {} | 38 ~IdleTimeEstimatorTest() override {} |
37 | 39 |
38 void SetUp() override { | 40 void SetUp() override { |
39 clock_.reset(new base::SimpleTestTickClock()); | 41 clock_.reset(new base::SimpleTestTickClock()); |
40 clock_->Advance(base::TimeDelta::FromMicroseconds(5000)); | 42 clock_->Advance(base::TimeDelta::FromMicroseconds(5000)); |
41 test_time_source_.reset(new TestTimeSource(clock_.get())); | 43 test_time_source_.reset(new TestTimeSource(clock_.get())); |
42 mock_task_runner_ = make_scoped_refptr( | 44 mock_task_runner_ = make_scoped_refptr( |
43 new cc::OrderedSimpleTaskRunner(clock_.get(), false)); | 45 new cc::OrderedSimpleTaskRunner(clock_.get(), false)); |
44 main_task_runner_ = SchedulerTqmDelegateForTest::Create( | 46 main_task_runner_ = SchedulerTqmDelegateForTest::Create( |
45 mock_task_runner_, base::WrapUnique(new TestTimeSource(clock_.get()))); | 47 mock_task_runner_, base::WrapUnique(new TestTimeSource(clock_.get()))); |
46 manager_ = base::WrapUnique( | 48 manager_ = base::WrapUnique(new TaskQueueManager( |
47 new TaskQueueManager(main_task_runner_, "test.scheduler", | 49 main_task_runner_, "test.scheduler", "test.scheduler", |
48 "test.scheduler", "test.scheduler.debug")); | 50 "test.scheduler.debug")); |
49 compositor_task_runner_ = | 51 compositor_task_runner_ = |
50 manager_->NewTaskQueue(TaskQueue::Spec("compositor_tq")); | 52 manager_->NewTaskQueue(TaskQueue::Spec("compositor_tq")); |
51 estimator_.reset(new IdleTimeEstimatorForTest( | 53 estimator_.reset(new IdleTimeEstimatorForTest( |
52 compositor_task_runner_, test_time_source_.get(), 10, 50)); | 54 compositor_task_runner_, test_time_source_.get(), 10, 50)); |
53 } | 55 } |
54 | 56 |
55 void SimulateFrameWithOneCompositorTask(int compositor_time) { | 57 void SimulateFrameWithOneCompositorTask(int compositor_time) { |
56 base::TimeDelta non_idle_time = | 58 base::TimeDelta non_idle_time = |
57 base::TimeDelta::FromMilliseconds(compositor_time); | 59 base::TimeDelta::FromMilliseconds(compositor_time); |
58 base::PendingTask task(FROM_HERE, base::Closure()); | 60 base::PendingTask task(FROM_HERE, base::Closure()); |
(...skipping 26 matching lines...) Expand all Loading... |
85 } | 87 } |
86 | 88 |
87 std::unique_ptr<base::SimpleTestTickClock> clock_; | 89 std::unique_ptr<base::SimpleTestTickClock> clock_; |
88 std::unique_ptr<TestTimeSource> test_time_source_; | 90 std::unique_ptr<TestTimeSource> test_time_source_; |
89 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; | 91 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; |
90 scoped_refptr<SchedulerTqmDelegate> main_task_runner_; | 92 scoped_refptr<SchedulerTqmDelegate> main_task_runner_; |
91 std::unique_ptr<TaskQueueManager> manager_; | 93 std::unique_ptr<TaskQueueManager> manager_; |
92 scoped_refptr<TaskQueue> compositor_task_runner_; | 94 scoped_refptr<TaskQueue> compositor_task_runner_; |
93 std::unique_ptr<IdleTimeEstimatorForTest> estimator_; | 95 std::unique_ptr<IdleTimeEstimatorForTest> estimator_; |
94 const base::TimeDelta frame_length_; | 96 const base::TimeDelta frame_length_; |
| 97 TaskTimeTracker task_time_tracker_; |
95 }; | 98 }; |
96 | 99 |
97 TEST_F(IdleTimeEstimatorTest, InitialTimeEstimateWithNoData) { | 100 TEST_F(IdleTimeEstimatorTest, InitialTimeEstimateWithNoData) { |
98 EXPECT_EQ(frame_length_, estimator_->GetExpectedIdleDuration(frame_length_)); | 101 EXPECT_EQ(frame_length_, estimator_->GetExpectedIdleDuration(frame_length_)); |
99 } | 102 } |
100 | 103 |
101 TEST_F(IdleTimeEstimatorTest, BasicEstimation_SteadyState) { | 104 TEST_F(IdleTimeEstimatorTest, BasicEstimation_SteadyState) { |
102 SimulateFrameWithOneCompositorTask(5); | 105 SimulateFrameWithOneCompositorTask(5); |
103 SimulateFrameWithOneCompositorTask(5); | 106 SimulateFrameWithOneCompositorTask(5); |
104 | 107 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 SimulateFrameWithTwoCompositorTasks(4, 4); | 161 SimulateFrameWithTwoCompositorTasks(4, 4); |
159 estimator_->DidCommitFrameToCompositor(); | 162 estimator_->DidCommitFrameToCompositor(); |
160 estimator_->DidProcessTask(task); | 163 estimator_->DidProcessTask(task); |
161 | 164 |
162 EXPECT_EQ(base::TimeDelta::FromMilliseconds(11), | 165 EXPECT_EQ(base::TimeDelta::FromMilliseconds(11), |
163 estimator_->GetExpectedIdleDuration(frame_length_)); | 166 estimator_->GetExpectedIdleDuration(frame_length_)); |
164 } | 167 } |
165 | 168 |
166 | 169 |
167 } // namespace scheduler | 170 } // namespace scheduler |
OLD | NEW |