Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(857)

Unified Diff: base/threading/thread_perftest.cc

Issue 254423003: base: Test the cost of adding observers on message loops. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/threading/thread_perftest.cc
diff --git a/base/threading/thread_perftest.cc b/base/threading/thread_perftest.cc
index 840a033226f3acb50de5de5f5461b0d226d73d8b..eaeddf9443507f4e73c8688f093628e797254bc9 100644
--- a/base/threading/thread_perftest.cc
+++ b/base/threading/thread_perftest.cc
@@ -144,6 +144,32 @@ TEST_F(TaskPerfTest, TaskPingPong) {
RunPingPongTest("4_Task_Threads", 4);
}
+
+// Same as above, but add observers to test their perf impact.
+class MessageLoopObserver : public base::MessageLoop::TaskObserver {
+ public:
+ virtual void WillProcessTask(const base::PendingTask& pending_task) OVERRIDE {
+ }
+ virtual void DidProcessTask(const base::PendingTask& pending_task) OVERRIDE {
+ }
+};
+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
+
+class TaskObserverPerfTest : public TaskPerfTest {
+ public:
+ virtual void Init() OVERRIDE {
+ TaskPerfTest::Init();
+ for (size_t i = 0; i < threads_.size(); i++) {
+ threads_[i]->message_loop()->AddTaskObserver(&message_loop_observer);
+ }
+ }
+};
+
+TEST_F(TaskObserverPerfTest, TaskPingPong) {
+ RunPingPongTest("1_Task_Threads_With_Observer", 1);
+ RunPingPongTest("4_Task_Threads_With_Observer", 4);
+}
+
// Class to test our WaitableEvent performance by signaling back and fort.
// WaitableEvent is templated so we can also compare with other versions.
template <typename WaitableEventType>
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698