OLD | NEW |
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 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
13 #include "content/public/renderer/render_thread.h" | 13 #include "content/public/renderer/render_thread.h" |
14 #include "content/renderer/all_rendering_benchmarks.h" | 14 #include "content/renderer/all_rendering_benchmarks.h" |
15 #include "content/renderer/render_view_impl.h" | 15 #include "content/renderer/render_view_impl.h" |
16 #include "content/renderer/rendering_benchmark.h" | 16 #include "content/renderer/rendering_benchmark.h" |
17 #include "content/renderer/rendering_benchmark_results.h" | |
18 #include "third_party/skia/include/core/SkGraphics.h" | 17 #include "third_party/skia/include/core/SkGraphics.h" |
19 #include "third_party/skia/include/core/SkPicture.h" | 18 #include "third_party/skia/include/core/SkPicture.h" |
20 #include "third_party/skia/include/core/SkStream.h" | 19 #include "third_party/skia/include/core/SkStream.h" |
21 #include "third_party/WebKit/Source/Platform/chromium/public/WebRenderingStats.h
" | 20 #include "third_party/WebKit/Source/Platform/chromium/public/WebRenderingStats.h
" |
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewBenchmarkSuppo
rt.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewBenchmarkSuppo
rt.h" |
25 #include "v8/include/v8.h" | 24 #include "v8/include/v8.h" |
26 | 25 |
27 using WebKit::WebCanvas; | 26 using WebKit::WebCanvas; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 private: | 77 private: |
79 FilePath dirpath_; | 78 FilePath dirpath_; |
80 int layer_id_; | 79 int layer_id_; |
81 SkPicture picture_; | 80 SkPicture picture_; |
82 }; | 81 }; |
83 | 82 |
84 } // namespace | 83 } // namespace |
85 | 84 |
86 namespace content { | 85 namespace content { |
87 | 86 |
88 // Benchmark results object that populates a v8 array. | |
89 class V8BenchmarkResults : public content::RenderingBenchmarkResults { | |
90 public: | |
91 explicit V8BenchmarkResults() | |
92 : results_array_(v8::Array::New(0)) { } | |
93 virtual ~V8BenchmarkResults() {} | |
94 | |
95 void AddResult(const std::string& benchmark_name, | |
96 const std::string& result_name, | |
97 const std::string& result_unit, | |
98 double result) { | |
99 v8::Handle<v8::Object> result_object = v8::Object::New(); | |
100 result_object->Set(v8::String::New("benchmarkName", 13), | |
101 v8::String::New(benchmark_name.c_str(), -1)); | |
102 result_object->Set(v8::String::New("resultName", 10), | |
103 v8::String::New(result_name.c_str(), -1)); | |
104 result_object->Set(v8::String::New("resultUnit", 10), | |
105 v8::String::New(result_unit.c_str(), -1)); | |
106 result_object->Set(v8::String::New("result", 6), v8::Number::New(result)); | |
107 | |
108 results_array_->Set(results_array_->Length(), result_object); | |
109 } | |
110 | |
111 v8::Handle<v8::Array> results_array() { | |
112 return results_array_; | |
113 } | |
114 | |
115 private: | |
116 v8::Handle<v8::Array> results_array_; | |
117 }; | |
118 | |
119 class GpuBenchmarkingWrapper : public v8::Extension { | 87 class GpuBenchmarkingWrapper : public v8::Extension { |
120 public: | 88 public: |
121 GpuBenchmarkingWrapper() : | 89 GpuBenchmarkingWrapper() : |
122 v8::Extension(kGpuBenchmarkingExtensionName, | 90 v8::Extension(kGpuBenchmarkingExtensionName, |
123 "if (typeof(chrome) == 'undefined') {" | 91 "if (typeof(chrome) == 'undefined') {" |
124 " chrome = {};" | 92 " chrome = {};" |
125 "};" | 93 "};" |
126 "if (typeof(chrome.gpuBenchmarking) == 'undefined') {" | 94 "if (typeof(chrome.gpuBenchmarking) == 'undefined') {" |
127 " chrome.gpuBenchmarking = {};" | 95 " chrome.gpuBenchmarking = {};" |
128 "};" | 96 "};" |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 WebView* web_view = web_frame->view(); | 283 WebView* web_view = web_frame->view(); |
316 if (!web_view) | 284 if (!web_view) |
317 return v8::Undefined(); | 285 return v8::Undefined(); |
318 | 286 |
319 WebViewBenchmarkSupport* support = web_view->benchmarkSupport(); | 287 WebViewBenchmarkSupport* support = web_view->benchmarkSupport(); |
320 if (!support) | 288 if (!support) |
321 return v8::Undefined(); | 289 return v8::Undefined(); |
322 | 290 |
323 ScopedVector<RenderingBenchmark> benchmarks = AllRenderingBenchmarks(); | 291 ScopedVector<RenderingBenchmark> benchmarks = AllRenderingBenchmarks(); |
324 | 292 |
325 V8BenchmarkResults results; | 293 v8::Handle<v8::Array> results = v8::Array::New(0); |
326 ScopedVector<RenderingBenchmark>::const_iterator it; | 294 ScopedVector<RenderingBenchmark>::const_iterator it; |
327 for (it = benchmarks.begin(); it != benchmarks.end(); it++) { | 295 for (it = benchmarks.begin(); it != benchmarks.end(); it++) { |
328 RenderingBenchmark* benchmark = *it; | 296 RenderingBenchmark* benchmark = *it; |
329 const std::string& name = benchmark->name(); | 297 const std::string& name = benchmark->name(); |
330 if (name_filter != "" && | 298 if (name_filter != "" && |
331 std::string::npos == name.find(name_filter)) { | 299 std::string::npos == name.find(name_filter)) { |
332 continue; | 300 continue; |
333 } | 301 } |
334 benchmark->SetUp(support); | 302 benchmark->SetUp(support); |
335 benchmark->Run(&results, support); | 303 double result = benchmark->Run(support); |
336 benchmark->TearDown(support); | 304 benchmark->TearDown(support); |
| 305 |
| 306 v8::Handle<v8::Object> result_object = v8::Object::New(); |
| 307 result_object->Set(v8::String::New("benchmark", 9), |
| 308 v8::String::New(name.c_str(), -1)); |
| 309 result_object->Set(v8::String::New("result", 6), v8::Number::New(result)); |
| 310 results->Set(results->Length(), result_object); |
337 } | 311 } |
338 | 312 |
339 return results.results_array(); | 313 return results; |
340 } | 314 } |
341 }; | 315 }; |
342 | 316 |
343 v8::Extension* GpuBenchmarkingExtension::Get() { | 317 v8::Extension* GpuBenchmarkingExtension::Get() { |
344 return new GpuBenchmarkingWrapper(); | 318 return new GpuBenchmarkingWrapper(); |
345 } | 319 } |
346 | 320 |
347 } // namespace content | 321 } // namespace content |
OLD | NEW |