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

Side by Side Diff: cc/raster/task_graph_runner_perftest.cc

Issue 2003333002: cc: Task should complete as finished or canceled in tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@test_task_runner
Patch Set: Created 4 years, 6 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 unified diff | Download patch
« no previous file with comments | « cc/raster/task.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <memory> 8 #include <memory>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 // Avoid unnecessary heap allocations by reusing the same graph. 69 // Avoid unnecessary heap allocations by reusing the same graph.
70 TaskGraph graph; 70 TaskGraph graph;
71 71
72 timer_.Reset(); 72 timer_.Reset();
73 do { 73 do {
74 graph.Reset(); 74 graph.Reset();
75 BuildTaskGraph(top_level_tasks, tasks, leaf_tasks, &graph); 75 BuildTaskGraph(top_level_tasks, tasks, leaf_tasks, &graph);
76 timer_.NextLap(); 76 timer_.NextLap();
77 } while (!timer_.HasTimeLimitExpired()); 77 } while (!timer_.HasTimeLimitExpired());
78 78
79 CancelTasks(leaf_tasks);
80 CancelTasks(tasks);
81 CancelTasks(top_level_tasks);
82
79 perf_test::PrintResult("build_task_graph", 83 perf_test::PrintResult("build_task_graph",
80 TestModifierString(), 84 TestModifierString(),
81 test_name, 85 test_name,
82 timer_.LapsPerSecond(), 86 timer_.LapsPerSecond(),
83 "runs/s", 87 "runs/s",
84 true); 88 true);
85 } 89 }
86 90
87 void RunScheduleTasksTest(const std::string& test_name, 91 void RunScheduleTasksTest(const std::string& test_name,
88 int num_top_level_tasks, 92 int num_top_level_tasks,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 TaskGraph graph; 146 TaskGraph graph;
143 Task::Vector completed_tasks; 147 Task::Vector completed_tasks;
144 148
145 size_t count = 0; 149 size_t count = 0;
146 timer_.Reset(); 150 timer_.Reset();
147 do { 151 do {
148 size_t current_version = count % kNumVersions; 152 size_t current_version = count % kNumVersions;
149 graph.Reset(); 153 graph.Reset();
150 // Reset tasks as we are not letting them execute, they get cancelled 154 // Reset tasks as we are not letting them execute, they get cancelled
151 // when next ScheduleTasks() happens. 155 // when next ScheduleTasks() happens.
152 ResetTasks(&top_level_tasks[current_version]); 156 ResetTasks(top_level_tasks[current_version]);
153 ResetTasks(&tasks[current_version]); 157 ResetTasks(tasks[current_version]);
154 ResetTasks(&leaf_tasks[current_version]); 158 ResetTasks(leaf_tasks[current_version]);
155 BuildTaskGraph(top_level_tasks[current_version], tasks[current_version], 159 BuildTaskGraph(top_level_tasks[current_version], tasks[current_version],
156 leaf_tasks[current_version], &graph); 160 leaf_tasks[current_version], &graph);
157 task_graph_runner_->ScheduleTasks(namespace_token_, &graph); 161 task_graph_runner_->ScheduleTasks(namespace_token_, &graph);
158 CollectCompletedTasks(&completed_tasks); 162 CollectCompletedTasks(&completed_tasks);
159 completed_tasks.clear(); 163 completed_tasks.clear();
160 ++count; 164 ++count;
161 timer_.NextLap(); 165 timer_.NextLap();
162 } while (!timer_.HasTimeLimitExpired()); 166 } while (!timer_.HasTimeLimitExpired());
163 167
164 TaskGraph empty; 168 TaskGraph empty;
(...skipping 20 matching lines...) Expand all
185 CreateTasks(num_leaf_tasks, &leaf_tasks); 189 CreateTasks(num_leaf_tasks, &leaf_tasks);
186 190
187 // Avoid unnecessary heap allocations by reusing the same graph and 191 // Avoid unnecessary heap allocations by reusing the same graph and
188 // completed tasks vector. 192 // completed tasks vector.
189 TaskGraph graph; 193 TaskGraph graph;
190 Task::Vector completed_tasks; 194 Task::Vector completed_tasks;
191 195
192 timer_.Reset(); 196 timer_.Reset();
193 do { 197 do {
194 graph.Reset(); 198 graph.Reset();
199 // Tasks run have finished state. Reset them to be considered as new for
200 // scheduling again.
201 ResetTasks(top_level_tasks);
202 ResetTasks(tasks);
203 ResetTasks(leaf_tasks);
195 BuildTaskGraph(top_level_tasks, tasks, leaf_tasks, &graph); 204 BuildTaskGraph(top_level_tasks, tasks, leaf_tasks, &graph);
196 task_graph_runner_->ScheduleTasks(namespace_token_, &graph); 205 task_graph_runner_->ScheduleTasks(namespace_token_, &graph);
197 task_graph_runner_->RunUntilIdle(); 206 task_graph_runner_->RunUntilIdle();
198 CollectCompletedTasks(&completed_tasks); 207 CollectCompletedTasks(&completed_tasks);
199 completed_tasks.clear(); 208 completed_tasks.clear();
200 ResetTasks(&top_level_tasks);
201 ResetTasks(&tasks);
202 ResetTasks(&leaf_tasks);
203 timer_.NextLap(); 209 timer_.NextLap();
204 } while (!timer_.HasTimeLimitExpired()); 210 } while (!timer_.HasTimeLimitExpired());
205 211
206 perf_test::PrintResult("execute_tasks", 212 perf_test::PrintResult("execute_tasks",
207 TestModifierString(), 213 TestModifierString(),
208 test_name, 214 test_name,
209 timer_.LapsPerSecond(), 215 timer_.LapsPerSecond(),
210 "runs/s", 216 "runs/s",
211 true); 217 true);
212 } 218 }
213 219
214 private: 220 private:
215 static std::string TestModifierString() { 221 static std::string TestModifierString() {
216 return std::string("_task_graph_runner"); 222 return std::string("_task_graph_runner");
217 } 223 }
218 224
219 void CreateTasks(int num_tasks, PerfTaskImpl::Vector* tasks) { 225 void CreateTasks(int num_tasks, PerfTaskImpl::Vector* tasks) {
220 for (int i = 0; i < num_tasks; ++i) 226 for (int i = 0; i < num_tasks; ++i)
221 tasks->push_back(make_scoped_refptr(new PerfTaskImpl)); 227 tasks->push_back(make_scoped_refptr(new PerfTaskImpl));
222 } 228 }
223 229
224 void ResetTasks(PerfTaskImpl::Vector* tasks) { 230 void CancelTasks(const PerfTaskImpl::Vector& tasks) {
225 for (PerfTaskImpl::Vector::iterator it = tasks->begin(); it != tasks->end(); 231 for (auto& task : tasks)
226 ++it) { 232 task->state().DidCancel();
227 PerfTaskImpl* task = it->get(); 233 }
234
235 void ResetTasks(const PerfTaskImpl::Vector& tasks) {
236 for (auto& task : tasks)
228 task->Reset(); 237 task->Reset();
229 }
230 } 238 }
231 239
232 void BuildTaskGraph(const PerfTaskImpl::Vector& top_level_tasks, 240 void BuildTaskGraph(const PerfTaskImpl::Vector& top_level_tasks,
233 const PerfTaskImpl::Vector& tasks, 241 const PerfTaskImpl::Vector& tasks,
234 const PerfTaskImpl::Vector& leaf_tasks, 242 const PerfTaskImpl::Vector& leaf_tasks,
235 TaskGraph* graph) { 243 TaskGraph* graph) {
236 DCHECK(graph->nodes.empty()); 244 DCHECK(graph->nodes.empty());
237 DCHECK(graph->edges.empty()); 245 DCHECK(graph->edges.empty());
238 246
239 for (PerfTaskImpl::Vector::const_iterator it = leaf_tasks.begin(); 247 for (PerfTaskImpl::Vector::const_iterator it = leaf_tasks.begin();
(...skipping 25 matching lines...) Expand all
265 it != top_level_tasks.end(); ++it) { 273 it != top_level_tasks.end(); ++it) {
266 graph->nodes.push_back(TaskGraph::Node( 274 graph->nodes.push_back(TaskGraph::Node(
267 it->get(), 0u, 0u, static_cast<uint32_t>(tasks.size()))); 275 it->get(), 0u, 0u, static_cast<uint32_t>(tasks.size())));
268 } 276 }
269 } 277 }
270 278
271 size_t CollectCompletedTasks(Task::Vector* completed_tasks) { 279 size_t CollectCompletedTasks(Task::Vector* completed_tasks) {
272 DCHECK(completed_tasks->empty()); 280 DCHECK(completed_tasks->empty());
273 task_graph_runner_->CollectCompletedTasks(namespace_token_, 281 task_graph_runner_->CollectCompletedTasks(namespace_token_,
274 completed_tasks); 282 completed_tasks);
275 for (auto& task : *completed_tasks) {
276 // Reset task state as same task would be reused as if new.
277 task->state().Reset();
278 }
279
280 return completed_tasks->size(); 283 return completed_tasks->size();
281 } 284 }
282 285
283 // Test uses SynchronousTaskGraphRunner, as this implementation introduces 286 // Test uses SynchronousTaskGraphRunner, as this implementation introduces
284 // minimal additional complexity over the TaskGraphWorkQueue helpers. 287 // minimal additional complexity over the TaskGraphWorkQueue helpers.
285 std::unique_ptr<SynchronousTaskGraphRunner> task_graph_runner_; 288 std::unique_ptr<SynchronousTaskGraphRunner> task_graph_runner_;
286 NamespaceToken namespace_token_; 289 NamespaceToken namespace_token_;
287 LapTimer timer_; 290 LapTimer timer_;
288 }; 291 };
289 292
(...skipping 28 matching lines...) Expand all
318 RunScheduleAndExecuteTasksTest("0_1_0", 0, 1, 0); 321 RunScheduleAndExecuteTasksTest("0_1_0", 0, 1, 0);
319 RunScheduleAndExecuteTasksTest("0_32_0", 0, 32, 0); 322 RunScheduleAndExecuteTasksTest("0_32_0", 0, 32, 0);
320 RunScheduleAndExecuteTasksTest("2_1_0", 2, 1, 0); 323 RunScheduleAndExecuteTasksTest("2_1_0", 2, 1, 0);
321 RunScheduleAndExecuteTasksTest("2_32_0", 2, 32, 0); 324 RunScheduleAndExecuteTasksTest("2_32_0", 2, 32, 0);
322 RunScheduleAndExecuteTasksTest("2_1_1", 2, 1, 1); 325 RunScheduleAndExecuteTasksTest("2_1_1", 2, 1, 1);
323 RunScheduleAndExecuteTasksTest("2_32_1", 2, 32, 1); 326 RunScheduleAndExecuteTasksTest("2_32_1", 2, 32, 1);
324 } 327 }
325 328
326 } // namespace 329 } // namespace
327 } // namespace cc 330 } // namespace cc
OLDNEW
« no previous file with comments | « cc/raster/task.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698