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