Chromium Code Reviews| 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/base_switches.h" | 5 #include "base/base_switches.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 // This tries to test the 'best-case' as well as the 'worst-case' task posting | 137 // This tries to test the 'best-case' as well as the 'worst-case' task posting |
| 138 // performance. The best-case keeps one thread alive such that it never yeilds, | 138 // performance. The best-case keeps one thread alive such that it never yeilds, |
| 139 // while the worse-case forces a context switch for every task. Four threads are | 139 // while the worse-case forces a context switch for every task. Four threads are |
| 140 // used to ensure the threads do yeild (with just two it might be possible for | 140 // used to ensure the threads do yeild (with just two it might be possible for |
| 141 // both threads to stay awake if they can signal each other fast enough). | 141 // both threads to stay awake if they can signal each other fast enough). |
| 142 TEST_F(TaskPerfTest, TaskPingPong) { | 142 TEST_F(TaskPerfTest, TaskPingPong) { |
| 143 RunPingPongTest("1_Task_Threads", 1); | 143 RunPingPongTest("1_Task_Threads", 1); |
| 144 RunPingPongTest("4_Task_Threads", 4); | 144 RunPingPongTest("4_Task_Threads", 4); |
| 145 } | 145 } |
| 146 | 146 |
| 147 | |
| 148 // Same as above, but add observers to test their perf impact. | |
| 149 class MessageLoopObserver : public base::MessageLoop::TaskObserver { | |
| 150 public: | |
| 151 virtual void WillProcessTask(const base::PendingTask& pending_task) OVERRIDE { | |
| 152 } | |
| 153 virtual void DidProcessTask(const base::PendingTask& pending_task) OVERRIDE { | |
| 154 } | |
| 155 }; | |
| 156 MessageLoopObserver message_loop_observer; | |
|
Nico
2014/04/24 02:52:20
Does this have to be a global? Can you make this a
epenner
2014/04/24 03:14:36
Good point. I wasn't thinking about it since it's
| |
| 157 | |
| 158 class TaskObserverPerfTest : public TaskPerfTest { | |
| 159 public: | |
| 160 virtual void Init() OVERRIDE { | |
| 161 TaskPerfTest::Init(); | |
| 162 for (size_t i = 0; i < threads_.size(); i++) { | |
| 163 threads_[i]->message_loop()->AddTaskObserver(&message_loop_observer); | |
| 164 } | |
| 165 } | |
| 166 }; | |
| 167 | |
| 168 TEST_F(TaskObserverPerfTest, TaskPingPong) { | |
| 169 RunPingPongTest("1_Task_Threads_With_Observer", 1); | |
| 170 RunPingPongTest("4_Task_Threads_With_Observer", 4); | |
| 171 } | |
| 172 | |
| 147 // Class to test our WaitableEvent performance by signaling back and fort. | 173 // Class to test our WaitableEvent performance by signaling back and fort. |
| 148 // WaitableEvent is templated so we can also compare with other versions. | 174 // WaitableEvent is templated so we can also compare with other versions. |
| 149 template <typename WaitableEventType> | 175 template <typename WaitableEventType> |
| 150 class EventPerfTest : public ThreadPerfTest { | 176 class EventPerfTest : public ThreadPerfTest { |
| 151 public: | 177 public: |
| 152 virtual void Init() OVERRIDE { | 178 virtual void Init() OVERRIDE { |
| 153 for (size_t i = 0; i < threads_.size(); i++) | 179 for (size_t i = 0; i < threads_.size(); i++) |
| 154 events_.push_back(new WaitableEventType(false, false)); | 180 events_.push_back(new WaitableEventType(false, false)); |
| 155 } | 181 } |
| 156 | 182 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 typedef EventPerfTest<PthreadEvent> PthreadEventPerfTest; | 305 typedef EventPerfTest<PthreadEvent> PthreadEventPerfTest; |
| 280 TEST_F(PthreadEventPerfTest, EventPingPong) { | 306 TEST_F(PthreadEventPerfTest, EventPingPong) { |
| 281 RunPingPongTest("4_PthreadCondVar_Threads", 4); | 307 RunPingPongTest("4_PthreadCondVar_Threads", 4); |
| 282 } | 308 } |
| 283 | 309 |
| 284 #endif | 310 #endif |
| 285 | 311 |
| 286 } // namespace | 312 } // namespace |
| 287 | 313 |
| 288 } // namespace base | 314 } // namespace base |
| OLD | NEW |