OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 maximum = std::max(maximum, laptime); | 58 maximum = std::max(maximum, laptime); |
59 } while (now - start < base::TimeDelta::FromSeconds(kTargetTimeSec)); | 59 } while (now - start < base::TimeDelta::FromSeconds(kTargetTimeSec)); |
60 | 60 |
61 scheduling_times_[index] = now - start; | 61 scheduling_times_[index] = now - start; |
62 if (ThreadTicks::IsSupported()) | 62 if (ThreadTicks::IsSupported()) |
63 scheduling_thread_times_[index] = | 63 scheduling_thread_times_[index] = |
64 base::ThreadTicks::Now() - thread_start; | 64 base::ThreadTicks::Now() - thread_start; |
65 min_batch_times_[index] = minimum; | 65 min_batch_times_[index] = minimum; |
66 max_batch_times_[index] = maximum; | 66 max_batch_times_[index] = maximum; |
67 target_message_loop()->task_runner()->PostTask( | 67 target_message_loop()->task_runner()->PostTask( |
68 FROM_HERE, base::Bind(&ScheduleWorkTest::Increment, | 68 FROM_HERE, base::BindOnce(&ScheduleWorkTest::Increment, |
69 base::Unretained(this), schedule_calls)); | 69 base::Unretained(this), schedule_calls)); |
70 } | 70 } |
71 | 71 |
72 void ScheduleWork(MessageLoop::Type target_type, int num_scheduling_threads) { | 72 void ScheduleWork(MessageLoop::Type target_type, int num_scheduling_threads) { |
73 #if defined(OS_ANDROID) | 73 #if defined(OS_ANDROID) |
74 if (target_type == MessageLoop::TYPE_JAVA) { | 74 if (target_type == MessageLoop::TYPE_JAVA) { |
75 java_thread_.reset(new android::JavaHandlerThread("target")); | 75 java_thread_.reset(new android::JavaHandlerThread("target")); |
76 java_thread_->Start(); | 76 java_thread_->Start(); |
77 } else | 77 } else |
78 #endif | 78 #endif |
79 { | 79 { |
(...skipping 14 matching lines...) Expand all Loading... |
94 min_batch_times_.reset(new base::TimeDelta[num_scheduling_threads]); | 94 min_batch_times_.reset(new base::TimeDelta[num_scheduling_threads]); |
95 max_batch_times_.reset(new base::TimeDelta[num_scheduling_threads]); | 95 max_batch_times_.reset(new base::TimeDelta[num_scheduling_threads]); |
96 | 96 |
97 for (int i = 0; i < num_scheduling_threads; ++i) { | 97 for (int i = 0; i < num_scheduling_threads; ++i) { |
98 scheduling_threads.push_back(MakeUnique<Thread>("posting thread")); | 98 scheduling_threads.push_back(MakeUnique<Thread>("posting thread")); |
99 scheduling_threads[i]->Start(); | 99 scheduling_threads[i]->Start(); |
100 } | 100 } |
101 | 101 |
102 for (int i = 0; i < num_scheduling_threads; ++i) { | 102 for (int i = 0; i < num_scheduling_threads; ++i) { |
103 scheduling_threads[i]->task_runner()->PostTask( | 103 scheduling_threads[i]->task_runner()->PostTask( |
104 FROM_HERE, | 104 FROM_HERE, base::BindOnce(&ScheduleWorkTest::Schedule, |
105 base::Bind(&ScheduleWorkTest::Schedule, base::Unretained(this), i)); | 105 base::Unretained(this), i)); |
106 } | 106 } |
107 | 107 |
108 for (int i = 0; i < num_scheduling_threads; ++i) { | 108 for (int i = 0; i < num_scheduling_threads; ++i) { |
109 scheduling_threads[i]->Stop(); | 109 scheduling_threads[i]->Stop(); |
110 } | 110 } |
111 #if defined(OS_ANDROID) | 111 #if defined(OS_ANDROID) |
112 if (target_type == MessageLoop::TYPE_JAVA) { | 112 if (target_type == MessageLoop::TYPE_JAVA) { |
113 java_thread_->Stop(); | 113 java_thread_->Stop(); |
114 java_thread_.reset(); | 114 java_thread_.reset(); |
115 } else | 115 } else |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 void Run(int batch_size, int tasks_per_reload) { | 256 void Run(int batch_size, int tasks_per_reload) { |
257 base::TimeTicks start = base::TimeTicks::Now(); | 257 base::TimeTicks start = base::TimeTicks::Now(); |
258 base::TimeTicks now; | 258 base::TimeTicks now; |
259 MessageLoop loop(std::unique_ptr<MessagePump>(new FakeMessagePump)); | 259 MessageLoop loop(std::unique_ptr<MessagePump>(new FakeMessagePump)); |
260 scoped_refptr<internal::IncomingTaskQueue> queue( | 260 scoped_refptr<internal::IncomingTaskQueue> queue( |
261 new internal::IncomingTaskQueue(&loop)); | 261 new internal::IncomingTaskQueue(&loop)); |
262 uint32_t num_posted = 0; | 262 uint32_t num_posted = 0; |
263 do { | 263 do { |
264 for (int i = 0; i < batch_size; ++i) { | 264 for (int i = 0; i < batch_size; ++i) { |
265 for (int j = 0; j < tasks_per_reload; ++j) { | 265 for (int j = 0; j < tasks_per_reload; ++j) { |
266 queue->AddToIncomingQueue( | 266 queue->AddToIncomingQueue(FROM_HERE, base::BindOnce(&DoNothing), |
267 FROM_HERE, base::Bind(&DoNothing), base::TimeDelta(), false); | 267 base::TimeDelta(), false); |
268 num_posted++; | 268 num_posted++; |
269 } | 269 } |
270 TaskQueue loop_local_queue; | 270 TaskQueue loop_local_queue; |
271 queue->ReloadWorkQueue(&loop_local_queue); | 271 queue->ReloadWorkQueue(&loop_local_queue); |
272 while (!loop_local_queue.empty()) { | 272 while (!loop_local_queue.empty()) { |
273 PendingTask t = std::move(loop_local_queue.front()); | 273 PendingTask t = std::move(loop_local_queue.front()); |
274 loop_local_queue.pop(); | 274 loop_local_queue.pop(); |
275 loop.RunTask(&t); | 275 loop.RunTask(&t); |
276 } | 276 } |
277 } | 277 } |
(...skipping 17 matching lines...) Expand all Loading... |
295 | 295 |
296 TEST_F(PostTaskTest, TenTasksPerReload) { | 296 TEST_F(PostTaskTest, TenTasksPerReload) { |
297 Run(10000, 10); | 297 Run(10000, 10); |
298 } | 298 } |
299 | 299 |
300 TEST_F(PostTaskTest, OneHundredTasksPerReload) { | 300 TEST_F(PostTaskTest, OneHundredTasksPerReload) { |
301 Run(1000, 100); | 301 Run(1000, 100); |
302 } | 302 } |
303 | 303 |
304 } // namespace base | 304 } // namespace base |
OLD | NEW |