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

Side by Side Diff: components/scheduler/base/task_queue_manager_perftest.cc

Issue 2132593002: Remove remaining calls to deprecated MessageLoop methods on Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: h264_vt_encoder_unittest.cc Created 4 years, 5 months 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 unified diff | Download patch
OLDNEW
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/base/task_queue_manager.h" 5 #include "components/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"
11 #include "base/run_loop.h"
11 #include "base/threading/thread.h" 12 #include "base/threading/thread.h"
12 #include "base/time/default_tick_clock.h" 13 #include "base/time/default_tick_clock.h"
13 #include "components/scheduler/base/task_queue_impl.h" 14 #include "components/scheduler/base/task_queue_impl.h"
14 #include "components/scheduler/base/task_queue_manager_delegate_for_test.h" 15 #include "components/scheduler/base/task_queue_manager_delegate_for_test.h"
15 #include "components/scheduler/base/task_queue_selector.h" 16 #include "components/scheduler/base/task_queue_selector.h"
16 #include "components/scheduler/base/test_task_time_tracker.h" 17 #include "components/scheduler/base/test_task_time_tracker.h"
17 #include "components/scheduler/base/work_queue_sets.h" 18 #include "components/scheduler/base/work_queue_sets.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 #include "testing/perf/perf_test.h" 20 #include "testing/perf/perf_test.h"
20 21
21 namespace scheduler { 22 namespace scheduler {
22 23
23 class TaskQueueManagerPerfTest : public testing::Test { 24 class TaskQueueManagerPerfTest : public testing::Test {
24 public: 25 public:
25 TaskQueueManagerPerfTest() 26 TaskQueueManagerPerfTest()
26 : num_queues_(0), 27 : num_queues_(0),
27 max_tasks_in_flight_(0), 28 max_tasks_in_flight_(0),
28 num_tasks_in_flight_(0), 29 num_tasks_in_flight_(0),
29 num_tasks_to_post_(0), 30 num_tasks_to_post_(0),
30 num_tasks_to_run_(0) {} 31 num_tasks_to_run_(0) {}
31 32
32 void SetUp() override { 33 void SetUp() override {
33 if (base::ThreadTicks::IsSupported()) 34 if (base::ThreadTicks::IsSupported())
34 base::ThreadTicks::WaitUntilInitialized(); 35 base::ThreadTicks::WaitUntilInitialized();
35 } 36 }
36 37
37 void Initialize(size_t num_queues) { 38 void Initialize(size_t num_queues) {
38 num_queues_ = num_queues; 39 num_queues_ = num_queues;
39 message_loop_.reset(new base::MessageLoop()); 40 message_loop_.reset(new base::MessageLoop());
41 run_loop_.reset(new base::RunLoop());
40 manager_ = base::WrapUnique(new TaskQueueManager( 42 manager_ = base::WrapUnique(new TaskQueueManager(
41 TaskQueueManagerDelegateForTest::Create( 43 TaskQueueManagerDelegateForTest::Create(
42 message_loop_->task_runner(), 44 message_loop_->task_runner(),
43 base::WrapUnique(new base::DefaultTickClock())), 45 base::WrapUnique(new base::DefaultTickClock())),
44 "fake.category", "fake.category", "fake.category.debug")); 46 "fake.category", "fake.category", "fake.category.debug"));
45 manager_->SetTaskTimeTracker(&test_task_time_tracker_); 47 manager_->SetTaskTimeTracker(&test_task_time_tracker_);
46 for (size_t i = 0; i < num_queues; i++) 48 for (size_t i = 0; i < num_queues; i++)
47 queues_.push_back(manager_->NewTaskQueue(TaskQueue::Spec("test"))); 49 queues_.push_back(manager_->NewTaskQueue(TaskQueue::Spec("test")));
48 } 50 }
49 51
50 void TestDelayedTask() { 52 void TestDelayedTask() {
51 if (--num_tasks_to_run_ == 0) { 53 if (--num_tasks_to_run_ == 0) {
52 message_loop_->QuitWhenIdle(); 54 run_loop_->QuitWhenIdle();
53 } 55 }
54 56
55 num_tasks_in_flight_--; 57 num_tasks_in_flight_--;
56 // NOTE there are only up to max_tasks_in_flight_ pending delayed tasks at 58 // NOTE there are only up to max_tasks_in_flight_ pending delayed tasks at
57 // any one time. Thanks to the lower_num_tasks_to_post going to zero if 59 // any one time. Thanks to the lower_num_tasks_to_post going to zero if
58 // there are a lot of tasks in flight, the total number of task in flight at 60 // there are a lot of tasks in flight, the total number of task in flight at
59 // any one time is very variable. 61 // any one time is very variable.
60 unsigned int lower_num_tasks_to_post = 62 unsigned int lower_num_tasks_to_post =
61 num_tasks_in_flight_ < (max_tasks_in_flight_ / 2) ? 1 : 0; 63 num_tasks_in_flight_ < (max_tasks_in_flight_ / 2) ? 1 : 0;
62 unsigned int max_tasks_to_post = 64 unsigned int max_tasks_to_post =
(...skipping 25 matching lines...) Expand all
88 num_tasks_to_run_ = num_tasks_to_run; 90 num_tasks_to_run_ = num_tasks_to_run;
89 TestDelayedTask(); 91 TestDelayedTask();
90 } 92 }
91 93
92 void Benchmark(const std::string& trace, const base::Closure& test_task) { 94 void Benchmark(const std::string& trace, const base::Closure& test_task) {
93 base::ThreadTicks start = base::ThreadTicks::Now(); 95 base::ThreadTicks start = base::ThreadTicks::Now();
94 base::ThreadTicks now; 96 base::ThreadTicks now;
95 unsigned long long num_iterations = 0; 97 unsigned long long num_iterations = 0;
96 do { 98 do {
97 test_task.Run(); 99 test_task.Run();
98 message_loop_->Run(); 100 run_loop_->Run();
99 now = base::ThreadTicks::Now(); 101 now = base::ThreadTicks::Now();
100 num_iterations++; 102 num_iterations++;
101 } while (now - start < base::TimeDelta::FromSeconds(5)); 103 } while (now - start < base::TimeDelta::FromSeconds(5));
102 perf_test::PrintResult( 104 perf_test::PrintResult(
103 "task", "", trace, 105 "task", "", trace,
104 (now - start).InMicroseconds() / static_cast<double>(num_iterations), 106 (now - start).InMicroseconds() / static_cast<double>(num_iterations),
105 "us/run", true); 107 "us/run", true);
106 } 108 }
107 109
108 size_t num_queues_; 110 size_t num_queues_;
109 unsigned int max_tasks_in_flight_; 111 unsigned int max_tasks_in_flight_;
110 unsigned int num_tasks_in_flight_; 112 unsigned int num_tasks_in_flight_;
111 unsigned int num_tasks_to_post_; 113 unsigned int num_tasks_to_post_;
112 unsigned int num_tasks_to_run_; 114 unsigned int num_tasks_to_run_;
113 std::unique_ptr<TaskQueueManager> manager_; 115 std::unique_ptr<TaskQueueManager> manager_;
114 std::unique_ptr<base::MessageLoop> message_loop_; 116 std::unique_ptr<base::MessageLoop> message_loop_;
117 std::unique_ptr<base::RunLoop> run_loop_;
115 std::vector<scoped_refptr<base::SingleThreadTaskRunner>> queues_; 118 std::vector<scoped_refptr<base::SingleThreadTaskRunner>> queues_;
116 // TODO(alexclarke): parameterize so we can measure with and without a 119 // TODO(alexclarke): parameterize so we can measure with and without a
117 // TaskTimeTracker. 120 // TaskTimeTracker.
118 TestTaskTimeTracker test_task_time_tracker_; 121 TestTaskTimeTracker test_task_time_tracker_;
119 }; 122 };
120 123
121 TEST_F(TaskQueueManagerPerfTest, RunTenThousandDelayedTasks_OneQueue) { 124 TEST_F(TaskQueueManagerPerfTest, RunTenThousandDelayedTasks_OneQueue) {
122 if (!base::ThreadTicks::IsSupported()) 125 if (!base::ThreadTicks::IsSupported())
123 return; 126 return;
124 Initialize(1u); 127 Initialize(1u);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 max_tasks_in_flight_ = 200; 162 max_tasks_in_flight_ = 200;
160 Benchmark("run 10000 delayed tasks with eight queues", 163 Benchmark("run 10000 delayed tasks with eight queues",
161 base::Bind(&TaskQueueManagerPerfTest::ResetAndCallTestDelayedTask, 164 base::Bind(&TaskQueueManagerPerfTest::ResetAndCallTestDelayedTask,
162 base::Unretained(this), 10000)); 165 base::Unretained(this), 10000));
163 } 166 }
164 167
165 // TODO(alexclarke): Add additional tests with different mixes of non-delayed vs 168 // TODO(alexclarke): Add additional tests with different mixes of non-delayed vs
166 // delayed tasks. 169 // delayed tasks.
167 170
168 } // namespace scheduler 171 } // namespace scheduler
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698