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

Unified Diff: content/renderer/gpu/gpu_benchmarking_extension.cc

Issue 10537036: Added rendering benchmark javascript hook (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Refactorings for WebKit changes Created 8 years, 5 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
« no previous file with comments | « content/renderer/all_rendering_benchmarks.cc ('k') | content/renderer/rendering_benchmark.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/gpu/gpu_benchmarking_extension.cc
diff --git a/content/renderer/gpu/gpu_benchmarking_extension.cc b/content/renderer/gpu/gpu_benchmarking_extension.cc
index e7c61b0602e0c23ad07f07d7eb6bf32bc5458c9a..eeca8c59489f3c9e5ef2f8d2418e6ff9f4ba6ee5 100644
--- a/content/renderer/gpu/gpu_benchmarking_extension.cc
+++ b/content/renderer/gpu/gpu_benchmarking_extension.cc
@@ -3,14 +3,24 @@
// found in the LICENSE file.
#include "content/renderer/gpu/gpu_benchmarking_extension.h"
+
+#include <string>
+
+#include "base/memory/scoped_vector.h"
+#include "content/public/renderer/render_thread.h"
+#include "content/renderer/all_rendering_benchmarks.h"
+#include "content/renderer/rendering_benchmark.h"
+#include "content/renderer/rendering_benchmark_results.h"
#include "content/renderer/render_view_impl.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebRenderingStats.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebViewBenchmarkSupport.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
#include "v8/include/v8.h"
using WebKit::WebFrame;
+using WebKit::WebPrivatePtr;
+using WebKit::WebViewBenchmarkSupport;
using WebKit::WebRenderingStats;
using WebKit::WebView;
@@ -21,6 +31,37 @@ using WebKit::WebView;
namespace content {
+// Benchmark results object that populates a v8 array.
+class V8BenchmarkResults : public content::RenderingBenchmarkResults {
+ public:
+ explicit V8BenchmarkResults()
+ : results_array_(v8::Array::New(0)) { }
+ virtual ~V8BenchmarkResults() {}
+
+ void AddResult(const std::string& benchmark_name,
+ const std::string& result_name,
+ const std::string& result_unit,
+ double result) {
+ v8::Handle<v8::Object> result_object = v8::Object::New();
+ result_object->Set(v8::String::New("benchmarkName", 13),
+ v8::String::New(benchmark_name.c_str(), -1));
+ result_object->Set(v8::String::New("resultName", 10),
+ v8::String::New(result_name.c_str(), -1));
+ result_object->Set(v8::String::New("resultUnit", 10),
+ v8::String::New(result_unit.c_str(), -1));
+ result_object->Set(v8::String::New("result", 6), v8::Number::New(result));
+
+ results_array_->Set(results_array_->Length(), result_object);
+ }
+
+ v8::Handle<v8::Array> results_array() {
+ return results_array_;
+ }
+
+ private:
+ v8::Handle<v8::Array> results_array_;
+};
+
class GpuBenchmarkingWrapper : public v8::Extension {
public:
GpuBenchmarkingWrapper() :
@@ -45,6 +86,10 @@ class GpuBenchmarkingWrapper : public v8::Extension {
" scroll_far = scroll_far || false;"
" native function BeginSmoothScroll();"
" return BeginSmoothScroll(false, scroll_far);"
+ "};"
+ "chrome.gpuBenchmarking.runRenderingBenchmarks = function(filter) {"
+ " native function RunRenderingBenchmarks();"
+ " return RunRenderingBenchmarks(filter);"
"};") {}
virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
@@ -53,6 +98,8 @@ class GpuBenchmarkingWrapper : public v8::Extension {
return v8::FunctionTemplate::New(GetRenderingStats);
if (name->Equals(v8::String::New("BeginSmoothScroll")))
return v8::FunctionTemplate::New(BeginSmoothScroll);
+ if (name->Equals(v8::String::New("RunRenderingBenchmarks")))
+ return v8::FunctionTemplate::New(RunRenderingBenchmarks);
return v8::Handle<v8::FunctionTemplate>();
}
@@ -115,6 +162,56 @@ class GpuBenchmarkingWrapper : public v8::Extension {
render_view_impl->BeginSmoothScroll(scroll_down, scroll_far);
return v8::True();
}
+
+ static v8::Handle<v8::Value> RunRenderingBenchmarks(
+ const v8::Arguments& args) {
+ // For our name filter, the argument can be undefined or null to run
+ // all benchmarks, or a string for filtering by name.
+ if (!args.Length() ||
+ (!args[0]->IsString() &&
+ !(args[0]->IsNull() || args[0]->IsUndefined()))) {
+ return v8::Undefined();
+ }
+
+ std::string name_filter;
+ if (args[0]->IsNull() || args[0]->IsUndefined()) {
+ name_filter = "";
+ } else {
+ char filter[256];
+ args[0]->ToString()->WriteAscii(filter, 0, sizeof(filter)-1);
+ name_filter = std::string(filter);
+ }
+
+ WebFrame* web_frame = WebFrame::frameForEnteredContext();
+ if (!web_frame)
+ return v8::Undefined();
+
+ WebView* web_view = web_frame->view();
+ if (!web_view)
+ return v8::Undefined();
+
+ WebViewBenchmarkSupport* support = web_view->benchmarkSupport();
+ if (!support)
+ return v8::Undefined();
+
+ ScopedVector<RenderingBenchmark> benchmarks = AllRenderingBenchmarks();
+
+ V8BenchmarkResults results;
+ ScopedVector<RenderingBenchmark>::const_iterator it;
+ for (it = benchmarks.begin(); it != benchmarks.end(); it++) {
+ RenderingBenchmark* benchmark = *it;
+ const std::string& name = benchmark->name();
+ if (name_filter != "" &&
+ std::string::npos == name.find(name_filter)) {
+ continue;
+ }
+ benchmark->SetUp(support);
+ benchmark->Run(&results, support);
+ benchmark->TearDown(support);
+ }
+
+ return results.results_array();
+ }
};
v8::Extension* GpuBenchmarkingExtension::Get() {
« no previous file with comments | « content/renderer/all_rendering_benchmarks.cc ('k') | content/renderer/rendering_benchmark.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698