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 <limits> | 7 #include <limits> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/memory/ptr_util.h" |
11 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
12 #include "base/values.h" | 13 #include "base/values.h" |
13 #include "cc/debug/invalidation_benchmark.h" | 14 #include "cc/debug/invalidation_benchmark.h" |
14 #include "cc/debug/rasterize_and_record_benchmark.h" | 15 #include "cc/debug/rasterize_and_record_benchmark.h" |
15 #include "cc/debug/unittest_only_benchmark.h" | 16 #include "cc/debug/unittest_only_benchmark.h" |
16 #include "cc/trees/layer_tree_host.h" | 17 #include "cc/trees/layer_tree_host.h" |
17 #include "cc/trees/layer_tree_host_impl.h" | 18 #include "cc/trees/layer_tree_host_impl.h" |
18 | 19 |
19 namespace cc { | 20 namespace cc { |
20 | 21 |
21 int MicroBenchmarkController::next_id_ = 1; | 22 int MicroBenchmarkController::next_id_ = 1; |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 scoped_ptr<MicroBenchmark> CreateBenchmark( | 26 std::unique_ptr<MicroBenchmark> CreateBenchmark( |
26 const std::string& name, | 27 const std::string& name, |
27 scoped_ptr<base::Value> value, | 28 std::unique_ptr<base::Value> value, |
28 const MicroBenchmark::DoneCallback& callback) { | 29 const MicroBenchmark::DoneCallback& callback) { |
29 if (name == "invalidation_benchmark") { | 30 if (name == "invalidation_benchmark") { |
30 return make_scoped_ptr( | 31 return base::WrapUnique( |
31 new InvalidationBenchmark(std::move(value), callback)); | 32 new InvalidationBenchmark(std::move(value), callback)); |
32 } else if (name == "rasterize_and_record_benchmark") { | 33 } else if (name == "rasterize_and_record_benchmark") { |
33 return make_scoped_ptr( | 34 return base::WrapUnique( |
34 new RasterizeAndRecordBenchmark(std::move(value), callback)); | 35 new RasterizeAndRecordBenchmark(std::move(value), callback)); |
35 } else if (name == "unittest_only_benchmark") { | 36 } else if (name == "unittest_only_benchmark") { |
36 return make_scoped_ptr( | 37 return base::WrapUnique( |
37 new UnittestOnlyBenchmark(std::move(value), callback)); | 38 new UnittestOnlyBenchmark(std::move(value), callback)); |
38 } | 39 } |
39 return nullptr; | 40 return nullptr; |
40 } | 41 } |
41 | 42 |
42 } // namespace | 43 } // namespace |
43 | 44 |
44 MicroBenchmarkController::MicroBenchmarkController(LayerTreeHost* host) | 45 MicroBenchmarkController::MicroBenchmarkController(LayerTreeHost* host) |
45 : host_(host), | 46 : host_(host), |
46 main_controller_task_runner_(base::ThreadTaskRunnerHandle::IsSet() | 47 main_controller_task_runner_(base::ThreadTaskRunnerHandle::IsSet() |
47 ? base::ThreadTaskRunnerHandle::Get() | 48 ? base::ThreadTaskRunnerHandle::Get() |
48 : nullptr) { | 49 : nullptr) { |
49 DCHECK(host_); | 50 DCHECK(host_); |
50 } | 51 } |
51 | 52 |
52 MicroBenchmarkController::~MicroBenchmarkController() {} | 53 MicroBenchmarkController::~MicroBenchmarkController() {} |
53 | 54 |
54 int MicroBenchmarkController::ScheduleRun( | 55 int MicroBenchmarkController::ScheduleRun( |
55 const std::string& micro_benchmark_name, | 56 const std::string& micro_benchmark_name, |
56 scoped_ptr<base::Value> value, | 57 std::unique_ptr<base::Value> value, |
57 const MicroBenchmark::DoneCallback& callback) { | 58 const MicroBenchmark::DoneCallback& callback) { |
58 scoped_ptr<MicroBenchmark> benchmark = | 59 std::unique_ptr<MicroBenchmark> benchmark = |
59 CreateBenchmark(micro_benchmark_name, std::move(value), callback); | 60 CreateBenchmark(micro_benchmark_name, std::move(value), callback); |
60 if (benchmark.get()) { | 61 if (benchmark.get()) { |
61 int id = GetNextIdAndIncrement(); | 62 int id = GetNextIdAndIncrement(); |
62 benchmark->set_id(id); | 63 benchmark->set_id(id); |
63 benchmarks_.push_back(std::move(benchmark)); | 64 benchmarks_.push_back(std::move(benchmark)); |
64 host_->SetNeedsCommit(); | 65 host_->SetNeedsCommit(); |
65 return id; | 66 return id; |
66 } | 67 } |
67 return 0; | 68 return 0; |
68 } | 69 } |
69 | 70 |
70 int MicroBenchmarkController::GetNextIdAndIncrement() { | 71 int MicroBenchmarkController::GetNextIdAndIncrement() { |
71 int id = next_id_++; | 72 int id = next_id_++; |
72 // Wrap around to 1 if we overflow (very unlikely). | 73 // Wrap around to 1 if we overflow (very unlikely). |
73 if (next_id_ == std::numeric_limits<int>::max()) | 74 if (next_id_ == std::numeric_limits<int>::max()) |
74 next_id_ = 1; | 75 next_id_ = 1; |
75 return id; | 76 return id; |
76 } | 77 } |
77 | 78 |
78 bool MicroBenchmarkController::SendMessage(int id, | 79 bool MicroBenchmarkController::SendMessage(int id, |
79 scoped_ptr<base::Value> value) { | 80 std::unique_ptr<base::Value> value) { |
80 auto it = std::find_if(benchmarks_.begin(), benchmarks_.end(), | 81 auto it = |
81 [id](const scoped_ptr<MicroBenchmark>& benchmark) { | 82 std::find_if(benchmarks_.begin(), benchmarks_.end(), |
82 return benchmark->id() == id; | 83 [id](const std::unique_ptr<MicroBenchmark>& benchmark) { |
83 }); | 84 return benchmark->id() == id; |
| 85 }); |
84 if (it == benchmarks_.end()) | 86 if (it == benchmarks_.end()) |
85 return false; | 87 return false; |
86 return (*it)->ProcessMessage(std::move(value)); | 88 return (*it)->ProcessMessage(std::move(value)); |
87 } | 89 } |
88 | 90 |
89 void MicroBenchmarkController::ScheduleImplBenchmarks( | 91 void MicroBenchmarkController::ScheduleImplBenchmarks( |
90 LayerTreeHostImpl* host_impl) { | 92 LayerTreeHostImpl* host_impl) { |
91 for (const auto& benchmark : benchmarks_) { | 93 for (const auto& benchmark : benchmarks_) { |
92 scoped_ptr<MicroBenchmarkImpl> benchmark_impl; | 94 std::unique_ptr<MicroBenchmarkImpl> benchmark_impl; |
93 if (!benchmark->ProcessedForBenchmarkImpl()) { | 95 if (!benchmark->ProcessedForBenchmarkImpl()) { |
94 benchmark_impl = | 96 benchmark_impl = |
95 benchmark->GetBenchmarkImpl(main_controller_task_runner_); | 97 benchmark->GetBenchmarkImpl(main_controller_task_runner_); |
96 } | 98 } |
97 | 99 |
98 if (benchmark_impl.get()) | 100 if (benchmark_impl.get()) |
99 host_impl->ScheduleMicroBenchmark(std::move(benchmark_impl)); | 101 host_impl->ScheduleMicroBenchmark(std::move(benchmark_impl)); |
100 } | 102 } |
101 } | 103 } |
102 | 104 |
103 void MicroBenchmarkController::DidUpdateLayers() { | 105 void MicroBenchmarkController::DidUpdateLayers() { |
104 for (const auto& benchmark : benchmarks_) { | 106 for (const auto& benchmark : benchmarks_) { |
105 if (!benchmark->IsDone()) | 107 if (!benchmark->IsDone()) |
106 benchmark->DidUpdateLayers(host_); | 108 benchmark->DidUpdateLayers(host_); |
107 } | 109 } |
108 | 110 |
109 CleanUpFinishedBenchmarks(); | 111 CleanUpFinishedBenchmarks(); |
110 } | 112 } |
111 | 113 |
112 void MicroBenchmarkController::CleanUpFinishedBenchmarks() { | 114 void MicroBenchmarkController::CleanUpFinishedBenchmarks() { |
113 benchmarks_.erase( | 115 benchmarks_.erase( |
114 std::remove_if(benchmarks_.begin(), benchmarks_.end(), | 116 std::remove_if(benchmarks_.begin(), benchmarks_.end(), |
115 [](const scoped_ptr<MicroBenchmark>& benchmark) { | 117 [](const std::unique_ptr<MicroBenchmark>& benchmark) { |
116 return benchmark->IsDone(); | 118 return benchmark->IsDone(); |
117 }), | 119 }), |
118 benchmarks_.end()); | 120 benchmarks_.end()); |
119 } | 121 } |
120 | 122 |
121 } // namespace cc | 123 } // namespace cc |
OLD | NEW |