| 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<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 GraphNode(root_task, 0u)); |
| 78 root_node->set_task(root_task); | 77 |
| 78 scoped_ptr<GraphNode> leaf_node; |
| 79 if (leaf_task) |
| 80 leaf_node = make_scoped_ptr(new 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 GraphNode* dependent_node, |
| 119 GraphNode* leaf_node, | 109 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<GraphNode> node(new GraphNode(task.get(), 0u)); |
| 126 node->set_task(task.get()); | |
| 127 | 115 |
| 128 if (current_depth < max_depth) { | 116 if (current_depth < max_depth) { |
| 129 for (unsigned i = 0; i < num_children_per_node; ++i) { | 117 for (unsigned i = 0; i < num_children_per_node; ++i) { |
| 130 priority = BuildTaskGraph(tasks, | 118 BuildTaskGraph(tasks, |
| 131 graph, | 119 graph, |
| 132 node.get(), | 120 node.get(), |
| 133 leaf_node, | 121 leaf_node, |
| 134 priority, | 122 current_depth + 1, |
| 135 current_depth + 1, | 123 max_depth, |
| 136 max_depth, | 124 num_children_per_node); |
| 137 num_children_per_node); | |
| 138 } | 125 } |
| 139 } else if (leaf_node) { | 126 } else if (leaf_node) { |
| 140 leaf_node->add_dependent(node.get()); | 127 leaf_node->add_dependent(node.get()); |
| 141 node->add_dependency(); | 128 node->add_dependency(); |
| 142 } | 129 } |
| 143 | 130 |
| 144 if (dependent_node) { | 131 if (dependent_node) { |
| 145 node->add_dependent(dependent_node); | 132 node->add_dependent(dependent_node); |
| 146 dependent_node->add_dependency(); | 133 dependent_node->add_dependency(); |
| 147 } | 134 } |
| 148 node->set_priority(priority); | |
| 149 graph->set(task.get(), node.Pass()); | 135 graph->set(task.get(), node.Pass()); |
| 150 tasks->push_back(task.get()); | 136 tasks->push_back(task.get()); |
| 151 | |
| 152 return priority + 1; | |
| 153 } | 137 } |
| 154 | 138 |
| 155 TaskVector tasks_; | 139 TaskVector tasks_; |
| 156 | 140 |
| 157 DISALLOW_COPY_AND_ASSIGN(PerfWorkerPool); | 141 DISALLOW_COPY_AND_ASSIGN(PerfWorkerPool); |
| 158 }; | 142 }; |
| 159 | 143 |
| 160 class WorkerPoolPerfTest : public testing::Test { | 144 class WorkerPoolPerfTest : public testing::Test { |
| 161 public: | 145 public: |
| 162 WorkerPoolPerfTest() : num_runs_(0) {} | 146 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); | 241 RunExecuteTasksTest("execute_tasks_2_10", 2, 10); |
| 258 RunExecuteTasksTest("execute_tasks_5_5", 5, 5); | 242 RunExecuteTasksTest("execute_tasks_5_5", 5, 5); |
| 259 RunExecuteTasksTest("execute_tasks_10_2", 10, 2); | 243 RunExecuteTasksTest("execute_tasks_10_2", 10, 2); |
| 260 RunExecuteTasksTest("execute_tasks_1000_1", 1000, 1); | 244 RunExecuteTasksTest("execute_tasks_1000_1", 1000, 1); |
| 261 RunExecuteTasksTest("execute_tasks_10_1", 10, 1); | 245 RunExecuteTasksTest("execute_tasks_10_1", 10, 1); |
| 262 } | 246 } |
| 263 | 247 |
| 264 } // namespace | 248 } // namespace |
| 265 | 249 |
| 266 } // namespace cc | 250 } // namespace cc |
| OLD | NEW |