Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / cc / debug / micro_benchmark_controller.cc
blob7d9025c1c42103dc40f9499fc2b467ca8b827460
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"
7 #include <string>
9 #include "base/callback.h"
10 #include "base/message_loop/message_loop_proxy.h"
11 #include "base/values.h"
12 #include "cc/debug/picture_record_benchmark.h"
13 #include "cc/debug/rasterize_and_record_benchmark.h"
14 #include "cc/debug/unittest_only_benchmark.h"
15 #include "cc/trees/layer_tree_host.h"
16 #include "cc/trees/layer_tree_host_impl.h"
18 namespace cc {
20 namespace {
22 scoped_ptr<MicroBenchmark> CreateBenchmark(
23 const std::string& name,
24 scoped_ptr<base::Value> value,
25 const MicroBenchmark::DoneCallback& callback) {
26 if (name == "picture_record_benchmark") {
27 return scoped_ptr<MicroBenchmark>(
28 new PictureRecordBenchmark(value.Pass(), callback));
29 } else if (name == "rasterize_and_record_benchmark") {
30 return scoped_ptr<MicroBenchmark>(
31 new RasterizeAndRecordBenchmark(value.Pass(), callback));
32 } else if (name == "unittest_only_benchmark") {
33 return scoped_ptr<MicroBenchmark>(
34 new UnittestOnlyBenchmark(value.Pass(), callback));
36 return scoped_ptr<MicroBenchmark>();
39 class IsDonePredicate {
40 public:
41 typedef const MicroBenchmark* argument_type;
42 typedef bool result_type;
44 result_type operator()(argument_type benchmark) const {
45 return benchmark->IsDone();
49 } // namespace
51 MicroBenchmarkController::MicroBenchmarkController(LayerTreeHost* host)
52 : host_(host),
53 main_controller_message_loop_(base::MessageLoopProxy::current().get()) {
54 DCHECK(host_);
57 MicroBenchmarkController::~MicroBenchmarkController() {}
59 bool MicroBenchmarkController::ScheduleRun(
60 const std::string& micro_benchmark_name,
61 scoped_ptr<base::Value> value,
62 const MicroBenchmark::DoneCallback& callback) {
63 scoped_ptr<MicroBenchmark> benchmark =
64 CreateBenchmark(micro_benchmark_name, value.Pass(), callback);
65 if (benchmark.get()) {
66 benchmarks_.push_back(benchmark.Pass());
67 host_->SetNeedsCommit();
68 return true;
70 return false;
73 void MicroBenchmarkController::ScheduleImplBenchmarks(
74 LayerTreeHostImpl* host_impl) {
75 for (ScopedPtrVector<MicroBenchmark>::iterator it = benchmarks_.begin();
76 it != benchmarks_.end();
77 ++it) {
78 scoped_ptr<MicroBenchmarkImpl> benchmark_impl;
79 if (!(*it)->ProcessedForBenchmarkImpl()) {
80 benchmark_impl =
81 (*it)->GetBenchmarkImpl(main_controller_message_loop_);
84 if (benchmark_impl.get())
85 host_impl->ScheduleMicroBenchmark(benchmark_impl.Pass());
89 void MicroBenchmarkController::DidUpdateLayers() {
90 for (ScopedPtrVector<MicroBenchmark>::iterator it = benchmarks_.begin();
91 it != benchmarks_.end();
92 ++it) {
93 if (!(*it)->IsDone())
94 (*it)->DidUpdateLayers(host_);
97 CleanUpFinishedBenchmarks();
100 void MicroBenchmarkController::CleanUpFinishedBenchmarks() {
101 benchmarks_.erase(
102 benchmarks_.partition(std::not1(IsDonePredicate())),
103 benchmarks_.end());
106 } // namespace cc