Commit 31d3ae59 authored by dmurph@chromium.org's avatar dmurph@chromium.org

Added rendering benchmark javascript hook

Created json results store for returning results to browser
Includes name filter of rendering benchmarks

Review URL: https://chromiumcodereview.appspot.com/10537036

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149031 0039d316-1c4b-4281-b951-d872f2087c98
parent 0ed9486d
...@@ -47,6 +47,8 @@ ...@@ -47,6 +47,8 @@
'renderer/accessibility_node_serializer.h', 'renderer/accessibility_node_serializer.h',
'renderer/active_notification_tracker.cc', 'renderer/active_notification_tracker.cc',
'renderer/active_notification_tracker.h', 'renderer/active_notification_tracker.h',
'renderer/all_rendering_benchmarks.cc',
'renderer/all_rendering_benchmarks.h',
'renderer/android/address_detector.cc', 'renderer/android/address_detector.cc',
'renderer/android/address_detector.h', 'renderer/android/address_detector.h',
'renderer/android/content_detector.cc', 'renderer/android/content_detector.cc',
...@@ -227,6 +229,9 @@ ...@@ -227,6 +229,9 @@
'renderer/renderer_webcolorchooser_impl.h', 'renderer/renderer_webcolorchooser_impl.h',
'renderer/renderer_webkitplatformsupport_impl.cc', 'renderer/renderer_webkitplatformsupport_impl.cc',
'renderer/renderer_webkitplatformsupport_impl.h', 'renderer/renderer_webkitplatformsupport_impl.h',
'renderer/rendering_benchmark.cc',
'renderer/rendering_benchmark.h',
'renderer/rendering_benchmark_results.h',
'renderer/speech_recognition_dispatcher.cc', 'renderer/speech_recognition_dispatcher.cc',
'renderer/speech_recognition_dispatcher.h', 'renderer/speech_recognition_dispatcher.h',
'renderer/text_input_client_observer.cc', 'renderer/text_input_client_observer.cc',
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/renderer/all_rendering_benchmarks.h"
#include <string>
#include "base/bind.h"
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/time.h"
#include "content/renderer/rendering_benchmark.h"
#include "content/renderer/rendering_benchmark_results.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkDevice.h"
#include "third_party/skia/include/utils/SkNullCanvas.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebCanvas.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebViewBenchmarkSupport.h"
using base::TimeDelta;
using base::TimeTicks;
using WebKit::WebSize;
using WebKit::WebCanvas;
using WebKit::WebViewBenchmarkSupport;
namespace {
class CustomPaintBenchmark
: public content::RenderingBenchmark,
public WebViewBenchmarkSupport::PaintClient {
public:
CustomPaintBenchmark(const std::string& name,
WebViewBenchmarkSupport::PaintMode paint_mode)
: content::RenderingBenchmark(name),
paint_mode_(paint_mode) { }
virtual WebCanvas* willPaint(const WebSize& size) OVERRIDE {
WebCanvas* canvas = createCanvas(size);
before_time_ = TimeTicks::Now();
return canvas;
}
virtual void didPaint(WebCanvas* canvas) OVERRIDE {
paint_time_total_ += (TimeTicks::Now() - before_time_);
delete canvas;
}
virtual void Run(content::RenderingBenchmarkResults* results,
WebViewBenchmarkSupport* support) {
paint_time_total_ = TimeDelta();
support->paint(this, paint_mode_);
results->AddResult(name(),
"paintTime",
"s",
paint_time_total_.InSecondsF());
}
private:
virtual WebCanvas* createCanvas(const WebSize& size) = 0;
TimeTicks before_time_;
TimeDelta paint_time_total_;
const WebViewBenchmarkSupport::PaintMode paint_mode_;
};
class BitmapCanvasPaintBenchmark : public CustomPaintBenchmark {
public:
BitmapCanvasPaintBenchmark(const std::string& name,
WebViewBenchmarkSupport::PaintMode paint_mode)
: CustomPaintBenchmark(name, paint_mode) { }
private:
virtual WebCanvas* createCanvas(const WebSize& size) OVERRIDE {
SkDevice* device = new SkDevice(SkBitmap::kARGB_8888_Config,
size.width,
size.height,
false);
WebCanvas* canvas = new WebCanvas(device);
device->unref();
return canvas;
}
};
class NullCanvasPaintBenchmark : public CustomPaintBenchmark {
public:
NullCanvasPaintBenchmark(const std::string& name,
WebViewBenchmarkSupport::PaintMode paint_mode)
: CustomPaintBenchmark(name, paint_mode) { }
private:
virtual WebCanvas* createCanvas(const WebSize& size) OVERRIDE {
return SkCreateNullCanvas();
}
};
} // anonymous namespace
namespace content {
ScopedVector<RenderingBenchmark> AllRenderingBenchmarks() {
ScopedVector<RenderingBenchmark> benchmarks;
benchmarks.push_back(new BitmapCanvasPaintBenchmark(
"PaintEverythingToBitmap",
WebViewBenchmarkSupport::PaintModeEverything));
benchmarks.push_back(new NullCanvasPaintBenchmark(
"PaintEverythingToNullCanvas",
WebViewBenchmarkSupport::PaintModeEverything));
return benchmarks.Pass();
}
} // namespace content
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_RENDERER_ALL_RENDERING_BENCHMARKS_H_
#define CONTENT_RENDERER_ALL_RENDERING_BENCHMARKS_H_
#include <vector>
#include "base/memory/scoped_vector.h"
namespace content {
class RenderingBenchmark;
ScopedVector<RenderingBenchmark> AllRenderingBenchmarks();
} // namespace content
#endif // CONTENT_RENDERER_ALL_RENDERING_BENCHMARKS_H_
...@@ -3,14 +3,24 @@ ...@@ -3,14 +3,24 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "content/renderer/gpu/gpu_benchmarking_extension.h" #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 "content/renderer/render_view_impl.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebRenderingStats.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/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/WebView.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
#include "v8/include/v8.h" #include "v8/include/v8.h"
using WebKit::WebFrame; using WebKit::WebFrame;
using WebKit::WebPrivatePtr;
using WebKit::WebViewBenchmarkSupport;
using WebKit::WebRenderingStats; using WebKit::WebRenderingStats;
using WebKit::WebView; using WebKit::WebView;
...@@ -21,6 +31,37 @@ using WebKit::WebView; ...@@ -21,6 +31,37 @@ using WebKit::WebView;
namespace content { 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 { class GpuBenchmarkingWrapper : public v8::Extension {
public: public:
GpuBenchmarkingWrapper() : GpuBenchmarkingWrapper() :
...@@ -45,6 +86,10 @@ class GpuBenchmarkingWrapper : public v8::Extension { ...@@ -45,6 +86,10 @@ class GpuBenchmarkingWrapper : public v8::Extension {
" scroll_far = scroll_far || false;" " scroll_far = scroll_far || false;"
" native function BeginSmoothScroll();" " native function BeginSmoothScroll();"
" return BeginSmoothScroll(false, scroll_far);" " return BeginSmoothScroll(false, scroll_far);"
"};"
"chrome.gpuBenchmarking.runRenderingBenchmarks = function(filter) {"
" native function RunRenderingBenchmarks();"
" return RunRenderingBenchmarks(filter);"
"};") {} "};") {}
virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
...@@ -53,6 +98,8 @@ class GpuBenchmarkingWrapper : public v8::Extension { ...@@ -53,6 +98,8 @@ class GpuBenchmarkingWrapper : public v8::Extension {
return v8::FunctionTemplate::New(GetRenderingStats); return v8::FunctionTemplate::New(GetRenderingStats);
if (name->Equals(v8::String::New("BeginSmoothScroll"))) if (name->Equals(v8::String::New("BeginSmoothScroll")))
return v8::FunctionTemplate::New(BeginSmoothScroll); return v8::FunctionTemplate::New(BeginSmoothScroll);
if (name->Equals(v8::String::New("RunRenderingBenchmarks")))
return v8::FunctionTemplate::New(RunRenderingBenchmarks);
return v8::Handle<v8::FunctionTemplate>(); return v8::Handle<v8::FunctionTemplate>();
} }
...@@ -115,6 +162,56 @@ class GpuBenchmarkingWrapper : public v8::Extension { ...@@ -115,6 +162,56 @@ class GpuBenchmarkingWrapper : public v8::Extension {
render_view_impl->BeginSmoothScroll(scroll_down, scroll_far); render_view_impl->BeginSmoothScroll(scroll_down, scroll_far);
return v8::True(); 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() { v8::Extension* GpuBenchmarkingExtension::Get() {
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/renderer/rendering_benchmark.h"
namespace content {
RenderingBenchmark::RenderingBenchmark(const std::string& name) : name_(name) {}
RenderingBenchmark::~RenderingBenchmark() {}
} // namespace content
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_RENDERER_RENDERING_BENCHMARK_H_
#define CONTENT_RENDERER_RENDERING_BENCHMARK_H_
#include <string>
#include "base/basictypes.h"
namespace WebKit {
class WebViewBenchmarkSupport;
}
namespace content {
class RenderingBenchmarkResults;
class RenderingBenchmark {
public:
explicit RenderingBenchmark(const std::string& name);
virtual ~RenderingBenchmark();
virtual void SetUp(WebKit::WebViewBenchmarkSupport* benchmarkSupport) {}
virtual void Run(RenderingBenchmarkResults* results,
WebKit::WebViewBenchmarkSupport* benchmarkSupport) = 0;
virtual void TearDown(WebKit::WebViewBenchmarkSupport* benchmarkSupport) {}
const std::string& name() { return name_; }
private:
const std::string name_;
DISALLOW_COPY_AND_ASSIGN(RenderingBenchmark);
};
} // namespace content
#endif // CONTENT_RENDERER_RENDERING_BENCHMARK_H_
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_RENDERER_RENDERING_BENCHMARK_RESULTS_H_
#define CONTENT_RENDERER_RENDERING_BENCHMARK_RESULTS_H_
#include <string>
#include "content/common/content_export.h"
namespace content {
class RenderingBenchmarkResults {
public:
virtual ~RenderingBenchmarkResults() { }
virtual void AddResult(const std::string& benchmark_name,
const std::string& result_name,
const std::string& result_unit,
double time) = 0;
};
} // namespace content
#endif // CONTENT_RENDERER_RENDERING_BENCHMARK_RESULTS_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment