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
3 // found in the LICENSE file.
5 #include "cc/debug/micro_benchmark_controller.h"
9 #include "base/callback.h"
10 #include "base/values.h"
11 #include "cc/debug/picture_record_benchmark.h"
12 #include "cc/debug/unittest_only_benchmark.h"
13 #include "cc/trees/layer_tree_host.h"
19 scoped_ptr
<MicroBenchmark
> CreateBenchmark(
20 const std::string
& name
,
21 scoped_ptr
<base::Value
> value
,
22 const MicroBenchmark::DoneCallback
& callback
) {
23 if (name
== "picture_record_benchmark") {
24 return scoped_ptr
<MicroBenchmark
>(
25 new PictureRecordBenchmark(value
.Pass(), callback
));
26 } else if (name
== "unittest_only_benchmark") {
27 return scoped_ptr
<MicroBenchmark
>(
28 new UnittestOnlyBenchmark(value
.Pass(), callback
));
30 return scoped_ptr
<MicroBenchmark
>();
33 class IsDonePredicate
{
35 typedef const MicroBenchmark
* argument_type
;
36 typedef bool result_type
;
38 result_type
operator()(argument_type benchmark
) const {
39 return benchmark
->IsDone();
45 MicroBenchmarkController::MicroBenchmarkController(LayerTreeHost
* host
)
50 MicroBenchmarkController::~MicroBenchmarkController() {}
52 bool MicroBenchmarkController::ScheduleRun(
53 const std::string
& micro_benchmark_name
,
54 scoped_ptr
<base::Value
> value
,
55 const MicroBenchmark::DoneCallback
& callback
) {
56 scoped_ptr
<MicroBenchmark
> benchmark
=
57 CreateBenchmark(micro_benchmark_name
, value
.Pass(), callback
);
58 if (benchmark
.get()) {
59 benchmarks_
.push_back(benchmark
.Pass());
60 host_
->SetNeedsCommit();
66 void MicroBenchmarkController::DidUpdateLayers() {
67 for (ScopedPtrVector
<MicroBenchmark
>::iterator it
= benchmarks_
.begin();
68 it
!= benchmarks_
.end();
70 DCHECK(!(*it
)->IsDone());
71 (*it
)->DidUpdateLayers(host_
);
74 CleanUpFinishedBenchmarks();
77 void MicroBenchmarkController::CleanUpFinishedBenchmarks() {
79 benchmarks_
.partition(std::not1(IsDonePredicate())),