| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "cc/base/completion_event.h" | 13 #include "cc/base/completion_event.h" |
| 14 #include "cc/debug/lap_timer.h" | 14 #include "cc/debug/lap_timer.h" |
| 15 #include "cc/raster/synchronous_task_graph_runner.h" | 15 #include "cc/raster/synchronous_task_graph_runner.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "testing/perf/perf_test.h" | 17 #include "testing/perf/perf_test.h" |
| 18 | 18 |
| 19 namespace cc { | 19 namespace cc { |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 static const int kTimeLimitMillis = 2000; | 22 static const int kTimeLimitMillis = 2000; |
| 23 static const int kWarmupRuns = 5; | 23 static const int kWarmupRuns = 5; |
| 24 static const int kTimeCheckInterval = 10; | 24 static const int kTimeCheckInterval = 10; |
| 25 | 25 |
| 26 class PerfTaskImpl : public Task { | 26 class PerfTaskImpl : public DependencyTask { |
| 27 public: | 27 public: |
| 28 typedef std::vector<scoped_refptr<PerfTaskImpl>> Vector; | 28 typedef std::vector<scoped_refptr<PerfTaskImpl>> Vector; |
| 29 | 29 |
| 30 PerfTaskImpl() {} | 30 PerfTaskImpl() {} |
| 31 | 31 |
| 32 // Overridden from Task: | 32 // Overridden from DependencyTask: |
| 33 void ScheduleOnOriginThread(DependencyTaskClient* client) override {} |
| 34 void CompleteOnOriginThread(DependencyTaskClient* client) override {} |
| 33 void RunOnWorkerThread() override {} | 35 void RunOnWorkerThread() override {} |
| 34 | 36 |
| 35 void Reset() { did_run_ = false; } | 37 void Reset() { did_run_ = false; } |
| 36 | 38 |
| 37 private: | 39 private: |
| 38 ~PerfTaskImpl() override {} | 40 ~PerfTaskImpl() override {} |
| 39 | 41 |
| 40 DISALLOW_COPY_AND_ASSIGN(PerfTaskImpl); | 42 DISALLOW_COPY_AND_ASSIGN(PerfTaskImpl); |
| 41 }; | 43 }; |
| 42 | 44 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 PerfTaskImpl::Vector top_level_tasks; | 92 PerfTaskImpl::Vector top_level_tasks; |
| 91 PerfTaskImpl::Vector tasks; | 93 PerfTaskImpl::Vector tasks; |
| 92 PerfTaskImpl::Vector leaf_tasks; | 94 PerfTaskImpl::Vector leaf_tasks; |
| 93 CreateTasks(num_top_level_tasks, &top_level_tasks); | 95 CreateTasks(num_top_level_tasks, &top_level_tasks); |
| 94 CreateTasks(num_tasks, &tasks); | 96 CreateTasks(num_tasks, &tasks); |
| 95 CreateTasks(num_leaf_tasks, &leaf_tasks); | 97 CreateTasks(num_leaf_tasks, &leaf_tasks); |
| 96 | 98 |
| 97 // Avoid unnecessary heap allocations by reusing the same graph and | 99 // Avoid unnecessary heap allocations by reusing the same graph and |
| 98 // completed tasks vector. | 100 // completed tasks vector. |
| 99 TaskGraph graph; | 101 TaskGraph graph; |
| 100 Task::Vector completed_tasks; | 102 DependencyTask::Vector completed_tasks; |
| 101 | 103 |
| 102 timer_.Reset(); | 104 timer_.Reset(); |
| 103 do { | 105 do { |
| 104 graph.Reset(); | 106 graph.Reset(); |
| 105 BuildTaskGraph(top_level_tasks, tasks, leaf_tasks, &graph); | 107 BuildTaskGraph(top_level_tasks, tasks, leaf_tasks, &graph); |
| 106 task_graph_runner_->ScheduleTasks(namespace_token_, &graph); | 108 task_graph_runner_->ScheduleTasks(namespace_token_, &graph); |
| 107 // Shouldn't be any tasks to collect as we reschedule the same set | 109 // Shouldn't be any tasks to collect as we reschedule the same set |
| 108 // of tasks. | 110 // of tasks. |
| 109 DCHECK_EQ(0u, CollectCompletedTasks(&completed_tasks)); | 111 DCHECK_EQ(0u, CollectCompletedTasks(&completed_tasks)); |
| 110 timer_.NextLap(); | 112 timer_.NextLap(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 132 PerfTaskImpl::Vector leaf_tasks[kNumVersions]; | 134 PerfTaskImpl::Vector leaf_tasks[kNumVersions]; |
| 133 for (size_t i = 0; i < kNumVersions; ++i) { | 135 for (size_t i = 0; i < kNumVersions; ++i) { |
| 134 CreateTasks(num_top_level_tasks, &top_level_tasks[i]); | 136 CreateTasks(num_top_level_tasks, &top_level_tasks[i]); |
| 135 CreateTasks(num_tasks, &tasks[i]); | 137 CreateTasks(num_tasks, &tasks[i]); |
| 136 CreateTasks(num_leaf_tasks, &leaf_tasks[i]); | 138 CreateTasks(num_leaf_tasks, &leaf_tasks[i]); |
| 137 } | 139 } |
| 138 | 140 |
| 139 // Avoid unnecessary heap allocations by reusing the same graph and | 141 // Avoid unnecessary heap allocations by reusing the same graph and |
| 140 // completed tasks vector. | 142 // completed tasks vector. |
| 141 TaskGraph graph; | 143 TaskGraph graph; |
| 142 Task::Vector completed_tasks; | 144 DependencyTask::Vector completed_tasks; |
| 143 | 145 |
| 144 size_t count = 0; | 146 size_t count = 0; |
| 145 timer_.Reset(); | 147 timer_.Reset(); |
| 146 do { | 148 do { |
| 147 graph.Reset(); | 149 graph.Reset(); |
| 148 BuildTaskGraph(top_level_tasks[count % kNumVersions], | 150 BuildTaskGraph(top_level_tasks[count % kNumVersions], |
| 149 tasks[count % kNumVersions], | 151 tasks[count % kNumVersions], |
| 150 leaf_tasks[count % kNumVersions], | 152 leaf_tasks[count % kNumVersions], |
| 151 &graph); | 153 &graph); |
| 152 task_graph_runner_->ScheduleTasks(namespace_token_, &graph); | 154 task_graph_runner_->ScheduleTasks(namespace_token_, &graph); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 175 PerfTaskImpl::Vector top_level_tasks; | 177 PerfTaskImpl::Vector top_level_tasks; |
| 176 PerfTaskImpl::Vector tasks; | 178 PerfTaskImpl::Vector tasks; |
| 177 PerfTaskImpl::Vector leaf_tasks; | 179 PerfTaskImpl::Vector leaf_tasks; |
| 178 CreateTasks(num_top_level_tasks, &top_level_tasks); | 180 CreateTasks(num_top_level_tasks, &top_level_tasks); |
| 179 CreateTasks(num_tasks, &tasks); | 181 CreateTasks(num_tasks, &tasks); |
| 180 CreateTasks(num_leaf_tasks, &leaf_tasks); | 182 CreateTasks(num_leaf_tasks, &leaf_tasks); |
| 181 | 183 |
| 182 // Avoid unnecessary heap allocations by reusing the same graph and | 184 // Avoid unnecessary heap allocations by reusing the same graph and |
| 183 // completed tasks vector. | 185 // completed tasks vector. |
| 184 TaskGraph graph; | 186 TaskGraph graph; |
| 185 Task::Vector completed_tasks; | 187 DependencyTask::Vector completed_tasks; |
| 186 | 188 |
| 187 timer_.Reset(); | 189 timer_.Reset(); |
| 188 do { | 190 do { |
| 189 graph.Reset(); | 191 graph.Reset(); |
| 190 BuildTaskGraph(top_level_tasks, tasks, leaf_tasks, &graph); | 192 BuildTaskGraph(top_level_tasks, tasks, leaf_tasks, &graph); |
| 191 task_graph_runner_->ScheduleTasks(namespace_token_, &graph); | 193 task_graph_runner_->ScheduleTasks(namespace_token_, &graph); |
| 192 task_graph_runner_->RunUntilIdle(); | 194 task_graph_runner_->RunUntilIdle(); |
| 193 CollectCompletedTasks(&completed_tasks); | 195 CollectCompletedTasks(&completed_tasks); |
| 194 completed_tasks.clear(); | 196 completed_tasks.clear(); |
| 195 ResetTasks(&top_level_tasks); | 197 ResetTasks(&top_level_tasks); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 } | 258 } |
| 257 } | 259 } |
| 258 | 260 |
| 259 for (PerfTaskImpl::Vector::const_iterator it = top_level_tasks.begin(); | 261 for (PerfTaskImpl::Vector::const_iterator it = top_level_tasks.begin(); |
| 260 it != top_level_tasks.end(); ++it) { | 262 it != top_level_tasks.end(); ++it) { |
| 261 graph->nodes.push_back(TaskGraph::Node( | 263 graph->nodes.push_back(TaskGraph::Node( |
| 262 it->get(), 0u, 0u, static_cast<uint32_t>(tasks.size()))); | 264 it->get(), 0u, 0u, static_cast<uint32_t>(tasks.size()))); |
| 263 } | 265 } |
| 264 } | 266 } |
| 265 | 267 |
| 266 size_t CollectCompletedTasks(Task::Vector* completed_tasks) { | 268 size_t CollectCompletedTasks(DependencyTask::Vector* completed_tasks) { |
| 267 DCHECK(completed_tasks->empty()); | 269 DCHECK(completed_tasks->empty()); |
| 268 task_graph_runner_->CollectCompletedTasks(namespace_token_, | 270 task_graph_runner_->CollectCompletedTasks(namespace_token_, |
| 269 completed_tasks); | 271 completed_tasks); |
| 270 return completed_tasks->size(); | 272 return completed_tasks->size(); |
| 271 } | 273 } |
| 272 | 274 |
| 273 // Test uses SynchronousTaskGraphRunner, as this implementation introduces | 275 // Test uses SynchronousTaskGraphRunner, as this implementation introduces |
| 274 // minimal additional complexity over the TaskGraphWorkQueue helpers. | 276 // minimal additional complexity over the TaskGraphWorkQueue helpers. |
| 275 scoped_ptr<SynchronousTaskGraphRunner> task_graph_runner_; | 277 scoped_ptr<SynchronousTaskGraphRunner> task_graph_runner_; |
| 276 NamespaceToken namespace_token_; | 278 NamespaceToken namespace_token_; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 RunScheduleAndExecuteTasksTest("0_1_0", 0, 1, 0); | 310 RunScheduleAndExecuteTasksTest("0_1_0", 0, 1, 0); |
| 309 RunScheduleAndExecuteTasksTest("0_32_0", 0, 32, 0); | 311 RunScheduleAndExecuteTasksTest("0_32_0", 0, 32, 0); |
| 310 RunScheduleAndExecuteTasksTest("2_1_0", 2, 1, 0); | 312 RunScheduleAndExecuteTasksTest("2_1_0", 2, 1, 0); |
| 311 RunScheduleAndExecuteTasksTest("2_32_0", 2, 32, 0); | 313 RunScheduleAndExecuteTasksTest("2_32_0", 2, 32, 0); |
| 312 RunScheduleAndExecuteTasksTest("2_1_1", 2, 1, 1); | 314 RunScheduleAndExecuteTasksTest("2_1_1", 2, 1, 1); |
| 313 RunScheduleAndExecuteTasksTest("2_32_1", 2, 32, 1); | 315 RunScheduleAndExecuteTasksTest("2_32_1", 2, 32, 1); |
| 314 } | 316 } |
| 315 | 317 |
| 316 } // namespace | 318 } // namespace |
| 317 } // namespace cc | 319 } // namespace cc |
| OLD | NEW |