summaryrefslogtreecommitdiffstats
path: root/cc/debug
diff options
context:
space:
mode:
authorvmpstr@chromium.org <vmpstr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-11 13:46:05 +0000
committervmpstr@chromium.org <vmpstr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-11 13:46:05 +0000
commit965240623cc2b3554c77f5d2ae7bac47a9c0af66 (patch)
tree1498460b0aec46be8de2c5dda1f2eb52033f1acf /cc/debug
parent3658534f9be85c5e5c2ea071ec21c0b1f3021728 (diff)
downloadchromium_src-965240623cc2b3554c77f5d2ae7bac47a9c0af66.zip
chromium_src-965240623cc2b3554c77f5d2ae7bac47a9c0af66.tar.gz
chromium_src-965240623cc2b3554c77f5d2ae7bac47a9c0af66.tar.bz2
cc: Add MicroBenchmarkController.
This patch adds a MicroBenchmark base class along with the MicroBenchmarkController. The idea of these classes is to be able to run benchmarks on real trees. That is, we would be able to inject benchmarking code into regular operations on the tree. The plumbing is going into a separate patch, just so each piece can be inspected separately. The general idea is the following. - The controller would live on the LayerTreeHost. - Gpu benchmarking extension would get access to it and schedule whatever benchmark is specified from javascript. For this reason, we decided to keep std::string as a parameter to ScheduleRun, instead of an enum - The benchmark would then use DidUpdateLayers callback to run the benchmark. Note that there are a couple of empty implementation virtual functions, but together with the plumbing patch, it should hopefully make sense. R=enne@chromium.org,nduca@chromium.org Review URL: https://codereview.chromium.org/26585002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@228177 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/debug')
-rw-r--r--cc/debug/micro_benchmark.cc33
-rw-r--r--cc/debug/micro_benchmark.h43
-rw-r--r--cc/debug/micro_benchmark_controller.cc73
-rw-r--r--cc/debug/micro_benchmark_controller.h45
4 files changed, 194 insertions, 0 deletions
diff --git a/cc/debug/micro_benchmark.cc b/cc/debug/micro_benchmark.cc
new file mode 100644
index 0000000..fe9bf97
--- /dev/null
+++ b/cc/debug/micro_benchmark.cc
@@ -0,0 +1,33 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/debug/micro_benchmark.h"
+
+#include "base/callback.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/values.h"
+
+namespace cc {
+
+MicroBenchmark::MicroBenchmark(const DoneCallback& callback)
+ : callback_(callback) {}
+
+MicroBenchmark::~MicroBenchmark() {}
+
+bool MicroBenchmark::IsDone() const {
+ return is_done_;
+}
+
+void MicroBenchmark::DidUpdateLayers(LayerTreeHost* host) {}
+
+void MicroBenchmark::NotifyDone(scoped_ptr<base::Value> result) {
+ callback_.Run(result.Pass());
+ is_done_ = true;
+}
+
+void MicroBenchmark::RunOnLayer(Layer* layer) {}
+
+void MicroBenchmark::RunOnLayer(PictureLayer* layer) {}
+
+} // namespace cc
diff --git a/cc/debug/micro_benchmark.h b/cc/debug/micro_benchmark.h
new file mode 100644
index 0000000..92c9b75
--- /dev/null
+++ b/cc/debug/micro_benchmark.h
@@ -0,0 +1,43 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CC_DEBUG_MICRO_BENCHMARK_H_
+#define CC_DEBUG_MICRO_BENCHMARK_H_
+
+#include "base/callback.h"
+#include "base/memory/scoped_ptr.h"
+
+namespace base {
+class Value;
+} // namespace base
+
+namespace cc {
+
+class LayerTreeHost;
+class Layer;
+class PictureLayer;
+class MicroBenchmark {
+ public:
+ typedef base::Callback<void(scoped_ptr<base::Value>)> DoneCallback;
+
+ explicit MicroBenchmark(const DoneCallback& callback);
+ virtual ~MicroBenchmark();
+
+ bool IsDone() const;
+ virtual void DidUpdateLayers(LayerTreeHost* host);
+
+ virtual void RunOnLayer(Layer* layer);
+ virtual void RunOnLayer(PictureLayer* layer);
+
+ protected:
+ void NotifyDone(scoped_ptr<base::Value> result);
+
+ private:
+ DoneCallback callback_;
+ bool is_done_;
+};
+
+} // namespace cc
+
+#endif // CC_DEBUG_MICRO_BENCHMARK_H_
diff --git a/cc/debug/micro_benchmark_controller.cc b/cc/debug/micro_benchmark_controller.cc
new file mode 100644
index 0000000..35b4585
--- /dev/null
+++ b/cc/debug/micro_benchmark_controller.cc
@@ -0,0 +1,73 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/debug/micro_benchmark_controller.h"
+
+#include <string>
+
+#include "base/callback.h"
+#include "base/values.h"
+#include "cc/trees/layer_tree_host.h"
+
+namespace cc {
+
+namespace {
+
+scoped_ptr<MicroBenchmark> CreateBenchmark(
+ const std::string& name,
+ const MicroBenchmark::DoneCallback& callback) {
+ // TODO(vmpstr): Add benchmarks.
+ return scoped_ptr<MicroBenchmark>();
+}
+
+class IsDonePredicate {
+ public:
+ typedef const MicroBenchmark* argument_type;
+ typedef bool result_type;
+
+ result_type operator()(argument_type benchmark) const {
+ return benchmark->IsDone();
+ }
+};
+
+} // namespace
+
+MicroBenchmarkController::MicroBenchmarkController(LayerTreeHost* host)
+ : host_(host) {
+ DCHECK(host_);
+}
+
+MicroBenchmarkController::~MicroBenchmarkController() {}
+
+bool MicroBenchmarkController::ScheduleRun(
+ const std::string& micro_benchmark_name,
+ const MicroBenchmark::DoneCallback& callback) {
+ scoped_ptr<MicroBenchmark> benchmark =
+ CreateBenchmark(micro_benchmark_name, callback);
+ if (benchmark.get()) {
+ benchmarks_.push_back(benchmark.Pass());
+ host_->SetNeedsCommit();
+ return true;
+ }
+ return false;
+}
+
+void MicroBenchmarkController::DidUpdateLayers() {
+ for (ScopedPtrVector<MicroBenchmark>::iterator it = benchmarks_.begin();
+ it != benchmarks_.end();
+ ++it) {
+ DCHECK(!(*it)->IsDone());
+ (*it)->DidUpdateLayers(host_);
+ }
+
+ CleanUpFinishedBenchmarks();
+}
+
+void MicroBenchmarkController::CleanUpFinishedBenchmarks() {
+ benchmarks_.erase(
+ benchmarks_.partition(std::not1(IsDonePredicate())),
+ benchmarks_.end());
+}
+
+} // namespace cc
diff --git a/cc/debug/micro_benchmark_controller.h b/cc/debug/micro_benchmark_controller.h
new file mode 100644
index 0000000..0a21c24
--- /dev/null
+++ b/cc/debug/micro_benchmark_controller.h
@@ -0,0 +1,45 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CC_DEBUG_MICRO_BENCHMARK_CONTROLLER_H_
+#define CC_DEBUG_MICRO_BENCHMARK_CONTROLLER_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/callback.h"
+#include "cc/base/scoped_ptr_vector.h"
+#include "cc/debug/micro_benchmark.h"
+
+namespace base {
+class Value;
+} // namespace base
+
+namespace cc {
+
+class LayerTreeHost;
+class Layer;
+class PictureLayer;
+class MicroBenchmarkController {
+ public:
+ explicit MicroBenchmarkController(LayerTreeHost* host);
+ ~MicroBenchmarkController();
+
+ void DidUpdateLayers();
+
+ bool ScheduleRun(const std::string& micro_benchmark_name,
+ const MicroBenchmark::DoneCallback& callback);
+
+ private:
+ void CleanUpFinishedBenchmarks();
+
+ LayerTreeHost* host_;
+ ScopedPtrVector<MicroBenchmark> benchmarks_;
+
+ DISALLOW_COPY_AND_ASSIGN(MicroBenchmarkController);
+};
+
+} // namespace cc
+
+#endif // CC_DEBUG_MICRO_BENCHMARK_CONTROLLER_H_