Chromium Code Reviews| 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 8590e1116b855eaadbe95d5ba3ac47d569435e58..86108cec25f4d1365a39e8161ea3ea41beb55dbf 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 <vector> |
| + |
| +#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,33 @@ using WebKit::WebView; |
| namespace content { |
| +// Benchmark results object that populates a v8 array. |
| +class V8BenchmarkResults : public content::RenderingBenchmarkResults { |
| + public: |
| + explicit V8BenchmarkResults(v8::Handle<v8::Array> results_array) |
|
nduca
2012/07/20 20:30:09
why not have the array inside here and have an acc
dmurph
2012/07/20 20:52:33
The results object doesn't own the array though, t
dmurph
2012/07/20 21:11:41
After discussion we realized v8 handles destructio
|
| + : results_array_(results_array) { } |
| + 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); |
| + } |
| + |
| + private: |
| + v8::Handle<v8::Array> results_array_; |
| +}; |
| + |
| class GpuBenchmarkingWrapper : public v8::Extension { |
| public: |
| GpuBenchmarkingWrapper() : |
| @@ -45,6 +82,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,7 +94,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); |
|
nduca
2012/07/20 20:30:09
i think there's a blank line after the ifs
dmurph
2012/07/20 20:52:33
Done.
|
| return v8::Handle<v8::FunctionTemplate>(); |
| } |
| @@ -103,6 +145,54 @@ 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 |
|
nduca
2012/07/20 20:30:09
// For
dmurph
2012/07/20 20:52:33
Done.
|
| + // all benchmarks, or a string for filtering by name |
| + if (!args.Length() || |
| + (!args[0]->IsString() && |
| + !(args[0]->IsNull() || args[0]->IsUndefined()))) |
|
piman
2012/07/20 20:35:35
nit: indent (! should be aligned with the one abov
dmurph
2012/07/20 21:19:13
Done.
|
| + return v8::Undefined(); |
| + |
| + WebFrame* web_frame = WebFrame::frameForEnteredContext(); |
| + if (!web_frame) |
| + return v8::Undefined(); |
| + |
| + WebView* web_view = web_frame->view(); |
| + if (!web_view) |
| + return v8::Undefined(); |
| + |
| + v8::Handle<v8::Array> resultsArray = v8::Array::New(0); |
| + V8BenchmarkResults results(resultsArray); |
|
nduca
2012/07/20 20:30:09
initialize the results array as late as you can. E
dmurph
2012/07/20 20:52:33
Done.
|
| + std::string name_filter; |
|
nduca
2012/07/20 20:30:09
how about moving the name_filter stuff up to where
dmurph
2012/07/20 20:52:33
Done.
|
| + 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); |
| + } |
| + |
| + WebViewBenchmarkSupport* support = |
| + web_view->benchmarkSupport(); |
| + std::vector<RenderingBenchmark*> benchmarks = AllRenderingBenchmarks(); |
| + |
| + std::vector<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)) { |
|
piman
2012/07/20 20:35:35
nit: indent (should be +4)
dmurph
2012/07/20 21:19:13
Done.
|
| + continue; |
| + } |
| + benchmark->SetUp(support); |
| + benchmark->Run(&results, support); |
| + benchmark->TearDown(support); |
| + } |
| + |
| + return resultsArray; |
| + } |
| }; |
| v8::Extension* GpuBenchmarkingExtension::Get() { |