| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/format_macros.h" | 6 #include "base/format_macros.h" |
| 7 #include "base/memory/scoped_vector.h" | 7 #include "base/memory/scoped_vector.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/synchronization/condition_variable.h" | 9 #include "base/synchronization/condition_variable.h" |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| 11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
| 12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "testing/perf/perf_test.h" | 16 #include "testing/perf/perf_test.h" |
| 17 | 17 |
| 18 #if defined(OS_ANDROID) | 18 #if defined(OS_ANDROID) |
| 19 #include "base/android/java_handler_thread.h" | 19 #include "base/android/java_handler_thread.h" |
| 20 #endif | 20 #endif |
| 21 | 21 |
| 22 namespace base { | 22 namespace base { |
| 23 namespace { | |
| 24 | 23 |
| 25 class ScheduleWorkTest : public testing::Test { | 24 class ScheduleWorkTest : public testing::Test { |
| 26 public: | 25 public: |
| 27 ScheduleWorkTest() : counter_(0) {} | 26 ScheduleWorkTest() : counter_(0) {} |
| 28 | 27 |
| 29 void Increment(uint64_t amount) { counter_ += amount; } | 28 void Increment(uint64_t amount) { counter_ += amount; } |
| 30 | 29 |
| 31 void Schedule(int index) { | 30 void Schedule(int index) { |
| 32 base::TimeTicks start = base::TimeTicks::Now(); | 31 base::TimeTicks start = base::TimeTicks::Now(); |
| 33 base::TimeTicks thread_start; | 32 base::ThreadTicks thread_start; |
| 34 if (TimeTicks::IsThreadNowSupported()) | 33 if (ThreadTicks::IsSupported()) |
| 35 thread_start = base::TimeTicks::ThreadNow(); | 34 thread_start = base::ThreadTicks::Now(); |
| 36 base::TimeDelta minimum = base::TimeDelta::Max(); | 35 base::TimeDelta minimum = base::TimeDelta::Max(); |
| 37 base::TimeDelta maximum = base::TimeDelta(); | 36 base::TimeDelta maximum = base::TimeDelta(); |
| 38 base::TimeTicks now, lastnow = start; | 37 base::TimeTicks now, lastnow = start; |
| 39 uint64_t schedule_calls = 0u; | 38 uint64_t schedule_calls = 0u; |
| 40 do { | 39 do { |
| 41 for (size_t i = 0; i < kBatchSize; ++i) { | 40 for (size_t i = 0; i < kBatchSize; ++i) { |
| 42 target_message_loop()->ScheduleWork(); | 41 target_message_loop()->ScheduleWork(); |
| 43 schedule_calls++; | 42 schedule_calls++; |
| 44 } | 43 } |
| 45 now = base::TimeTicks::Now(); | 44 now = base::TimeTicks::Now(); |
| 46 base::TimeDelta laptime = now - lastnow; | 45 base::TimeDelta laptime = now - lastnow; |
| 47 lastnow = now; | 46 lastnow = now; |
| 48 minimum = std::min(minimum, laptime); | 47 minimum = std::min(minimum, laptime); |
| 49 maximum = std::max(maximum, laptime); | 48 maximum = std::max(maximum, laptime); |
| 50 } while (now - start < base::TimeDelta::FromSeconds(kTargetTimeSec)); | 49 } while (now - start < base::TimeDelta::FromSeconds(kTargetTimeSec)); |
| 51 | 50 |
| 52 scheduling_times_[index] = now - start; | 51 scheduling_times_[index] = now - start; |
| 53 if (TimeTicks::IsThreadNowSupported()) | 52 if (ThreadTicks::IsSupported()) |
| 54 scheduling_thread_times_[index] = | 53 scheduling_thread_times_[index] = |
| 55 base::TimeTicks::ThreadNow() - thread_start; | 54 base::ThreadTicks::Now() - thread_start; |
| 56 min_batch_times_[index] = minimum; | 55 min_batch_times_[index] = minimum; |
| 57 max_batch_times_[index] = maximum; | 56 max_batch_times_[index] = maximum; |
| 58 target_message_loop()->PostTask(FROM_HERE, | 57 target_message_loop()->PostTask(FROM_HERE, |
| 59 base::Bind(&ScheduleWorkTest::Increment, | 58 base::Bind(&ScheduleWorkTest::Increment, |
| 60 base::Unretained(this), | 59 base::Unretained(this), |
| 61 schedule_calls)); | 60 schedule_calls)); |
| 62 } | 61 } |
| 63 | 62 |
| 64 void ScheduleWork(MessageLoop::Type target_type, int num_scheduling_threads) { | 63 void ScheduleWork(MessageLoop::Type target_type, int num_scheduling_threads) { |
| 65 #if defined(OS_ANDROID) | 64 #if defined(OS_ANDROID) |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 min_batch_time.InMicroseconds() / static_cast<double>(kBatchSize), | 132 min_batch_time.InMicroseconds() / static_cast<double>(kBatchSize), |
| 134 "us/task", | 133 "us/task", |
| 135 false); | 134 false); |
| 136 perf_test::PrintResult( | 135 perf_test::PrintResult( |
| 137 "task", | 136 "task", |
| 138 "_max_batch_time", | 137 "_max_batch_time", |
| 139 trace, | 138 trace, |
| 140 max_batch_time.InMicroseconds() / static_cast<double>(kBatchSize), | 139 max_batch_time.InMicroseconds() / static_cast<double>(kBatchSize), |
| 141 "us/task", | 140 "us/task", |
| 142 false); | 141 false); |
| 143 if (TimeTicks::IsThreadNowSupported()) { | 142 if (ThreadTicks::IsSupported()) { |
| 144 perf_test::PrintResult( | 143 perf_test::PrintResult( |
| 145 "task", | 144 "task", |
| 146 "_thread_time", | 145 "_thread_time", |
| 147 trace, | 146 trace, |
| 148 total_thread_time.InMicroseconds() / static_cast<double>(counter_), | 147 total_thread_time.InMicroseconds() / static_cast<double>(counter_), |
| 149 "us/task", | 148 "us/task", |
| 150 true); | 149 true); |
| 151 } | 150 } |
| 152 } | 151 } |
| 153 | 152 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 216 |
| 218 TEST_F(ScheduleWorkTest, ThreadTimeToJavaFromTwoThreads) { | 217 TEST_F(ScheduleWorkTest, ThreadTimeToJavaFromTwoThreads) { |
| 219 ScheduleWork(MessageLoop::TYPE_JAVA, 2); | 218 ScheduleWork(MessageLoop::TYPE_JAVA, 2); |
| 220 } | 219 } |
| 221 | 220 |
| 222 TEST_F(ScheduleWorkTest, ThreadTimeToJavaFromFourThreads) { | 221 TEST_F(ScheduleWorkTest, ThreadTimeToJavaFromFourThreads) { |
| 223 ScheduleWork(MessageLoop::TYPE_JAVA, 4); | 222 ScheduleWork(MessageLoop::TYPE_JAVA, 4); |
| 224 } | 223 } |
| 225 #endif | 224 #endif |
| 226 | 225 |
| 227 static void DoNothing() { | |
| 228 } | |
| 229 | |
| 230 class FakeMessagePump : public MessagePump { | 226 class FakeMessagePump : public MessagePump { |
| 231 public: | 227 public: |
| 232 FakeMessagePump() {} | 228 FakeMessagePump() {} |
| 233 ~FakeMessagePump() override {} | 229 ~FakeMessagePump() override {} |
| 234 | 230 |
| 235 void Run(Delegate* delegate) override {} | 231 void Run(Delegate* delegate) override {} |
| 236 | 232 |
| 237 void Quit() override {} | 233 void Quit() override {} |
| 238 void ScheduleWork() override {} | 234 void ScheduleWork() override {} |
| 239 void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override {} | 235 void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override {} |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 } | 278 } |
| 283 | 279 |
| 284 TEST_F(PostTaskTest, TenTasksPerReload) { | 280 TEST_F(PostTaskTest, TenTasksPerReload) { |
| 285 Run(10000, 10); | 281 Run(10000, 10); |
| 286 } | 282 } |
| 287 | 283 |
| 288 TEST_F(PostTaskTest, OneHundredTasksPerReload) { | 284 TEST_F(PostTaskTest, OneHundredTasksPerReload) { |
| 289 Run(1000, 100); | 285 Run(1000, 100); |
| 290 } | 286 } |
| 291 | 287 |
| 292 } // namespace | |
| 293 } // namespace base | 288 } // namespace base |
| OLD | NEW |