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

Unified 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, 7 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 side-by-side diff with in-line comments
Download patch
Index: cc/debug/micro_benchmark_controller.cc
diff --git a/cc/debug/micro_benchmark_controller.cc b/cc/debug/micro_benchmark_controller.cc
index 7d9025c1c42103dc40f9499fc2b467ca8b827460..f6df0f6be19ac20aa997f0b9d2f7aece8086cec2 100644
--- a/cc/debug/micro_benchmark_controller.cc
+++ b/cc/debug/micro_benchmark_controller.cc
@@ -4,6 +4,7 @@
#include "cc/debug/micro_benchmark_controller.h"
+#include <limits>
#include <string>
#include "base/callback.h"
@@ -17,6 +18,8 @@
namespace cc {
+int MicroBenchmarkController::next_id_ = 1;
+
namespace {
scoped_ptr<MicroBenchmark> CreateBenchmark(
@@ -56,16 +59,37 @@ MicroBenchmarkController::MicroBenchmarkController(LayerTreeHost* host)
MicroBenchmarkController::~MicroBenchmarkController() {}
-bool MicroBenchmarkController::ScheduleRun(
+int MicroBenchmarkController::ScheduleRun(
const std::string& micro_benchmark_name,
scoped_ptr<base::Value> value,
const MicroBenchmark::DoneCallback& callback) {
scoped_ptr<MicroBenchmark> benchmark =
CreateBenchmark(micro_benchmark_name, value.Pass(), callback);
if (benchmark.get()) {
+ int id = GetNextIdAndIncrement();
+ benchmark->set_id(id);
benchmarks_.push_back(benchmark.Pass());
host_->SetNeedsCommit();
- return true;
+ return id;
+ }
+ return 0;
+}
+
+int MicroBenchmarkController::GetNextIdAndIncrement() {
+ int id = next_id_++;
+ // Wrap around to 1 if we overflow (very unlikely).
+ if (next_id_ == std::numeric_limits<int>::max())
+ next_id_ = 1;
+ return id;
+}
+
+bool MicroBenchmarkController::SendMessage(int id,
+ scoped_ptr<base::Value> value) {
+ for (ScopedPtrVector<MicroBenchmark>::iterator it = benchmarks_.begin();
+ it != benchmarks_.end();
+ ++it) {
+ if ((*it)->id() == id)
+ return (*it)->ProcessMessage(value.Pass());
}
return false;
}

Powered by Google App Engine
This is Rietveld 408576698