| 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/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
| 11 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 12 #include "base/synchronization/condition_variable.h" | 13 #include "base/synchronization/condition_variable.h" |
| 13 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
| 14 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
| 15 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 17 #include "build/build_config.h" | 18 #include "build/build_config.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" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 target_->StartWithOptions(Thread::Options(target_type, 0u)); | 81 target_->StartWithOptions(Thread::Options(target_type, 0u)); |
| 81 | 82 |
| 82 // Without this, it's possible for the scheduling threads to start and run | 83 // Without this, it's possible for the scheduling threads to start and run |
| 83 // before the target thread. In this case, the scheduling threads will | 84 // before the target thread. In this case, the scheduling threads will |
| 84 // call target_message_loop()->ScheduleWork(), which dereferences the | 85 // call target_message_loop()->ScheduleWork(), which dereferences the |
| 85 // loop's message pump, which is only created after the target thread has | 86 // loop's message pump, which is only created after the target thread has |
| 86 // finished starting. | 87 // finished starting. |
| 87 target_->WaitUntilThreadStarted(); | 88 target_->WaitUntilThreadStarted(); |
| 88 } | 89 } |
| 89 | 90 |
| 90 std::vector<scoped_ptr<Thread>> scheduling_threads; | 91 std::vector<std::unique_ptr<Thread>> scheduling_threads; |
| 91 scheduling_times_.reset(new base::TimeDelta[num_scheduling_threads]); | 92 scheduling_times_.reset(new base::TimeDelta[num_scheduling_threads]); |
| 92 scheduling_thread_times_.reset(new base::TimeDelta[num_scheduling_threads]); | 93 scheduling_thread_times_.reset(new base::TimeDelta[num_scheduling_threads]); |
| 93 min_batch_times_.reset(new base::TimeDelta[num_scheduling_threads]); | 94 min_batch_times_.reset(new base::TimeDelta[num_scheduling_threads]); |
| 94 max_batch_times_.reset(new base::TimeDelta[num_scheduling_threads]); | 95 max_batch_times_.reset(new base::TimeDelta[num_scheduling_threads]); |
| 95 | 96 |
| 96 for (int i = 0; i < num_scheduling_threads; ++i) { | 97 for (int i = 0; i < num_scheduling_threads; ++i) { |
| 97 scheduling_threads.push_back( | 98 scheduling_threads.push_back( |
| 98 make_scoped_ptr(new Thread("posting thread"))); | 99 WrapUnique(new Thread("posting thread"))); |
| 99 scheduling_threads[i]->Start(); | 100 scheduling_threads[i]->Start(); |
| 100 } | 101 } |
| 101 | 102 |
| 102 for (int i = 0; i < num_scheduling_threads; ++i) { | 103 for (int i = 0; i < num_scheduling_threads; ++i) { |
| 103 scheduling_threads[i]->message_loop()->PostTask( | 104 scheduling_threads[i]->message_loop()->PostTask( |
| 104 FROM_HERE, | 105 FROM_HERE, |
| 105 base::Bind(&ScheduleWorkTest::Schedule, base::Unretained(this), i)); | 106 base::Bind(&ScheduleWorkTest::Schedule, base::Unretained(this), i)); |
| 106 } | 107 } |
| 107 | 108 |
| 108 for (int i = 0; i < num_scheduling_threads; ++i) { | 109 for (int i = 0; i < num_scheduling_threads; ++i) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 169 |
| 169 MessageLoop* target_message_loop() { | 170 MessageLoop* target_message_loop() { |
| 170 #if defined(OS_ANDROID) | 171 #if defined(OS_ANDROID) |
| 171 if (java_thread_) | 172 if (java_thread_) |
| 172 return java_thread_->message_loop(); | 173 return java_thread_->message_loop(); |
| 173 #endif | 174 #endif |
| 174 return target_->message_loop(); | 175 return target_->message_loop(); |
| 175 } | 176 } |
| 176 | 177 |
| 177 private: | 178 private: |
| 178 scoped_ptr<Thread> target_; | 179 std::unique_ptr<Thread> target_; |
| 179 #if defined(OS_ANDROID) | 180 #if defined(OS_ANDROID) |
| 180 scoped_ptr<android::JavaHandlerThread> java_thread_; | 181 std::unique_ptr<android::JavaHandlerThread> java_thread_; |
| 181 #endif | 182 #endif |
| 182 scoped_ptr<base::TimeDelta[]> scheduling_times_; | 183 std::unique_ptr<base::TimeDelta[]> scheduling_times_; |
| 183 scoped_ptr<base::TimeDelta[]> scheduling_thread_times_; | 184 std::unique_ptr<base::TimeDelta[]> scheduling_thread_times_; |
| 184 scoped_ptr<base::TimeDelta[]> min_batch_times_; | 185 std::unique_ptr<base::TimeDelta[]> min_batch_times_; |
| 185 scoped_ptr<base::TimeDelta[]> max_batch_times_; | 186 std::unique_ptr<base::TimeDelta[]> max_batch_times_; |
| 186 uint64_t counter_; | 187 uint64_t counter_; |
| 187 | 188 |
| 188 static const size_t kTargetTimeSec = 5; | 189 static const size_t kTargetTimeSec = 5; |
| 189 static const size_t kBatchSize = 1000; | 190 static const size_t kBatchSize = 1000; |
| 190 }; | 191 }; |
| 191 | 192 |
| 192 TEST_F(ScheduleWorkTest, ThreadTimeToIOFromOneThread) { | 193 TEST_F(ScheduleWorkTest, ThreadTimeToIOFromOneThread) { |
| 193 ScheduleWork(MessageLoop::TYPE_IO, 1); | 194 ScheduleWork(MessageLoop::TYPE_IO, 1); |
| 194 } | 195 } |
| 195 | 196 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 void Quit() override {} | 250 void Quit() override {} |
| 250 void ScheduleWork() override {} | 251 void ScheduleWork() override {} |
| 251 void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override {} | 252 void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override {} |
| 252 }; | 253 }; |
| 253 | 254 |
| 254 class PostTaskTest : public testing::Test { | 255 class PostTaskTest : public testing::Test { |
| 255 public: | 256 public: |
| 256 void Run(int batch_size, int tasks_per_reload) { | 257 void Run(int batch_size, int tasks_per_reload) { |
| 257 base::TimeTicks start = base::TimeTicks::Now(); | 258 base::TimeTicks start = base::TimeTicks::Now(); |
| 258 base::TimeTicks now; | 259 base::TimeTicks now; |
| 259 MessageLoop loop(scoped_ptr<MessagePump>(new FakeMessagePump)); | 260 MessageLoop loop(std::unique_ptr<MessagePump>(new FakeMessagePump)); |
| 260 scoped_refptr<internal::IncomingTaskQueue> queue( | 261 scoped_refptr<internal::IncomingTaskQueue> queue( |
| 261 new internal::IncomingTaskQueue(&loop)); | 262 new internal::IncomingTaskQueue(&loop)); |
| 262 uint32_t num_posted = 0; | 263 uint32_t num_posted = 0; |
| 263 do { | 264 do { |
| 264 for (int i = 0; i < batch_size; ++i) { | 265 for (int i = 0; i < batch_size; ++i) { |
| 265 for (int j = 0; j < tasks_per_reload; ++j) { | 266 for (int j = 0; j < tasks_per_reload; ++j) { |
| 266 queue->AddToIncomingQueue( | 267 queue->AddToIncomingQueue( |
| 267 FROM_HERE, base::Bind(&DoNothing), base::TimeDelta(), false); | 268 FROM_HERE, base::Bind(&DoNothing), base::TimeDelta(), false); |
| 268 num_posted++; | 269 num_posted++; |
| 269 } | 270 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 295 | 296 |
| 296 TEST_F(PostTaskTest, TenTasksPerReload) { | 297 TEST_F(PostTaskTest, TenTasksPerReload) { |
| 297 Run(10000, 10); | 298 Run(10000, 10); |
| 298 } | 299 } |
| 299 | 300 |
| 300 TEST_F(PostTaskTest, OneHundredTasksPerReload) { | 301 TEST_F(PostTaskTest, OneHundredTasksPerReload) { |
| 301 Run(1000, 100); | 302 Run(1000, 100); |
| 302 } | 303 } |
| 303 | 304 |
| 304 } // namespace base | 305 } // namespace base |
| OLD | NEW |