| 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" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 namespace base { | 22 namespace base { |
| 23 | 23 |
| 24 class ScheduleWorkTest : public testing::Test { | 24 class ScheduleWorkTest : public testing::Test { |
| 25 public: | 25 public: |
| 26 ScheduleWorkTest() : counter_(0) {} | 26 ScheduleWorkTest() : counter_(0) {} |
| 27 | 27 |
| 28 void Increment(uint64_t amount) { counter_ += amount; } | 28 void Increment(uint64_t amount) { counter_ += amount; } |
| 29 | 29 |
| 30 void Schedule(int index) { | 30 void Schedule(int index) { |
| 31 base::TimeTicks start = base::TimeTicks::Now(); | 31 base::TimeTicks start = base::TimeTicks::Now(); |
| 32 base::TimeTicks thread_start; | 32 base::ThreadTicks thread_start; |
| 33 if (TimeTicks::IsThreadNowSupported()) | 33 if (ThreadTicks::IsSupported()) |
| 34 thread_start = base::TimeTicks::ThreadNow(); | 34 thread_start = base::ThreadTicks::Now(); |
| 35 base::TimeDelta minimum = base::TimeDelta::Max(); | 35 base::TimeDelta minimum = base::TimeDelta::Max(); |
| 36 base::TimeDelta maximum = base::TimeDelta(); | 36 base::TimeDelta maximum = base::TimeDelta(); |
| 37 base::TimeTicks now, lastnow = start; | 37 base::TimeTicks now, lastnow = start; |
| 38 uint64_t schedule_calls = 0u; | 38 uint64_t schedule_calls = 0u; |
| 39 do { | 39 do { |
| 40 for (size_t i = 0; i < kBatchSize; ++i) { | 40 for (size_t i = 0; i < kBatchSize; ++i) { |
| 41 target_message_loop()->ScheduleWork(); | 41 target_message_loop()->ScheduleWork(); |
| 42 schedule_calls++; | 42 schedule_calls++; |
| 43 } | 43 } |
| 44 now = base::TimeTicks::Now(); | 44 now = base::TimeTicks::Now(); |
| 45 base::TimeDelta laptime = now - lastnow; | 45 base::TimeDelta laptime = now - lastnow; |
| 46 lastnow = now; | 46 lastnow = now; |
| 47 minimum = std::min(minimum, laptime); | 47 minimum = std::min(minimum, laptime); |
| 48 maximum = std::max(maximum, laptime); | 48 maximum = std::max(maximum, laptime); |
| 49 } while (now - start < base::TimeDelta::FromSeconds(kTargetTimeSec)); | 49 } while (now - start < base::TimeDelta::FromSeconds(kTargetTimeSec)); |
| 50 | 50 |
| 51 scheduling_times_[index] = now - start; | 51 scheduling_times_[index] = now - start; |
| 52 if (TimeTicks::IsThreadNowSupported()) | 52 if (ThreadTicks::IsSupported()) |
| 53 scheduling_thread_times_[index] = | 53 scheduling_thread_times_[index] = |
| 54 base::TimeTicks::ThreadNow() - thread_start; | 54 base::ThreadTicks::Now() - thread_start; |
| 55 min_batch_times_[index] = minimum; | 55 min_batch_times_[index] = minimum; |
| 56 max_batch_times_[index] = maximum; | 56 max_batch_times_[index] = maximum; |
| 57 target_message_loop()->PostTask(FROM_HERE, | 57 target_message_loop()->PostTask(FROM_HERE, |
| 58 base::Bind(&ScheduleWorkTest::Increment, | 58 base::Bind(&ScheduleWorkTest::Increment, |
| 59 base::Unretained(this), | 59 base::Unretained(this), |
| 60 schedule_calls)); | 60 schedule_calls)); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void ScheduleWork(MessageLoop::Type target_type, int num_scheduling_threads) { | 63 void ScheduleWork(MessageLoop::Type target_type, int num_scheduling_threads) { |
| 64 #if defined(OS_ANDROID) | 64 #if defined(OS_ANDROID) |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 min_batch_time.InMicroseconds() / static_cast<double>(kBatchSize), | 132 min_batch_time.InMicroseconds() / static_cast<double>(kBatchSize), |
| 133 "us/task", | 133 "us/task", |
| 134 false); | 134 false); |
| 135 perf_test::PrintResult( | 135 perf_test::PrintResult( |
| 136 "task", | 136 "task", |
| 137 "_max_batch_time", | 137 "_max_batch_time", |
| 138 trace, | 138 trace, |
| 139 max_batch_time.InMicroseconds() / static_cast<double>(kBatchSize), | 139 max_batch_time.InMicroseconds() / static_cast<double>(kBatchSize), |
| 140 "us/task", | 140 "us/task", |
| 141 false); | 141 false); |
| 142 if (TimeTicks::IsThreadNowSupported()) { | 142 if (ThreadTicks::IsSupported()) { |
| 143 perf_test::PrintResult( | 143 perf_test::PrintResult( |
| 144 "task", | 144 "task", |
| 145 "_thread_time", | 145 "_thread_time", |
| 146 trace, | 146 trace, |
| 147 total_thread_time.InMicroseconds() / static_cast<double>(counter_), | 147 total_thread_time.InMicroseconds() / static_cast<double>(counter_), |
| 148 "us/task", | 148 "us/task", |
| 149 true); | 149 true); |
| 150 } | 150 } |
| 151 } | 151 } |
| 152 | 152 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 | 279 |
| 280 TEST_F(PostTaskTest, TenTasksPerReload) { | 280 TEST_F(PostTaskTest, TenTasksPerReload) { |
| 281 Run(10000, 10); | 281 Run(10000, 10); |
| 282 } | 282 } |
| 283 | 283 |
| 284 TEST_F(PostTaskTest, OneHundredTasksPerReload) { | 284 TEST_F(PostTaskTest, OneHundredTasksPerReload) { |
| 285 Run(1000, 100); | 285 Run(1000, 100); |
| 286 } | 286 } |
| 287 | 287 |
| 288 } // namespace base | 288 } // namespace base |
| OLD | NEW |