| Index: cc/resources/task_graph_runner_perftest.cc
|
| diff --git a/cc/resources/worker_pool_perftest.cc b/cc/resources/task_graph_runner_perftest.cc
|
| similarity index 61%
|
| rename from cc/resources/worker_pool_perftest.cc
|
| rename to cc/resources/task_graph_runner_perftest.cc
|
| index 108586964b9d5bd75a0c6b72b4eefbc5000983af..d296fe74480701aecac24c2be3542b9f50975dfa 100644
|
| --- a/cc/resources/worker_pool_perftest.cc
|
| +++ b/cc/resources/task_graph_runner_perftest.cc
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "cc/resources/worker_pool.h"
|
| +#include "cc/resources/task_graph_runner.h"
|
|
|
| #include "base/time/time.h"
|
| #include "cc/base/completion_event.h"
|
| @@ -11,67 +11,122 @@
|
| #include "testing/perf/perf_test.h"
|
|
|
| namespace cc {
|
| -
|
| namespace {
|
|
|
| static const int kTimeLimitMillis = 2000;
|
| static const int kWarmupRuns = 5;
|
| static const int kTimeCheckInterval = 10;
|
|
|
| -class PerfWorkerPoolTaskImpl : public internal::WorkerPoolTask {
|
| +class PerfTaskImpl : public internal::Task {
|
| public:
|
| - // Overridden from internal::WorkerPoolTask:
|
| + PerfTaskImpl() {}
|
| +
|
| + // Overridden from internal::Task:
|
| virtual void RunOnWorkerThread(unsigned thread_index) OVERRIDE {}
|
| - virtual void CompleteOnOriginThread() OVERRIDE {}
|
|
|
| private:
|
| - virtual ~PerfWorkerPoolTaskImpl() {}
|
| + virtual ~PerfTaskImpl() {}
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(PerfTaskImpl);
|
| };
|
|
|
| -class PerfControlWorkerPoolTaskImpl : public internal::WorkerPoolTask {
|
| +class PerfControlTaskImpl : public internal::Task {
|
| public:
|
| - PerfControlWorkerPoolTaskImpl() : did_start_(new CompletionEvent),
|
| - can_finish_(new CompletionEvent) {}
|
| + PerfControlTaskImpl() {}
|
|
|
| - // Overridden from internal::WorkerPoolTask:
|
| + // Overridden from internal::Task:
|
| virtual void RunOnWorkerThread(unsigned thread_index) OVERRIDE {
|
| - did_start_->Signal();
|
| - can_finish_->Wait();
|
| + did_start_.Signal();
|
| + can_finish_.Wait();
|
| }
|
| - virtual void CompleteOnOriginThread() OVERRIDE {}
|
|
|
| void WaitForTaskToStartRunning() {
|
| - did_start_->Wait();
|
| + did_start_.Wait();
|
| }
|
|
|
| void AllowTaskToFinish() {
|
| - can_finish_->Signal();
|
| + can_finish_.Signal();
|
| }
|
|
|
| private:
|
| - virtual ~PerfControlWorkerPoolTaskImpl() {}
|
| + virtual ~PerfControlTaskImpl() {}
|
|
|
| - scoped_ptr<CompletionEvent> did_start_;
|
| - scoped_ptr<CompletionEvent> can_finish_;
|
| + CompletionEvent did_start_;
|
| + CompletionEvent can_finish_;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(PerfControlWorkerPoolTaskImpl);
|
| + DISALLOW_COPY_AND_ASSIGN(PerfControlTaskImpl);
|
| };
|
|
|
| -class PerfWorkerPool : public WorkerPool {
|
| +class TaskGraphRunnerPerfTest : public testing::Test {
|
| public:
|
| - PerfWorkerPool() : WorkerPool() {}
|
| - virtual ~PerfWorkerPool() {}
|
| + TaskGraphRunnerPerfTest()
|
| + : timer_(kWarmupRuns,
|
| + base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
|
| + kTimeCheckInterval) {
|
| + }
|
|
|
| - static scoped_ptr<PerfWorkerPool> Create() {
|
| - return make_scoped_ptr(new PerfWorkerPool);
|
| + // Overridden from testing::Test:
|
| + virtual void SetUp() OVERRIDE {
|
| + task_graph_runner_ = make_scoped_ptr(
|
| + new internal::TaskGraphRunner(1, "PerfTest"));
|
| + namespace_token_ = task_graph_runner_->GetNamespaceToken();
|
| + }
|
| + virtual void TearDown() OVERRIDE {
|
| + task_graph_runner_.reset();
|
| }
|
|
|
| - void ScheduleTasks(internal::WorkerPoolTask* root_task,
|
| - internal::WorkerPoolTask* leaf_task,
|
| + void AfterTest(const std::string& test_name) {
|
| + // Format matches chrome/test/perf/perf_test.h:PrintResult
|
| + printf("*RESULT %s: %.2f runs/s\n",
|
| + test_name.c_str(),
|
| + timer_.LapsPerSecond());
|
| + }
|
| +
|
| + void RunScheduleTasksTest(const std::string& test_name,
|
| + unsigned max_depth,
|
| + unsigned num_children_per_node) {
|
| + timer_.Reset();
|
| + do {
|
| + scoped_refptr<PerfControlTaskImpl> leaf_task(new PerfControlTaskImpl);
|
| + ScheduleTasks(NULL, leaf_task.get(), max_depth, num_children_per_node);
|
| + leaf_task->WaitForTaskToStartRunning();
|
| + ScheduleTasks(NULL, NULL, 0, 0);
|
| + leaf_task->AllowTaskToFinish();
|
| + task_graph_runner_->WaitForTasksToFinishRunning(namespace_token_);
|
| + internal::Task::Vector completed_tasks;
|
| + task_graph_runner_->CollectCompletedTasks(
|
| + namespace_token_, &completed_tasks);
|
| + timer_.NextLap();
|
| + } while (!timer_.HasTimeLimitExpired());
|
| +
|
| + perf_test::PrintResult("schedule_tasks", "", test_name,
|
| + timer_.LapsPerSecond(), "runs/s", true);
|
| + }
|
| +
|
| + void RunExecuteTasksTest(const std::string& test_name,
|
| + unsigned max_depth,
|
| + unsigned num_children_per_node) {
|
| + timer_.Reset();
|
| + do {
|
| + ScheduleTasks(NULL, NULL, max_depth, num_children_per_node);
|
| + task_graph_runner_->WaitForTasksToFinishRunning(namespace_token_);
|
| + internal::Task::Vector completed_tasks;
|
| + task_graph_runner_->CollectCompletedTasks(
|
| + namespace_token_, &completed_tasks);
|
| + timer_.NextLap();
|
| + } while (!timer_.HasTimeLimitExpired());
|
| +
|
| + perf_test::PrintResult("execute_tasks", "", test_name,
|
| + timer_.LapsPerSecond(), "runs/s", true);
|
| + }
|
| +
|
| + private:
|
| + void ScheduleTasks(internal::Task* root_task,
|
| + internal::Task* leaf_task,
|
| unsigned max_depth,
|
| unsigned num_children_per_node) {
|
| - TaskVector tasks;
|
| - TaskGraph graph;
|
| + internal::Task::Vector tasks;
|
| + internal::GraphNode::Map graph;
|
|
|
| scoped_ptr<internal::GraphNode> root_node;
|
| if (root_task)
|
| @@ -97,26 +152,19 @@ class PerfWorkerPool : public WorkerPool {
|
| if (root_node)
|
| graph.set(root_task, root_node.Pass());
|
|
|
| - SetTaskGraph(&graph);
|
| + task_graph_runner_->SetTaskGraph(namespace_token_, &graph);
|
|
|
| tasks_.swap(tasks);
|
| }
|
|
|
| - void CheckForCompletedTasks() {
|
| - CheckForCompletedWorkerTasks();
|
| - }
|
| -
|
| - private:
|
| - typedef std::vector<scoped_refptr<internal::WorkerPoolTask> > TaskVector;
|
| -
|
| - void BuildTaskGraph(TaskVector* tasks,
|
| - TaskGraph* graph,
|
| + void BuildTaskGraph(internal::Task::Vector* tasks,
|
| + internal::GraphNode::Map* graph,
|
| internal::GraphNode* dependent_node,
|
| internal::GraphNode* leaf_node,
|
| unsigned current_depth,
|
| unsigned max_depth,
|
| unsigned num_children_per_node) {
|
| - scoped_refptr<PerfWorkerPoolTaskImpl> task(new PerfWorkerPoolTaskImpl);
|
| + scoped_refptr<PerfTaskImpl> task(new PerfTaskImpl);
|
| scoped_ptr<internal::GraphNode> node(
|
| new internal::GraphNode(task.get(), 0u));
|
|
|
| @@ -143,78 +191,13 @@ class PerfWorkerPool : public WorkerPool {
|
| tasks->push_back(task.get());
|
| }
|
|
|
| - TaskVector tasks_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(PerfWorkerPool);
|
| -};
|
| -
|
| -class WorkerPoolPerfTest : public testing::Test {
|
| - public:
|
| - WorkerPoolPerfTest()
|
| - : timer_(kWarmupRuns,
|
| - base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
|
| - kTimeCheckInterval) {}
|
| -
|
| - // Overridden from testing::Test:
|
| - virtual void SetUp() OVERRIDE {
|
| - worker_pool_ = PerfWorkerPool::Create();
|
| - }
|
| - virtual void TearDown() OVERRIDE {
|
| - worker_pool_->Shutdown();
|
| - worker_pool_->CheckForCompletedTasks();
|
| - }
|
| -
|
| - void AfterTest(const std::string& test_name) {
|
| - // Format matches chrome/test/perf/perf_test.h:PrintResult
|
| - printf(
|
| - "*RESULT %s: %.2f runs/s\n", test_name.c_str(), timer_.LapsPerSecond());
|
| - }
|
| -
|
| - void RunScheduleTasksTest(const std::string& test_name,
|
| - unsigned max_depth,
|
| - unsigned num_children_per_node) {
|
| - timer_.Reset();
|
| - do {
|
| - scoped_refptr<PerfControlWorkerPoolTaskImpl> leaf_task(
|
| - new PerfControlWorkerPoolTaskImpl);
|
| - worker_pool_->ScheduleTasks(
|
| - NULL, leaf_task.get(), max_depth, num_children_per_node);
|
| - leaf_task->WaitForTaskToStartRunning();
|
| - worker_pool_->ScheduleTasks(NULL, NULL, 0, 0);
|
| - worker_pool_->CheckForCompletedTasks();
|
| - leaf_task->AllowTaskToFinish();
|
| - timer_.NextLap();
|
| - } while (!timer_.HasTimeLimitExpired());
|
| -
|
| - perf_test::PrintResult("schedule_tasks", "", test_name,
|
| - timer_.LapsPerSecond(), "runs/s", true);
|
| - }
|
| -
|
| - void RunExecuteTasksTest(const std::string& test_name,
|
| - unsigned max_depth,
|
| - unsigned num_children_per_node) {
|
| - timer_.Reset();
|
| - do {
|
| - scoped_refptr<PerfControlWorkerPoolTaskImpl> root_task(
|
| - new PerfControlWorkerPoolTaskImpl);
|
| - worker_pool_->ScheduleTasks(
|
| - root_task.get(), NULL, max_depth, num_children_per_node);
|
| - root_task->WaitForTaskToStartRunning();
|
| - root_task->AllowTaskToFinish();
|
| - worker_pool_->CheckForCompletedTasks();
|
| - timer_.NextLap();
|
| - } while (!timer_.HasTimeLimitExpired());
|
| -
|
| - perf_test::PrintResult("execute_tasks", "", test_name,
|
| - timer_.LapsPerSecond(), "runs/s", true);
|
| - }
|
| -
|
| - protected:
|
| - scoped_ptr<PerfWorkerPool> worker_pool_;
|
| + scoped_ptr<internal::TaskGraphRunner> task_graph_runner_;
|
| + internal::NamespaceToken namespace_token_;
|
| + internal::Task::Vector tasks_;
|
| LapTimer timer_;
|
| };
|
|
|
| -TEST_F(WorkerPoolPerfTest, ScheduleTasks) {
|
| +TEST_F(TaskGraphRunnerPerfTest, ScheduleTasks) {
|
| RunScheduleTasksTest("1_10", 1, 10);
|
| RunScheduleTasksTest("1_1000", 1, 1000);
|
| RunScheduleTasksTest("2_10", 2, 10);
|
| @@ -224,7 +207,7 @@ TEST_F(WorkerPoolPerfTest, ScheduleTasks) {
|
| RunScheduleTasksTest("10_1", 10, 1);
|
| }
|
|
|
| -TEST_F(WorkerPoolPerfTest, ExecuteTasks) {
|
| +TEST_F(TaskGraphRunnerPerfTest, ExecuteTasks) {
|
| RunExecuteTasksTest("1_10", 1, 10);
|
| RunExecuteTasksTest("1_1000", 1, 1000);
|
| RunExecuteTasksTest("2_10", 2, 10);
|
| @@ -235,5 +218,4 @@ TEST_F(WorkerPoolPerfTest, ExecuteTasks) {
|
| }
|
|
|
| } // namespace
|
| -
|
| } // namespace cc
|
|
|