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/debug/micro_benchmark_controller.h" | 5 #include "cc/debug/micro_benchmark_controller.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "cc/debug/picture_record_benchmark.h" | 12 #include "cc/debug/picture_record_benchmark.h" |
13 #include "cc/debug/rasterize_and_record_benchmark.h" | 13 #include "cc/debug/rasterize_and_record_benchmark.h" |
14 #include "cc/debug/unittest_only_benchmark.h" | 14 #include "cc/debug/unittest_only_benchmark.h" |
15 #include "cc/trees/layer_tree_host.h" | 15 #include "cc/trees/layer_tree_host.h" |
16 #include "cc/trees/layer_tree_host_impl.h" | 16 #include "cc/trees/layer_tree_host_impl.h" |
17 | 17 |
18 namespace cc { | 18 namespace cc { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 scoped_ptr<MicroBenchmark> CreateBenchmark( | 22 scoped_ptr<MicroBenchmark> CreateBenchmark( |
23 const std::string& name, | 23 const std::string& name, |
24 scoped_ptr<base::Value> value, | 24 scoped_ptr<base::Value> value, |
25 const MicroBenchmark::DoneCallback& callback) { | 25 const MicroBenchmark::DoneCallback& callback, |
26 int id) { | |
26 if (name == "picture_record_benchmark") { | 27 if (name == "picture_record_benchmark") { |
27 return scoped_ptr<MicroBenchmark>( | 28 return scoped_ptr<MicroBenchmark>( |
28 new PictureRecordBenchmark(value.Pass(), callback)); | 29 new PictureRecordBenchmark(value.Pass(), callback, id)); |
29 } else if (name == "rasterize_and_record_benchmark") { | 30 } else if (name == "rasterize_and_record_benchmark") { |
30 return scoped_ptr<MicroBenchmark>( | 31 return scoped_ptr<MicroBenchmark>( |
31 new RasterizeAndRecordBenchmark(value.Pass(), callback)); | 32 new RasterizeAndRecordBenchmark(value.Pass(), callback, id)); |
32 } else if (name == "unittest_only_benchmark") { | 33 } else if (name == "unittest_only_benchmark") { |
33 return scoped_ptr<MicroBenchmark>( | 34 return scoped_ptr<MicroBenchmark>( |
34 new UnittestOnlyBenchmark(value.Pass(), callback)); | 35 new UnittestOnlyBenchmark(value.Pass(), callback, id)); |
35 } | 36 } |
36 return scoped_ptr<MicroBenchmark>(); | 37 return scoped_ptr<MicroBenchmark>(); |
37 } | 38 } |
38 | 39 |
39 class IsDonePredicate { | 40 class IsDonePredicate { |
40 public: | 41 public: |
41 typedef const MicroBenchmark* argument_type; | 42 typedef const MicroBenchmark* argument_type; |
42 typedef bool result_type; | 43 typedef bool result_type; |
43 | 44 |
44 result_type operator()(argument_type benchmark) const { | 45 result_type operator()(argument_type benchmark) const { |
45 return benchmark->IsDone(); | 46 return benchmark->IsDone(); |
46 } | 47 } |
47 }; | 48 }; |
48 | 49 |
49 } // namespace | 50 } // namespace |
50 | 51 |
51 MicroBenchmarkController::MicroBenchmarkController(LayerTreeHost* host) | 52 MicroBenchmarkController::MicroBenchmarkController(LayerTreeHost* host) |
52 : host_(host), | 53 : host_(host), |
54 next_id_(1), | |
53 main_controller_message_loop_(base::MessageLoopProxy::current().get()) { | 55 main_controller_message_loop_(base::MessageLoopProxy::current().get()) { |
54 DCHECK(host_); | 56 DCHECK(host_); |
55 } | 57 } |
56 | 58 |
57 MicroBenchmarkController::~MicroBenchmarkController() {} | 59 MicroBenchmarkController::~MicroBenchmarkController() {} |
58 | 60 |
59 bool MicroBenchmarkController::ScheduleRun( | 61 int MicroBenchmarkController::ScheduleRun( |
60 const std::string& micro_benchmark_name, | 62 const std::string& micro_benchmark_name, |
61 scoped_ptr<base::Value> value, | 63 scoped_ptr<base::Value> value, |
62 const MicroBenchmark::DoneCallback& callback) { | 64 const MicroBenchmark::DoneCallback& callback) { |
65 int id = GetNextIdAndIncrement(); | |
63 scoped_ptr<MicroBenchmark> benchmark = | 66 scoped_ptr<MicroBenchmark> benchmark = |
64 CreateBenchmark(micro_benchmark_name, value.Pass(), callback); | 67 CreateBenchmark(micro_benchmark_name, value.Pass(), callback, id); |
65 if (benchmark.get()) { | 68 if (benchmark.get()) { |
66 benchmarks_.push_back(benchmark.Pass()); | 69 benchmarks_.push_back(benchmark.Pass()); |
67 host_->SetNeedsCommit(); | 70 host_->SetNeedsCommit(); |
68 return true; | 71 return id; |
72 } | |
73 return 0; | |
74 } | |
75 | |
76 int MicroBenchmarkController::GetNextIdAndIncrement() { | |
77 int id = next_id_++; | |
78 // Wrap around to 1 if we overflow (very unlikely). | |
79 if (next_id_ < 1) | |
vmpstr
2014/05/28 21:16:25
signed int overflow is undefined... Maybe somethin
ernstm
2014/05/28 21:51:55
Done.
| |
80 next_id_ = 1; | |
81 return id; | |
82 } | |
83 | |
84 bool MicroBenchmarkController::SendMessage(int id, | |
vmpstr
2014/05/28 21:16:25
I'm sorry to go back on what I said earlier, but..
ernstm
2014/05/28 21:51:55
As discussed offline, renamed the function to Proc
| |
85 scoped_ptr<base::Value> value) { | |
86 for (ScopedPtrVector<MicroBenchmark>::iterator it = benchmarks_.begin(); | |
87 it != benchmarks_.end(); | |
88 ++it) { | |
89 if ((*it)->id() == id) | |
90 return (*it)->SendMessage(value.Pass()); | |
69 } | 91 } |
70 return false; | 92 return false; |
71 } | 93 } |
72 | 94 |
73 void MicroBenchmarkController::ScheduleImplBenchmarks( | 95 void MicroBenchmarkController::ScheduleImplBenchmarks( |
74 LayerTreeHostImpl* host_impl) { | 96 LayerTreeHostImpl* host_impl) { |
75 for (ScopedPtrVector<MicroBenchmark>::iterator it = benchmarks_.begin(); | 97 for (ScopedPtrVector<MicroBenchmark>::iterator it = benchmarks_.begin(); |
76 it != benchmarks_.end(); | 98 it != benchmarks_.end(); |
77 ++it) { | 99 ++it) { |
78 scoped_ptr<MicroBenchmarkImpl> benchmark_impl; | 100 scoped_ptr<MicroBenchmarkImpl> benchmark_impl; |
(...skipping 18 matching lines...) Expand all Loading... | |
97 CleanUpFinishedBenchmarks(); | 119 CleanUpFinishedBenchmarks(); |
98 } | 120 } |
99 | 121 |
100 void MicroBenchmarkController::CleanUpFinishedBenchmarks() { | 122 void MicroBenchmarkController::CleanUpFinishedBenchmarks() { |
101 benchmarks_.erase( | 123 benchmarks_.erase( |
102 benchmarks_.partition(std::not1(IsDonePredicate())), | 124 benchmarks_.partition(std::not1(IsDonePredicate())), |
103 benchmarks_.end()); | 125 benchmarks_.end()); |
104 } | 126 } |
105 | 127 |
106 } // namespace cc | 128 } // namespace cc |
OLD | NEW |