| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "cc/resources/worker_pool.h" | 5 #include "cc/resources/worker_pool.h" |
| 6 | 6 |
| 7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
| 8 #include "cc/base/completion_event.h" | 8 #include "cc/base/completion_event.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 | 62 |
| 63 static scoped_ptr<PerfWorkerPool> Create() { | 63 static scoped_ptr<PerfWorkerPool> Create() { |
| 64 return make_scoped_ptr(new PerfWorkerPool); | 64 return make_scoped_ptr(new PerfWorkerPool); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void ScheduleTasks(internal::WorkerPoolTask* root_task, | 67 void ScheduleTasks(internal::WorkerPoolTask* root_task, |
| 68 internal::WorkerPoolTask* leaf_task, | 68 internal::WorkerPoolTask* leaf_task, |
| 69 unsigned max_depth, | 69 unsigned max_depth, |
| 70 unsigned num_children_per_node) { | 70 unsigned num_children_per_node) { |
| 71 TaskVector tasks; | 71 TaskVector tasks; |
| 72 unsigned priority = 0u; | |
| 73 TaskGraph graph; | 72 TaskGraph graph; |
| 74 | 73 |
| 75 scoped_ptr<GraphNode> root_node; | 74 scoped_ptr<internal::GraphNode> root_node; |
| 76 if (root_task) { | 75 if (root_task) |
| 77 root_node = make_scoped_ptr(new GraphNode); | 76 root_node = make_scoped_ptr(new internal::GraphNode(root_task, 0u)); |
| 78 root_node->set_task(root_task); | 77 |
| 78 scoped_ptr<internal::GraphNode> leaf_node; |
| 79 if (leaf_task) |
| 80 leaf_node = make_scoped_ptr(new internal::GraphNode(leaf_task, 0u)); |
| 81 |
| 82 if (max_depth) { |
| 83 BuildTaskGraph(&tasks, |
| 84 &graph, |
| 85 root_node.get(), |
| 86 leaf_node.get(), |
| 87 0, |
| 88 max_depth, |
| 89 num_children_per_node); |
| 79 } | 90 } |
| 80 | 91 |
| 81 scoped_ptr<GraphNode> leaf_node; | 92 if (leaf_node) |
| 82 if (leaf_task) { | 93 graph.set(leaf_task, leaf_node.Pass()); |
| 83 leaf_node = make_scoped_ptr(new GraphNode); | |
| 84 leaf_node->set_task(leaf_task); | |
| 85 } | |
| 86 | 94 |
| 87 if (max_depth) { | 95 if (root_node) |
| 88 priority = BuildTaskGraph(&tasks, | |
| 89 &graph, | |
| 90 root_node.get(), | |
| 91 leaf_node.get(), | |
| 92 priority, | |
| 93 0, | |
| 94 max_depth, | |
| 95 num_children_per_node); | |
| 96 } | |
| 97 | |
| 98 if (leaf_node) { | |
| 99 leaf_node->set_priority(priority++); | |
| 100 graph.set(leaf_task, leaf_node.Pass()); | |
| 101 } | |
| 102 | |
| 103 if (root_node) { | |
| 104 root_node->set_priority(priority++); | |
| 105 graph.set(root_task, root_node.Pass()); | 96 graph.set(root_task, root_node.Pass()); |
| 106 } | |
| 107 | 97 |
| 108 SetTaskGraph(&graph); | 98 SetTaskGraph(&graph); |
| 109 | 99 |
| 110 tasks_.swap(tasks); | 100 tasks_.swap(tasks); |
| 111 } | 101 } |
| 112 | 102 |
| 113 private: | 103 private: |
| 114 typedef std::vector<scoped_refptr<internal::WorkerPoolTask> > TaskVector; | 104 typedef std::vector<scoped_refptr<internal::WorkerPoolTask> > TaskVector; |
| 115 | 105 |
| 116 unsigned BuildTaskGraph(TaskVector* tasks, | 106 void BuildTaskGraph(TaskVector* tasks, |
| 117 TaskGraph* graph, | 107 TaskGraph* graph, |
| 118 GraphNode* dependent_node, | 108 internal::GraphNode* dependent_node, |
| 119 GraphNode* leaf_node, | 109 internal::GraphNode* leaf_node, |
| 120 unsigned priority, | 110 unsigned current_depth, |
| 121 unsigned current_depth, | 111 unsigned max_depth, |
| 122 unsigned max_depth, | 112 unsigned num_children_per_node) { |
| 123 unsigned num_children_per_node) { | |
| 124 scoped_refptr<PerfWorkerPoolTaskImpl> task(new PerfWorkerPoolTaskImpl); | 113 scoped_refptr<PerfWorkerPoolTaskImpl> task(new PerfWorkerPoolTaskImpl); |
| 125 scoped_ptr<GraphNode> node(new GraphNode); | 114 scoped_ptr<internal::GraphNode> node( |
| 126 node->set_task(task.get()); | 115 new internal::GraphNode(task.get(), 0u)); |
| 127 | 116 |
| 128 if (current_depth < max_depth) { | 117 if (current_depth < max_depth) { |
| 129 for (unsigned i = 0; i < num_children_per_node; ++i) { | 118 for (unsigned i = 0; i < num_children_per_node; ++i) { |
| 130 priority = BuildTaskGraph(tasks, | 119 BuildTaskGraph(tasks, |
| 131 graph, | 120 graph, |
| 132 node.get(), | 121 node.get(), |
| 133 leaf_node, | 122 leaf_node, |
| 134 priority, | 123 current_depth + 1, |
| 135 current_depth + 1, | 124 max_depth, |
| 136 max_depth, | 125 num_children_per_node); |
| 137 num_children_per_node); | |
| 138 } | 126 } |
| 139 } else if (leaf_node) { | 127 } else if (leaf_node) { |
| 140 leaf_node->add_dependent(node.get()); | 128 leaf_node->add_dependent(node.get()); |
| 141 node->add_dependency(); | 129 node->add_dependency(); |
| 142 } | 130 } |
| 143 | 131 |
| 144 if (dependent_node) { | 132 if (dependent_node) { |
| 145 node->add_dependent(dependent_node); | 133 node->add_dependent(dependent_node); |
| 146 dependent_node->add_dependency(); | 134 dependent_node->add_dependency(); |
| 147 } | 135 } |
| 148 node->set_priority(priority); | |
| 149 graph->set(task.get(), node.Pass()); | 136 graph->set(task.get(), node.Pass()); |
| 150 tasks->push_back(task.get()); | 137 tasks->push_back(task.get()); |
| 151 | |
| 152 return priority + 1; | |
| 153 } | 138 } |
| 154 | 139 |
| 155 TaskVector tasks_; | 140 TaskVector tasks_; |
| 156 | 141 |
| 157 DISALLOW_COPY_AND_ASSIGN(PerfWorkerPool); | 142 DISALLOW_COPY_AND_ASSIGN(PerfWorkerPool); |
| 158 }; | 143 }; |
| 159 | 144 |
| 160 class WorkerPoolPerfTest : public testing::Test { | 145 class WorkerPoolPerfTest : public testing::Test { |
| 161 public: | 146 public: |
| 162 WorkerPoolPerfTest() : num_runs_(0) {} | 147 WorkerPoolPerfTest() : num_runs_(0) {} |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 RunExecuteTasksTest("execute_tasks_2_10", 2, 10); | 242 RunExecuteTasksTest("execute_tasks_2_10", 2, 10); |
| 258 RunExecuteTasksTest("execute_tasks_5_5", 5, 5); | 243 RunExecuteTasksTest("execute_tasks_5_5", 5, 5); |
| 259 RunExecuteTasksTest("execute_tasks_10_2", 10, 2); | 244 RunExecuteTasksTest("execute_tasks_10_2", 10, 2); |
| 260 RunExecuteTasksTest("execute_tasks_1000_1", 1000, 1); | 245 RunExecuteTasksTest("execute_tasks_1000_1", 1000, 1); |
| 261 RunExecuteTasksTest("execute_tasks_10_1", 10, 1); | 246 RunExecuteTasksTest("execute_tasks_10_1", 10, 1); |
| 262 } | 247 } |
| 263 | 248 |
| 264 } // namespace | 249 } // namespace |
| 265 | 250 |
| 266 } // namespace cc | 251 } // namespace cc |
| OLD | NEW |