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