| 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" |
| 11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
| 12 #include "base/single_thread_task_runner.h" |
| 12 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 13 #include "base/synchronization/condition_variable.h" | 14 #include "base/synchronization/condition_variable.h" |
| 14 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
| 15 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
| 16 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
| 17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "testing/perf/perf_test.h" | 21 #include "testing/perf/perf_test.h" |
| 21 | 22 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 minimum = std::min(minimum, laptime); | 57 minimum = std::min(minimum, laptime); |
| 57 maximum = std::max(maximum, laptime); | 58 maximum = std::max(maximum, laptime); |
| 58 } while (now - start < base::TimeDelta::FromSeconds(kTargetTimeSec)); | 59 } while (now - start < base::TimeDelta::FromSeconds(kTargetTimeSec)); |
| 59 | 60 |
| 60 scheduling_times_[index] = now - start; | 61 scheduling_times_[index] = now - start; |
| 61 if (ThreadTicks::IsSupported()) | 62 if (ThreadTicks::IsSupported()) |
| 62 scheduling_thread_times_[index] = | 63 scheduling_thread_times_[index] = |
| 63 base::ThreadTicks::Now() - thread_start; | 64 base::ThreadTicks::Now() - thread_start; |
| 64 min_batch_times_[index] = minimum; | 65 min_batch_times_[index] = minimum; |
| 65 max_batch_times_[index] = maximum; | 66 max_batch_times_[index] = maximum; |
| 66 target_message_loop()->PostTask(FROM_HERE, | 67 target_message_loop()->task_runner()->PostTask( |
| 67 base::Bind(&ScheduleWorkTest::Increment, | 68 FROM_HERE, base::Bind(&ScheduleWorkTest::Increment, |
| 68 base::Unretained(this), | 69 base::Unretained(this), schedule_calls)); |
| 69 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( | 98 scheduling_threads.push_back( |
| 99 WrapUnique(new Thread("posting thread"))); | 99 WrapUnique(new Thread("posting thread"))); |
| 100 scheduling_threads[i]->Start(); | 100 scheduling_threads[i]->Start(); |
| 101 } | 101 } |
| 102 | 102 |
| 103 for (int i = 0; i < num_scheduling_threads; ++i) { | 103 for (int i = 0; i < num_scheduling_threads; ++i) { |
| 104 scheduling_threads[i]->message_loop()->PostTask( | 104 scheduling_threads[i]->message_loop()->task_runner()->PostTask( |
| 105 FROM_HERE, | 105 FROM_HERE, |
| 106 base::Bind(&ScheduleWorkTest::Schedule, base::Unretained(this), i)); | 106 base::Bind(&ScheduleWorkTest::Schedule, base::Unretained(this), i)); |
| 107 } | 107 } |
| 108 | 108 |
| 109 for (int i = 0; i < num_scheduling_threads; ++i) { | 109 for (int i = 0; i < num_scheduling_threads; ++i) { |
| 110 scheduling_threads[i]->Stop(); | 110 scheduling_threads[i]->Stop(); |
| 111 } | 111 } |
| 112 #if defined(OS_ANDROID) | 112 #if defined(OS_ANDROID) |
| 113 if (target_type == MessageLoop::TYPE_JAVA) { | 113 if (target_type == MessageLoop::TYPE_JAVA) { |
| 114 java_thread_->Stop(); | 114 java_thread_->Stop(); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 | 296 |
| 297 TEST_F(PostTaskTest, TenTasksPerReload) { | 297 TEST_F(PostTaskTest, TenTasksPerReload) { |
| 298 Run(10000, 10); | 298 Run(10000, 10); |
| 299 } | 299 } |
| 300 | 300 |
| 301 TEST_F(PostTaskTest, OneHundredTasksPerReload) { | 301 TEST_F(PostTaskTest, OneHundredTasksPerReload) { |
| 302 Run(1000, 100); | 302 Run(1000, 100); |
| 303 } | 303 } |
| 304 | 304 |
| 305 } // namespace base | 305 } // namespace base |
| OLD | NEW |