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

Unified Diff: content/renderer/scheduler/task_queue_manager_perftest.cc

Issue 971393002: Adds a couple of simple micro benchmarks for the TaskQueueManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove header Created 5 years, 10 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
« content/content_tests.gypi ('K') | « content/content_tests.gypi ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/scheduler/task_queue_manager_perftest.cc
diff --git a/content/renderer/scheduler/task_queue_manager_perftest.cc b/content/renderer/scheduler/task_queue_manager_perftest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9af5476c2e850a262282c4477630811bb5c90097
--- /dev/null
+++ b/content/renderer/scheduler/task_queue_manager_perftest.cc
@@ -0,0 +1,142 @@
+
Sami 2015/03/03 18:09:18 Nit: extra blank line.
alex clarke (OOO till 29th) 2015/03/04 11:38:06 Done.
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/renderer/scheduler/task_queue_manager.h"
+
+#include <functional>
Sami 2015/03/03 18:09:18 I'm not sure we can use this yet. Lambdas by thems
alex clarke (OOO till 29th) 2015/03/04 11:38:06 Done.
+#include "base/bind.h"
+#include "base/threading/thread.h"
+#include "content/renderer/scheduler/task_queue_selector.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/perf/perf_test.h"
+
+namespace content {
+
+namespace {
+
+class SelectorForTest : public TaskQueueSelector {
+ public:
+ SelectorForTest() {}
+
+ void RegisterWorkQueues(
+ const std::vector<const base::TaskQueue*>& work_queues) override {
+ work_queues_ = work_queues;
+ }
+
+ bool SelectWorkQueueToService(size_t* out_queue_index) override {
+ // Choose the oldest task, if any.
+ bool found_one = false;
+ for (size_t i = 0; i < work_queues_.size(); i++) {
+ if (work_queues_[i]->empty())
+ continue;
+ // Note: the < comparison is correct due to the fact that the PendingTask
+ // operator inverts its comparison operation in order to work well in a
+ // heap based priority queue.
+ if (!found_one ||
+ work_queues_[*out_queue_index]->front() < work_queues_[i]->front())
+ *out_queue_index = i;
+ found_one = true;
+ }
+ return found_one;
Sami 2015/03/03 18:09:18 nit: This is guaranteed to be true because the sel
alex clarke (OOO till 29th) 2015/03/04 11:38:06 Sure. I put a CHECK in there to hopefully make th
+ }
+
+ void AsValueInto(base::trace_event::TracedValue* state) const override {}
+
+ private:
+ std::vector<const base::TaskQueue*> work_queues_;
+
+ DISALLOW_COPY_AND_ASSIGN(SelectorForTest);
+};
+
+} // namespace
+
+class TaskQueueManagerPerfTest : public testing::Test {
+ protected:
+ void Initialize(size_t num_queues) {
+ num_queues_ = num_queues;
+ message_loop_.reset(new base::MessageLoop());
+ selector_ = make_scoped_ptr(new SelectorForTest);
+ manager_ = make_scoped_ptr(new TaskQueueManager(
+ num_queues, message_loop_->task_runner(), selector_.get()));
+ }
+
+ void Benchmark(const std::string& trace, std::function<void()> fn) {
+ base::TimeTicks start = base::TimeTicks::Now();
+ base::TimeTicks now;
+ unsigned long long num_iterations = 0;
+ do {
+ fn();
+ now = base::TimeTicks::Now();
+ num_iterations++;
+ } while (now - start < base::TimeDelta::FromSeconds(5));
+ perf_test::PrintResult(
+ "task", "", trace,
+ (now - start).InMicroseconds() / static_cast<double>(num_iterations),
+ "us/run", true);
+ }
+
+ void TestTask() {
+ // Post a variable number of tasks.
+ unsigned int num_posts = 1 + sequence_number_ % 8;
+ for (unsigned int i = 0; i < num_posts; i++) {
+ if (++sequence_number_ < 10000) {
+ // Choose a queue weighted towards queue 0.
+ unsigned int queue = sequence_number_ % (num_queues_ + 1);
+ if (queue == num_queues_) {
+ queue = 0;
+ }
+ base::TimeDelta delay(
+ base::TimeDelta::FromMilliseconds(sequence_number_ % 10));
Sami 2015/03/03 18:09:18 I think you said this takes less than a millisecon
alex clarke (OOO till 29th) 2015/03/04 11:38:06 No it takes much longer to complete than that. Pu
Sami 2015/03/04 13:00:08 We're counting tasks posted and not tasks run thou
alex clarke (OOO till 29th) 2015/03/04 16:34:20 I changed it so that it runs all. I don't see muc
+ scoped_refptr<base::SingleThreadTaskRunner> runner =
+ manager_->TaskRunnerForQueue(queue);
+ runner->PostDelayedTask(FROM_HERE,
Sami 2015/03/03 18:09:18 I'm worried this is a little too atypical workload
alex clarke (OOO till 29th) 2015/03/04 11:38:06 50 - 200 delayed tasks are common on heavy pages l
+ base::Bind(&TaskQueueManagerPerfTest::TestTask,
+ base::Unretained(this)),
+ delay);
+ } else {
+ message_loop_->Quit();
+ return;
+ }
+ }
+ }
+
+ size_t num_queues_;
+ unsigned int sequence_number_;
+ scoped_ptr<SelectorForTest> selector_;
+ scoped_ptr<TaskQueueManager> manager_;
+ scoped_ptr<base::MessageLoop> message_loop_;
+};
+
+TEST_F(TaskQueueManagerPerfTest, RunTenThousandDelayedTasks_OneQueue) {
+ Initialize(1u);
+
+ Benchmark("post 10000 delayed tasks", [this]() {
Sami 2015/03/03 18:09:18 Could you pass in the number of task queues as a m
alex clarke (OOO till 29th) 2015/03/04 11:38:06 Done.
+ sequence_number_ = 0;
+ TestTask();
+ message_loop_->Run();
+ });
+}
+
+TEST_F(TaskQueueManagerPerfTest, RunTenThousandDelayedTasks_FourQueues) {
+ Initialize(4u);
+
+ Benchmark("post 10000 delayed tasks", [this]() {
+ sequence_number_ = 0;
+ TestTask();
+ message_loop_->Run();
+ });
+}
+
+TEST_F(TaskQueueManagerPerfTest, RunTenThousandDelayedTasks_EightQueues) {
+ Initialize(8u);
+
+ Benchmark("post 10000 delayed tasks", [this]() {
+ sequence_number_ = 0;
+ TestTask();
+ message_loop_->Run();
+ });
+}
+
+} // namespace content
« content/content_tests.gypi ('K') | « content/content_tests.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698