OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This tool is used to benchmark the render model used by the compositor | 5 // This tool is used to benchmark the render model used by the compositor |
6 | 6 |
7 // Most of this file is derived from the source of the tile_render_bench tool, | 7 // Most of this file is derived from the source of the tile_render_bench tool, |
8 // and has been changed to support running a sequence of independent | 8 // and has been changed to support running a sequence of independent |
9 // simulations for our different render models and test cases. | 9 // simulations for our different render models and test cases. |
10 | 10 |
(...skipping 29 matching lines...) Expand all Loading... |
40 using file_util::CloseFile; | 40 using file_util::CloseFile; |
41 using file_util::DirectoryExists; | 41 using file_util::DirectoryExists; |
42 using file_util::FileEnumerator; | 42 using file_util::FileEnumerator; |
43 using file_util::OpenFile; | 43 using file_util::OpenFile; |
44 using file_util::PathExists; | 44 using file_util::PathExists; |
45 using std::queue; | 45 using std::queue; |
46 using std::string; | 46 using std::string; |
47 | 47 |
48 struct SimulationSpecification { | 48 struct SimulationSpecification { |
49 string simulation_name; | 49 string simulation_name; |
50 FilePath input_path; | 50 base::FilePath input_path; |
51 RenderModel model_under_test; | 51 RenderModel model_under_test; |
52 TimeTicks simulation_start_time; | 52 TimeTicks simulation_start_time; |
53 int frames_rendered; | 53 int frames_rendered; |
54 }; | 54 }; |
55 | 55 |
56 // Forward declarations | 56 // Forward declarations |
57 class Simulator; | 57 class Simulator; |
58 void _process_events(Simulator* sim); | 58 void _process_events(Simulator* sim); |
59 void _update_loop(Simulator* sim); | 59 void _update_loop(Simulator* sim); |
60 | 60 |
61 class Simulator { | 61 class Simulator { |
62 public: | 62 public: |
63 Simulator(int seconds_per_test, const FilePath& output_path) | 63 Simulator(int seconds_per_test, const base::FilePath& output_path) |
64 : current_sim_(NULL), | 64 : current_sim_(NULL), |
65 output_path_(output_path), | 65 output_path_(output_path), |
66 seconds_per_test_(seconds_per_test), | 66 seconds_per_test_(seconds_per_test), |
67 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 67 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
68 display_(NULL), | 68 display_(NULL), |
69 window_(0), | 69 window_(0), |
70 gl_context_(NULL), | 70 gl_context_(NULL), |
71 window_width_(WINDOW_WIDTH), | 71 window_width_(WINDOW_WIDTH), |
72 window_height_(WINDOW_HEIGHT) { | 72 window_height_(WINDOW_HEIGHT) { |
73 } | 73 } |
74 | 74 |
75 ~Simulator() { | 75 ~Simulator() { |
76 // Cleanup GL. | 76 // Cleanup GL. |
77 glXMakeCurrent(display_, 0, NULL); | 77 glXMakeCurrent(display_, 0, NULL); |
78 glXDestroyContext(display_, gl_context_); | 78 glXDestroyContext(display_, gl_context_); |
79 | 79 |
80 // Destroy window and display. | 80 // Destroy window and display. |
81 XDestroyWindow(display_, window_); | 81 XDestroyWindow(display_, window_); |
82 XCloseDisplay(display_); | 82 XCloseDisplay(display_); |
83 } | 83 } |
84 | 84 |
85 void QueueTest(const FilePath& path) { | 85 void QueueTest(const base::FilePath& path) { |
86 SimulationSpecification spec; | 86 SimulationSpecification spec; |
87 | 87 |
88 // To get a std::string, we'll try to get an ASCII simulation name. | 88 // To get a std::string, we'll try to get an ASCII simulation name. |
89 // If the name of the file wasn't ASCII, this will give an empty simulation | 89 // If the name of the file wasn't ASCII, this will give an empty simulation |
90 // name, but that's not really harmful (we'll still warn about it though.) | 90 // name, but that's not really harmful (we'll still warn about it though.) |
91 spec.simulation_name = path.BaseName().RemoveExtension().MaybeAsASCII(); | 91 spec.simulation_name = path.BaseName().RemoveExtension().MaybeAsASCII(); |
92 if (spec.simulation_name == "") { | 92 if (spec.simulation_name == "") { |
93 LOG(WARNING) << "Simulation for path " << path.LossyDisplayName() << | 93 LOG(WARNING) << "Simulation for path " << path.LossyDisplayName() << |
94 " will have a blank simulation name, since the file name isn't ASCII"; | 94 " will have a blank simulation name, since the file name isn't ASCII"; |
95 } | 95 } |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 return false; | 218 return false; |
219 } | 219 } |
220 | 220 |
221 return true; | 221 return true; |
222 } | 222 } |
223 | 223 |
224 bool InitializeNextTest() { | 224 bool InitializeNextTest() { |
225 SimulationSpecification& spec = sims_remaining_.front(); | 225 SimulationSpecification& spec = sims_remaining_.front(); |
226 LOG(INFO) << "Initializing test for " << spec.simulation_name << | 226 LOG(INFO) << "Initializing test for " << spec.simulation_name << |
227 "(" << ModelToString(spec.model_under_test) << ")"; | 227 "(" << ModelToString(spec.model_under_test) << ")"; |
228 const FilePath& path = spec.input_path; | 228 const base::FilePath& path = spec.input_path; |
229 | 229 |
230 RenderNode* root = NULL; | 230 RenderNode* root = NULL; |
231 if (!(root = BuildRenderTreeFromFile(path))) { | 231 if (!(root = BuildRenderTreeFromFile(path))) { |
232 LOG(ERROR) << "Couldn't parse test configuration file " << | 232 LOG(ERROR) << "Couldn't parse test configuration file " << |
233 path.LossyDisplayName(); | 233 path.LossyDisplayName(); |
234 return false; | 234 return false; |
235 } | 235 } |
236 | 236 |
237 current_sim_ = ConstructSimulationModel(spec.model_under_test, | 237 current_sim_ = ConstructSimulationModel(spec.model_under_test, |
238 root, | 238 root, |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 window_width_ = width; | 336 window_width_ = width; |
337 window_height_ = height; | 337 window_height_ = height; |
338 if (current_sim_) | 338 if (current_sim_) |
339 current_sim_->Resize(window_width_, window_height_); | 339 current_sim_->Resize(window_width_, window_height_); |
340 } | 340 } |
341 | 341 |
342 // Simulation task list for this execution | 342 // Simulation task list for this execution |
343 RenderModelSimulator* current_sim_; | 343 RenderModelSimulator* current_sim_; |
344 queue<SimulationSpecification> sims_remaining_; | 344 queue<SimulationSpecification> sims_remaining_; |
345 queue<SimulationSpecification> sims_completed_; | 345 queue<SimulationSpecification> sims_completed_; |
346 FilePath output_path_; | 346 base::FilePath output_path_; |
347 // Amount of time to run each simulation | 347 // Amount of time to run each simulation |
348 int seconds_per_test_; | 348 int seconds_per_test_; |
349 // GUI data | 349 // GUI data |
350 base::WeakPtrFactory<Simulator> weak_factory_; | 350 base::WeakPtrFactory<Simulator> weak_factory_; |
351 Display* display_; | 351 Display* display_; |
352 Window window_; | 352 Window window_; |
353 GLXContext gl_context_; | 353 GLXContext gl_context_; |
354 int window_width_; | 354 int window_width_; |
355 int window_height_; | 355 int window_height_; |
356 }; | 356 }; |
(...skipping 16 matching lines...) Expand all Loading... |
373 "written to the output path."; | 373 "written to the output path."; |
374 return -1; | 374 return -1; |
375 } | 375 } |
376 | 376 |
377 int seconds_per_test = 1; | 377 int seconds_per_test = 1; |
378 if (cl->HasSwitch("duration")) { | 378 if (cl->HasSwitch("duration")) { |
379 seconds_per_test = atoi(cl->GetSwitchValueASCII("duration").c_str()); | 379 seconds_per_test = atoi(cl->GetSwitchValueASCII("duration").c_str()); |
380 } | 380 } |
381 | 381 |
382 Simulator sim(seconds_per_test, cl->GetSwitchValuePath("out")); | 382 Simulator sim(seconds_per_test, cl->GetSwitchValuePath("out")); |
383 FilePath inPath = cl->GetSwitchValuePath("in"); | 383 base::FilePath inPath = cl->GetSwitchValuePath("in"); |
384 | 384 |
385 if (!PathExists(inPath)) { | 385 if (!PathExists(inPath)) { |
386 LOG(FATAL) << "Path does not exist: " << inPath.LossyDisplayName(); | 386 LOG(FATAL) << "Path does not exist: " << inPath.LossyDisplayName(); |
387 return -1; | 387 return -1; |
388 } | 388 } |
389 | 389 |
390 if (DirectoryExists(inPath)) { | 390 if (DirectoryExists(inPath)) { |
391 LOG(INFO) << "(input path is a directory)"; | 391 LOG(INFO) << "(input path is a directory)"; |
392 FileEnumerator dirItr(inPath, true, FileEnumerator::FILES); | 392 FileEnumerator dirItr(inPath, true, FileEnumerator::FILES); |
393 for (FilePath f = dirItr.Next(); !f.empty(); f = dirItr.Next()) { | 393 for (base::FilePath f = dirItr.Next(); !f.empty(); f = dirItr.Next()) { |
394 sim.QueueTest(f); | 394 sim.QueueTest(f); |
395 } | 395 } |
396 } else { | 396 } else { |
397 LOG(INFO) << "(input path is a file)"; | 397 LOG(INFO) << "(input path is a file)"; |
398 sim.QueueTest(inPath); | 398 sim.QueueTest(inPath); |
399 } | 399 } |
400 | 400 |
401 sim.Run(); | 401 sim.Run(); |
402 | 402 |
403 return 0; | 403 return 0; |
404 } | 404 } |
OLD | NEW |