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

Side by Side 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, 4 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/gpu/gpu_benchmarking_extension.h" 5 #include "content/renderer/gpu/gpu_benchmarking_extension.h"
6
7 #include <string>
8
9 #include "base/memory/scoped_vector.h"
10 #include "content/public/renderer/render_thread.h"
11 #include "content/renderer/all_rendering_benchmarks.h"
12 #include "content/renderer/rendering_benchmark.h"
13 #include "content/renderer/rendering_benchmark_results.h"
6 #include "content/renderer/render_view_impl.h" 14 #include "content/renderer/render_view_impl.h"
7 #include "third_party/WebKit/Source/Platform/chromium/public/WebRenderingStats.h " 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebRenderingStats.h "
8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewBenchmarkSuppo rt.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
11 #include "v8/include/v8.h" 19 #include "v8/include/v8.h"
12 20
13 using WebKit::WebFrame; 21 using WebKit::WebFrame;
22 using WebKit::WebPrivatePtr;
23 using WebKit::WebViewBenchmarkSupport;
14 using WebKit::WebRenderingStats; 24 using WebKit::WebRenderingStats;
15 using WebKit::WebView; 25 using WebKit::WebView;
16 26
17 const char kGpuBenchmarkingExtensionName[] = "v8/GpuBenchmarking"; 27 const char kGpuBenchmarkingExtensionName[] = "v8/GpuBenchmarking";
18 28
19 using WebKit::WebFrame; 29 using WebKit::WebFrame;
20 using WebKit::WebView; 30 using WebKit::WebView;
21 31
22 namespace content { 32 namespace content {
23 33
34 // Benchmark results object that populates a v8 array.
35 class V8BenchmarkResults : public content::RenderingBenchmarkResults {
36 public:
37 explicit V8BenchmarkResults()
38 : results_array_(v8::Array::New(0)) { }
39 virtual ~V8BenchmarkResults() {}
40
41 void AddResult(const std::string& benchmark_name,
42 const std::string& result_name,
43 const std::string& result_unit,
44 double result) {
45 v8::Handle<v8::Object> result_object = v8::Object::New();
46 result_object->Set(v8::String::New("benchmarkName", 13),
47 v8::String::New(benchmark_name.c_str(), -1));
48 result_object->Set(v8::String::New("resultName", 10),
49 v8::String::New(result_name.c_str(), -1));
50 result_object->Set(v8::String::New("resultUnit", 10),
51 v8::String::New(result_unit.c_str(), -1));
52 result_object->Set(v8::String::New("result", 6), v8::Number::New(result));
53
54 results_array_->Set(results_array_->Length(), result_object);
55 }
56
57 v8::Handle<v8::Array> results_array() {
58 return results_array_;
59 }
60
61 private:
62 v8::Handle<v8::Array> results_array_;
63 };
64
24 class GpuBenchmarkingWrapper : public v8::Extension { 65 class GpuBenchmarkingWrapper : public v8::Extension {
25 public: 66 public:
26 GpuBenchmarkingWrapper() : 67 GpuBenchmarkingWrapper() :
27 v8::Extension(kGpuBenchmarkingExtensionName, 68 v8::Extension(kGpuBenchmarkingExtensionName,
28 "if (typeof(chrome) == 'undefined') {" 69 "if (typeof(chrome) == 'undefined') {"
29 " chrome = {};" 70 " chrome = {};"
30 "};" 71 "};"
31 "if (typeof(chrome.gpuBenchmarking) == 'undefined') {" 72 "if (typeof(chrome.gpuBenchmarking) == 'undefined') {"
32 " chrome.gpuBenchmarking = {};" 73 " chrome.gpuBenchmarking = {};"
33 "};" 74 "};"
34 "chrome.gpuBenchmarking.renderingStats = function() {" 75 "chrome.gpuBenchmarking.renderingStats = function() {"
35 " native function GetRenderingStats();" 76 " native function GetRenderingStats();"
36 " return GetRenderingStats();" 77 " return GetRenderingStats();"
37 "};" 78 "};"
38 "chrome.gpuBenchmarking.beginSmoothScrollDown = " 79 "chrome.gpuBenchmarking.beginSmoothScrollDown = "
39 " function(scroll_far) {" 80 " function(scroll_far) {"
40 " scroll_far = scroll_far || false;" 81 " scroll_far = scroll_far || false;"
41 " native function BeginSmoothScroll();" 82 " native function BeginSmoothScroll();"
42 " return BeginSmoothScroll(true, scroll_far);" 83 " return BeginSmoothScroll(true, scroll_far);"
43 "};" 84 "};"
44 "chrome.gpuBenchmarking.beginSmoothScrollUp = function(scroll_far) {" 85 "chrome.gpuBenchmarking.beginSmoothScrollUp = function(scroll_far) {"
45 " scroll_far = scroll_far || false;" 86 " scroll_far = scroll_far || false;"
46 " native function BeginSmoothScroll();" 87 " native function BeginSmoothScroll();"
47 " return BeginSmoothScroll(false, scroll_far);" 88 " return BeginSmoothScroll(false, scroll_far);"
89 "};"
90 "chrome.gpuBenchmarking.runRenderingBenchmarks = function(filter) {"
91 " native function RunRenderingBenchmarks();"
92 " return RunRenderingBenchmarks(filter);"
48 "};") {} 93 "};") {}
49 94
50 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( 95 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
51 v8::Handle<v8::String> name) { 96 v8::Handle<v8::String> name) {
52 if (name->Equals(v8::String::New("GetRenderingStats"))) 97 if (name->Equals(v8::String::New("GetRenderingStats")))
53 return v8::FunctionTemplate::New(GetRenderingStats); 98 return v8::FunctionTemplate::New(GetRenderingStats);
54 if (name->Equals(v8::String::New("BeginSmoothScroll"))) 99 if (name->Equals(v8::String::New("BeginSmoothScroll")))
55 return v8::FunctionTemplate::New(BeginSmoothScroll); 100 return v8::FunctionTemplate::New(BeginSmoothScroll);
101 if (name->Equals(v8::String::New("RunRenderingBenchmarks")))
102 return v8::FunctionTemplate::New(RunRenderingBenchmarks);
56 103
57 return v8::Handle<v8::FunctionTemplate>(); 104 return v8::Handle<v8::FunctionTemplate>();
58 } 105 }
59 106
60 static v8::Handle<v8::Value> GetRenderingStats(const v8::Arguments& args) { 107 static v8::Handle<v8::Value> GetRenderingStats(const v8::Arguments& args) {
61 WebFrame* web_frame = WebFrame::frameForEnteredContext(); 108 WebFrame* web_frame = WebFrame::frameForEnteredContext();
62 if (!web_frame) 109 if (!web_frame)
63 return v8::Undefined(); 110 return v8::Undefined();
64 111
65 WebView* web_view = web_frame->view(); 112 WebView* web_view = web_frame->view();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 155
109 if (args.Length() != 2 || !args[0]->IsBoolean() || !args[1]->IsBoolean()) 156 if (args.Length() != 2 || !args[0]->IsBoolean() || !args[1]->IsBoolean())
110 return v8::False(); 157 return v8::False();
111 158
112 bool scroll_down = args[0]->BooleanValue(); 159 bool scroll_down = args[0]->BooleanValue();
113 bool scroll_far = args[1]->BooleanValue(); 160 bool scroll_far = args[1]->BooleanValue();
114 161
115 render_view_impl->BeginSmoothScroll(scroll_down, scroll_far); 162 render_view_impl->BeginSmoothScroll(scroll_down, scroll_far);
116 return v8::True(); 163 return v8::True();
117 } 164 }
165
166 static v8::Handle<v8::Value> RunRenderingBenchmarks(
167 const v8::Arguments& args) {
168 // For our name filter, the argument can be undefined or null to run
169 // all benchmarks, or a string for filtering by name.
170 if (!args.Length() ||
171 (!args[0]->IsString() &&
172 !(args[0]->IsNull() || args[0]->IsUndefined()))) {
173 return v8::Undefined();
174 }
175
176 std::string name_filter;
177 if (args[0]->IsNull() || args[0]->IsUndefined()) {
178 name_filter = "";
179 } else {
180 char filter[256];
181 args[0]->ToString()->WriteAscii(filter, 0, sizeof(filter)-1);
182 name_filter = std::string(filter);
183 }
184
185 WebFrame* web_frame = WebFrame::frameForEnteredContext();
186 if (!web_frame)
187 return v8::Undefined();
188
189 WebView* web_view = web_frame->view();
190 if (!web_view)
191 return v8::Undefined();
192
193 WebViewBenchmarkSupport* support = web_view->benchmarkSupport();
194 if (!support)
195 return v8::Undefined();
196
197 ScopedVector<RenderingBenchmark> benchmarks = AllRenderingBenchmarks();
198
199 V8BenchmarkResults results;
200 ScopedVector<RenderingBenchmark>::const_iterator it;
201 for (it = benchmarks.begin(); it != benchmarks.end(); it++) {
202 RenderingBenchmark* benchmark = *it;
203 const std::string& name = benchmark->name();
204 if (name_filter != "" &&
205 std::string::npos == name.find(name_filter)) {
206 continue;
207 }
208 benchmark->SetUp(support);
209 benchmark->Run(&results, support);
210 benchmark->TearDown(support);
211 }
212
213 return results.results_array();
214 }
118 }; 215 };
119 216
120 v8::Extension* GpuBenchmarkingExtension::Get() { 217 v8::Extension* GpuBenchmarkingExtension::Get() {
121 return new GpuBenchmarkingWrapper(); 218 return new GpuBenchmarkingWrapper();
122 } 219 }
123 220
124 } // namespace content 221 } // namespace content
OLDNEW
« 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