diff options
author | ernstm@chromium.org <ernstm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-30 05:31:51 +0000 |
---|---|---|
committer | ernstm@chromium.org <ernstm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-30 05:31:51 +0000 |
commit | 67e703e12d95897bb915d776006608f35bd25077 (patch) | |
tree | 4df402000d950777516ccd6eeeed15ed57ad5e61 /cc/debug | |
parent | f0785c60a1bc5797c74c69274ff6abe499949bbf (diff) | |
download | chromium_src-67e703e12d95897bb915d776006608f35bd25077.zip chromium_src-67e703e12d95897bb915d776006608f35bd25077.tar.gz chromium_src-67e703e12d95897bb915d776006608f35bd25077.tar.bz2 |
cc: Add message passing mechanism to micro benchmarking.
Add a mechansim to send messages to running micro benchmarks through the
GPU benchmarking extension. This will be used for example to shut down a
running micro benchmark from telemetry.
R=vmpstr@chromium.org,jamesr@chromium.org
BUG=376379
Review URL: https://codereview.chromium.org/300963004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273726 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/debug')
-rw-r--r-- | cc/debug/micro_benchmark.cc | 8 | ||||
-rw-r--r-- | cc/debug/micro_benchmark.h | 5 | ||||
-rw-r--r-- | cc/debug/micro_benchmark_controller.cc | 28 | ||||
-rw-r--r-- | cc/debug/micro_benchmark_controller.h | 11 | ||||
-rw-r--r-- | cc/debug/micro_benchmark_controller_unittest.cc | 63 | ||||
-rw-r--r-- | cc/debug/unittest_only_benchmark.cc | 12 | ||||
-rw-r--r-- | cc/debug/unittest_only_benchmark.h | 2 |
7 files changed, 106 insertions, 23 deletions
diff --git a/cc/debug/micro_benchmark.cc b/cc/debug/micro_benchmark.cc index 464d0cb..05c5c0d 100644 --- a/cc/debug/micro_benchmark.cc +++ b/cc/debug/micro_benchmark.cc @@ -16,7 +16,9 @@ namespace cc { MicroBenchmark::MicroBenchmark(const DoneCallback& callback) : callback_(callback), is_done_(false), - processed_for_benchmark_impl_(false) {} + processed_for_benchmark_impl_(false), + id_(0) { +} MicroBenchmark::~MicroBenchmark() {} @@ -35,6 +37,10 @@ void MicroBenchmark::RunOnLayer(Layer* layer) {} void MicroBenchmark::RunOnLayer(PictureLayer* layer) {} +bool MicroBenchmark::ProcessMessage(scoped_ptr<base::Value> value) { + return false; +} + bool MicroBenchmark::ProcessedForBenchmarkImpl() const { return processed_for_benchmark_impl_; } diff --git a/cc/debug/micro_benchmark.h b/cc/debug/micro_benchmark.h index f179fb9..1654c36 100644 --- a/cc/debug/micro_benchmark.h +++ b/cc/debug/micro_benchmark.h @@ -29,10 +29,14 @@ class CC_EXPORT MicroBenchmark { bool IsDone() const; virtual void DidUpdateLayers(LayerTreeHost* host); + int id() const { return id_; } + void set_id(int id) { id_ = id; } virtual void RunOnLayer(Layer* layer); virtual void RunOnLayer(PictureLayer* layer); + virtual bool ProcessMessage(scoped_ptr<base::Value> value); + bool ProcessedForBenchmarkImpl() const; scoped_ptr<MicroBenchmarkImpl> GetBenchmarkImpl( scoped_refptr<base::MessageLoopProxy> origin_loop); @@ -47,6 +51,7 @@ class CC_EXPORT MicroBenchmark { DoneCallback callback_; bool is_done_; bool processed_for_benchmark_impl_; + int id_; }; } // namespace cc diff --git a/cc/debug/micro_benchmark_controller.cc b/cc/debug/micro_benchmark_controller.cc index 7d9025c..f6df0f6 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; } diff --git a/cc/debug/micro_benchmark_controller.h b/cc/debug/micro_benchmark_controller.h index 7220dc1..88f6d9a 100644 --- a/cc/debug/micro_benchmark_controller.h +++ b/cc/debug/micro_benchmark_controller.h @@ -28,17 +28,22 @@ class CC_EXPORT MicroBenchmarkController { void DidUpdateLayers(); - bool ScheduleRun(const std::string& micro_benchmark_name, - scoped_ptr<base::Value> value, - const MicroBenchmark::DoneCallback& callback); + // Returns the id of the benchmark on success, 0 otherwise. + int ScheduleRun(const std::string& micro_benchmark_name, + scoped_ptr<base::Value> value, + const MicroBenchmark::DoneCallback& callback); + // Returns true if the message was successfully delivered and handled. + bool SendMessage(int id, scoped_ptr<base::Value> value); void ScheduleImplBenchmarks(LayerTreeHostImpl* host_impl); private: void CleanUpFinishedBenchmarks(); + int GetNextIdAndIncrement(); LayerTreeHost* host_; ScopedPtrVector<MicroBenchmark> benchmarks_; + static int next_id_; scoped_refptr<base::MessageLoopProxy> main_controller_message_loop_; DISALLOW_COPY_AND_ASSIGN(MicroBenchmarkController); diff --git a/cc/debug/micro_benchmark_controller_unittest.cc b/cc/debug/micro_benchmark_controller_unittest.cc index 9af2d8d..83faeab 100644 --- a/cc/debug/micro_benchmark_controller_unittest.cc +++ b/cc/debug/micro_benchmark_controller_unittest.cc @@ -49,26 +49,26 @@ void IncrementCallCount(int* count, scoped_ptr<base::Value> value) { } TEST_F(MicroBenchmarkControllerTest, ScheduleFail) { - bool result = layer_tree_host_->ScheduleMicroBenchmark( + int id = layer_tree_host_->ScheduleMicroBenchmark( "non_existant_benchmark", scoped_ptr<base::Value>(), base::Bind(&Noop)); - EXPECT_FALSE(result); + EXPECT_EQ(id, 0); } TEST_F(MicroBenchmarkControllerTest, CommitScheduled) { EXPECT_FALSE(layer_tree_host_->needs_commit()); - bool result = layer_tree_host_->ScheduleMicroBenchmark( + int id = layer_tree_host_->ScheduleMicroBenchmark( "unittest_only_benchmark", scoped_ptr<base::Value>(), base::Bind(&Noop)); - EXPECT_TRUE(result); + EXPECT_GT(id, 0); EXPECT_TRUE(layer_tree_host_->needs_commit()); } TEST_F(MicroBenchmarkControllerTest, BenchmarkRan) { int run_count = 0; - bool result = layer_tree_host_->ScheduleMicroBenchmark( + int id = layer_tree_host_->ScheduleMicroBenchmark( "unittest_only_benchmark", scoped_ptr<base::Value>(), base::Bind(&IncrementCallCount, base::Unretained(&run_count))); - EXPECT_TRUE(result); + EXPECT_GT(id, 0); scoped_ptr<ResourceUpdateQueue> queue(new ResourceUpdateQueue); layer_tree_host_->SetOutputSurfaceLostForTesting(false); @@ -79,16 +79,16 @@ TEST_F(MicroBenchmarkControllerTest, BenchmarkRan) { TEST_F(MicroBenchmarkControllerTest, MultipleBenchmarkRan) { int run_count = 0; - bool result = layer_tree_host_->ScheduleMicroBenchmark( + int id = layer_tree_host_->ScheduleMicroBenchmark( "unittest_only_benchmark", scoped_ptr<base::Value>(), base::Bind(&IncrementCallCount, base::Unretained(&run_count))); - EXPECT_TRUE(result); - result = layer_tree_host_->ScheduleMicroBenchmark( + EXPECT_GT(id, 0); + id = layer_tree_host_->ScheduleMicroBenchmark( "unittest_only_benchmark", scoped_ptr<base::Value>(), base::Bind(&IncrementCallCount, base::Unretained(&run_count))); - EXPECT_TRUE(result); + EXPECT_GT(id, 0); scoped_ptr<ResourceUpdateQueue> queue(new ResourceUpdateQueue); layer_tree_host_->SetOutputSurfaceLostForTesting(false); @@ -96,16 +96,16 @@ TEST_F(MicroBenchmarkControllerTest, MultipleBenchmarkRan) { EXPECT_EQ(2, run_count); - result = layer_tree_host_->ScheduleMicroBenchmark( + id = layer_tree_host_->ScheduleMicroBenchmark( "unittest_only_benchmark", scoped_ptr<base::Value>(), base::Bind(&IncrementCallCount, base::Unretained(&run_count))); - EXPECT_TRUE(result); - result = layer_tree_host_->ScheduleMicroBenchmark( + EXPECT_GT(id, 0); + id = layer_tree_host_->ScheduleMicroBenchmark( "unittest_only_benchmark", scoped_ptr<base::Value>(), base::Bind(&IncrementCallCount, base::Unretained(&run_count))); - EXPECT_TRUE(result); + EXPECT_GT(id, 0); layer_tree_host_->UpdateLayers(queue.get()); EXPECT_EQ(4, run_count); @@ -120,11 +120,11 @@ TEST_F(MicroBenchmarkControllerTest, BenchmarkImplRan) { settings->SetBoolean("run_benchmark_impl", true); // Schedule a main thread benchmark. - bool result = layer_tree_host_->ScheduleMicroBenchmark( + int id = layer_tree_host_->ScheduleMicroBenchmark( "unittest_only_benchmark", settings.PassAs<base::Value>(), base::Bind(&IncrementCallCount, base::Unretained(&run_count))); - EXPECT_TRUE(result); + EXPECT_GT(id, 0); // Schedule impl benchmarks. In production code, this is run in commit. layer_tree_host_->GetMicroBenchmarkController()->ScheduleImplBenchmarks( @@ -139,5 +139,36 @@ TEST_F(MicroBenchmarkControllerTest, BenchmarkImplRan) { EXPECT_EQ(1, run_count); } +TEST_F(MicroBenchmarkControllerTest, SendMessage) { + // Send valid message to invalid benchmark (id = 0) + scoped_ptr<base::DictionaryValue> message(new base::DictionaryValue); + message->SetBoolean("can_handle", true); + bool message_handled = layer_tree_host_->SendMessageToMicroBenchmark( + 0, message.PassAs<base::Value>()); + EXPECT_FALSE(message_handled); + + // Schedule a benchmark + int run_count = 0; + int id = layer_tree_host_->ScheduleMicroBenchmark( + "unittest_only_benchmark", + scoped_ptr<base::Value>(), + base::Bind(&IncrementCallCount, base::Unretained(&run_count))); + EXPECT_GT(id, 0); + + // Send valid message to valid benchmark + message = scoped_ptr<base::DictionaryValue>(new base::DictionaryValue); + message->SetBoolean("can_handle", true); + message_handled = layer_tree_host_->SendMessageToMicroBenchmark( + id, message.PassAs<base::Value>()); + EXPECT_TRUE(message_handled); + + // Send invalid message to valid benchmark + message = scoped_ptr<base::DictionaryValue>(new base::DictionaryValue); + message->SetBoolean("can_handle", false); + message_handled = layer_tree_host_->SendMessageToMicroBenchmark( + id, message.PassAs<base::Value>()); + EXPECT_FALSE(message_handled); +} + } // namespace } // namespace cc diff --git a/cc/debug/unittest_only_benchmark.cc b/cc/debug/unittest_only_benchmark.cc index 9c6b176..0f0694a 100644 --- a/cc/debug/unittest_only_benchmark.cc +++ b/cc/debug/unittest_only_benchmark.cc @@ -36,6 +36,18 @@ void UnittestOnlyBenchmark::DidUpdateLayers(LayerTreeHost* host) { NotifyDone(scoped_ptr<base::Value>()); } +bool UnittestOnlyBenchmark::ProcessMessage(scoped_ptr<base::Value> value) { + base::DictionaryValue* message = NULL; + value->GetAsDictionary(&message); + bool can_handle; + if (message->HasKey("can_handle")) { + message->GetBoolean("can_handle", &can_handle); + if (can_handle) + return true; + } + return false; +} + void UnittestOnlyBenchmark::RecordImplResults(scoped_ptr<base::Value> results) { NotifyDone(results.Pass()); } diff --git a/cc/debug/unittest_only_benchmark.h b/cc/debug/unittest_only_benchmark.h index 8331285..8b2c815 100644 --- a/cc/debug/unittest_only_benchmark.h +++ b/cc/debug/unittest_only_benchmark.h @@ -17,6 +17,7 @@ class CC_EXPORT UnittestOnlyBenchmark : public MicroBenchmark { virtual ~UnittestOnlyBenchmark(); virtual void DidUpdateLayers(LayerTreeHost* host) OVERRIDE; + virtual bool ProcessMessage(scoped_ptr<base::Value> value) OVERRIDE; protected: virtual scoped_ptr<MicroBenchmarkImpl> CreateBenchmarkImpl( @@ -32,4 +33,3 @@ class CC_EXPORT UnittestOnlyBenchmark : public MicroBenchmark { } // namespace cc #endif // CC_DEBUG_UNITTEST_ONLY_BENCHMARK_H_ - |