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 "platform/scheduler/base/task_queue_manager.h" | 5 #include "platform/scheduler/base/task_queue_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 num_tasks_to_post_(0), | 31 num_tasks_to_post_(0), |
32 num_tasks_to_run_(0) {} | 32 num_tasks_to_run_(0) {} |
33 | 33 |
34 void SetUp() override { | 34 void SetUp() override { |
35 if (base::ThreadTicks::IsSupported()) | 35 if (base::ThreadTicks::IsSupported()) |
36 base::ThreadTicks::WaitUntilInitialized(); | 36 base::ThreadTicks::WaitUntilInitialized(); |
37 } | 37 } |
38 | 38 |
39 void Initialize(size_t num_queues) { | 39 void Initialize(size_t num_queues) { |
40 num_queues_ = num_queues; | 40 num_queues_ = num_queues; |
| 41 message_loop_.reset(new base::MessageLoop()); |
| 42 run_loop_.reset(new base::RunLoop()); |
41 manager_ = base::MakeUnique<TaskQueueManager>( | 43 manager_ = base::MakeUnique<TaskQueueManager>( |
42 TaskQueueManagerDelegateForTest::Create( | 44 TaskQueueManagerDelegateForTest::Create( |
43 base::MessageLoop::current()->task_runner(), | 45 message_loop_->task_runner(), |
44 base::WrapUnique(new base::DefaultTickClock())), | 46 base::WrapUnique(new base::DefaultTickClock())), |
45 "fake.category", "fake.category", "fake.category.debug"); | 47 "fake.category", "fake.category", "fake.category.debug"); |
46 manager_->AddTaskTimeObserver(&test_task_time_observer_); | 48 manager_->AddTaskTimeObserver(&test_task_time_observer_); |
47 for (size_t i = 0; i < num_queues; i++) | 49 for (size_t i = 0; i < num_queues; i++) |
48 queues_.push_back(manager_->NewTaskQueue(TaskQueue::Spec("test"))); | 50 queues_.push_back(manager_->NewTaskQueue(TaskQueue::Spec("test"))); |
49 } | 51 } |
50 | 52 |
51 void TestDelayedTask() { | 53 void TestDelayedTask() { |
52 if (--num_tasks_to_run_ == 0) { | 54 if (--num_tasks_to_run_ == 0) { |
53 run_loop_->QuitWhenIdle(); | 55 run_loop_->QuitWhenIdle(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 num_tasks_to_run_ = num_tasks_to_run; | 91 num_tasks_to_run_ = num_tasks_to_run; |
90 TestDelayedTask(); | 92 TestDelayedTask(); |
91 } | 93 } |
92 | 94 |
93 void Benchmark(const std::string& trace, const base::Closure& test_task) { | 95 void Benchmark(const std::string& trace, const base::Closure& test_task) { |
94 base::ThreadTicks start = base::ThreadTicks::Now(); | 96 base::ThreadTicks start = base::ThreadTicks::Now(); |
95 base::ThreadTicks now; | 97 base::ThreadTicks now; |
96 unsigned long long num_iterations = 0; | 98 unsigned long long num_iterations = 0; |
97 do { | 99 do { |
98 test_task.Run(); | 100 test_task.Run(); |
99 run_loop_.reset(new base::RunLoop()); | |
100 run_loop_->Run(); | 101 run_loop_->Run(); |
101 now = base::ThreadTicks::Now(); | 102 now = base::ThreadTicks::Now(); |
102 num_iterations++; | 103 num_iterations++; |
103 } while (now - start < base::TimeDelta::FromSeconds(5)); | 104 } while (now - start < base::TimeDelta::FromSeconds(5)); |
104 perf_test::PrintResult( | 105 perf_test::PrintResult( |
105 "task", "", trace, | 106 "task", "", trace, |
106 (now - start).InMicroseconds() / static_cast<double>(num_iterations), | 107 (now - start).InMicroseconds() / static_cast<double>(num_iterations), |
107 "us/run", true); | 108 "us/run", true); |
108 } | 109 } |
109 | 110 |
110 size_t num_queues_; | 111 size_t num_queues_; |
111 unsigned int max_tasks_in_flight_; | 112 unsigned int max_tasks_in_flight_; |
112 unsigned int num_tasks_in_flight_; | 113 unsigned int num_tasks_in_flight_; |
113 unsigned int num_tasks_to_post_; | 114 unsigned int num_tasks_to_post_; |
114 unsigned int num_tasks_to_run_; | 115 unsigned int num_tasks_to_run_; |
115 std::unique_ptr<TaskQueueManager> manager_; | 116 std::unique_ptr<TaskQueueManager> manager_; |
| 117 std::unique_ptr<base::MessageLoop> message_loop_; |
116 std::unique_ptr<base::RunLoop> run_loop_; | 118 std::unique_ptr<base::RunLoop> run_loop_; |
117 std::vector<scoped_refptr<base::SingleThreadTaskRunner>> queues_; | 119 std::vector<scoped_refptr<base::SingleThreadTaskRunner>> queues_; |
118 // TODO(alexclarke): parameterize so we can measure with and without a | 120 // TODO(alexclarke): parameterize so we can measure with and without a |
119 // TaskTimeObserver. | 121 // TaskTimeObserver. |
120 TestTaskTimeObserver test_task_time_observer_; | 122 TestTaskTimeObserver test_task_time_observer_; |
121 }; | 123 }; |
122 | 124 |
123 TEST_F(TaskQueueManagerPerfTest, RunTenThousandDelayedTasks_OneQueue) { | 125 TEST_F(TaskQueueManagerPerfTest, RunTenThousandDelayedTasks_OneQueue) { |
124 if (!base::ThreadTicks::IsSupported()) | 126 if (!base::ThreadTicks::IsSupported()) |
125 return; | 127 return; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 Benchmark("run 10000 delayed tasks with eight queues", | 164 Benchmark("run 10000 delayed tasks with eight queues", |
163 base::Bind(&TaskQueueManagerPerfTest::ResetAndCallTestDelayedTask, | 165 base::Bind(&TaskQueueManagerPerfTest::ResetAndCallTestDelayedTask, |
164 base::Unretained(this), 10000)); | 166 base::Unretained(this), 10000)); |
165 } | 167 } |
166 | 168 |
167 // TODO(alexclarke): Add additional tests with different mixes of non-delayed vs | 169 // TODO(alexclarke): Add additional tests with different mixes of non-delayed vs |
168 // delayed tasks. | 170 // delayed tasks. |
169 | 171 |
170 } // namespace scheduler | 172 } // namespace scheduler |
171 } // namespace blink | 173 } // namespace blink |
OLD | NEW |