Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(363)

Side by Side Diff: cc/debug/micro_benchmark_controller.cc

Issue 300963004: cc: Add message passing mechanism to micro benchmarking. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix comments. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <string> 8 #include <string>
8 9
9 #include "base/callback.h" 10 #include "base/callback.h"
10 #include "base/message_loop/message_loop_proxy.h" 11 #include "base/message_loop/message_loop_proxy.h"
11 #include "base/values.h" 12 #include "base/values.h"
12 #include "cc/debug/picture_record_benchmark.h" 13 #include "cc/debug/picture_record_benchmark.h"
13 #include "cc/debug/rasterize_and_record_benchmark.h" 14 #include "cc/debug/rasterize_and_record_benchmark.h"
14 #include "cc/debug/unittest_only_benchmark.h" 15 #include "cc/debug/unittest_only_benchmark.h"
15 #include "cc/trees/layer_tree_host.h" 16 #include "cc/trees/layer_tree_host.h"
16 #include "cc/trees/layer_tree_host_impl.h" 17 #include "cc/trees/layer_tree_host_impl.h"
17 18
18 namespace cc { 19 namespace cc {
19 20
21 int MicroBenchmarkController::next_id_ = 1;
22
20 namespace { 23 namespace {
21 24
22 scoped_ptr<MicroBenchmark> CreateBenchmark( 25 scoped_ptr<MicroBenchmark> CreateBenchmark(
23 const std::string& name, 26 const std::string& name,
24 scoped_ptr<base::Value> value, 27 scoped_ptr<base::Value> value,
25 const MicroBenchmark::DoneCallback& callback) { 28 const MicroBenchmark::DoneCallback& callback) {
26 if (name == "picture_record_benchmark") { 29 if (name == "picture_record_benchmark") {
27 return scoped_ptr<MicroBenchmark>( 30 return scoped_ptr<MicroBenchmark>(
28 new PictureRecordBenchmark(value.Pass(), callback)); 31 new PictureRecordBenchmark(value.Pass(), callback));
29 } else if (name == "rasterize_and_record_benchmark") { 32 } else if (name == "rasterize_and_record_benchmark") {
(...skipping 19 matching lines...) Expand all
49 } // namespace 52 } // namespace
50 53
51 MicroBenchmarkController::MicroBenchmarkController(LayerTreeHost* host) 54 MicroBenchmarkController::MicroBenchmarkController(LayerTreeHost* host)
52 : host_(host), 55 : host_(host),
53 main_controller_message_loop_(base::MessageLoopProxy::current().get()) { 56 main_controller_message_loop_(base::MessageLoopProxy::current().get()) {
54 DCHECK(host_); 57 DCHECK(host_);
55 } 58 }
56 59
57 MicroBenchmarkController::~MicroBenchmarkController() {} 60 MicroBenchmarkController::~MicroBenchmarkController() {}
58 61
59 bool MicroBenchmarkController::ScheduleRun( 62 int MicroBenchmarkController::ScheduleRun(
60 const std::string& micro_benchmark_name, 63 const std::string& micro_benchmark_name,
61 scoped_ptr<base::Value> value, 64 scoped_ptr<base::Value> value,
62 const MicroBenchmark::DoneCallback& callback) { 65 const MicroBenchmark::DoneCallback& callback) {
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);
65 if (benchmark.get()) { 68 if (benchmark.get()) {
69 int id = GetNextIdAndIncrement();
70 benchmark->set_id(id);
66 benchmarks_.push_back(benchmark.Pass()); 71 benchmarks_.push_back(benchmark.Pass());
67 host_->SetNeedsCommit(); 72 host_->SetNeedsCommit();
68 return true; 73 return id;
74 }
75 return 0;
76 }
77
78 int MicroBenchmarkController::GetNextIdAndIncrement() {
79 int id = next_id_++;
80 // Wrap around to 1 if we overflow (very unlikely).
81 if (next_id_ == std::numeric_limits<int>::max())
82 next_id_ = 1;
83 return id;
84 }
85
86 bool MicroBenchmarkController::SendMessage(int id,
87 scoped_ptr<base::Value> value) {
88 for (ScopedPtrVector<MicroBenchmark>::iterator it = benchmarks_.begin();
89 it != benchmarks_.end();
90 ++it) {
91 if ((*it)->id() == id)
92 return (*it)->ProcessMessage(value.Pass());
69 } 93 }
70 return false; 94 return false;
71 } 95 }
72 96
73 void MicroBenchmarkController::ScheduleImplBenchmarks( 97 void MicroBenchmarkController::ScheduleImplBenchmarks(
74 LayerTreeHostImpl* host_impl) { 98 LayerTreeHostImpl* host_impl) {
75 for (ScopedPtrVector<MicroBenchmark>::iterator it = benchmarks_.begin(); 99 for (ScopedPtrVector<MicroBenchmark>::iterator it = benchmarks_.begin();
76 it != benchmarks_.end(); 100 it != benchmarks_.end();
77 ++it) { 101 ++it) {
78 scoped_ptr<MicroBenchmarkImpl> benchmark_impl; 102 scoped_ptr<MicroBenchmarkImpl> benchmark_impl;
(...skipping 18 matching lines...) Expand all
97 CleanUpFinishedBenchmarks(); 121 CleanUpFinishedBenchmarks();
98 } 122 }
99 123
100 void MicroBenchmarkController::CleanUpFinishedBenchmarks() { 124 void MicroBenchmarkController::CleanUpFinishedBenchmarks() {
101 benchmarks_.erase( 125 benchmarks_.erase(
102 benchmarks_.partition(std::not1(IsDonePredicate())), 126 benchmarks_.partition(std::not1(IsDonePredicate())),
103 benchmarks_.end()); 127 benchmarks_.end());
104 } 128 }
105 129
106 } // namespace cc 130 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698