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

Unified Diff: chrome/renderer/benchmarking_extension.cc

Issue 10537036: Added rendering benchmark javascript hook (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 6 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 | « no previous file | skia/skia.gyp » ('j') | skia/skia.gyp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/benchmarking_extension.cc
diff --git a/chrome/renderer/benchmarking_extension.cc b/chrome/renderer/benchmarking_extension.cc
index d6eb831fad1647a1ebcf4b090a32cde3b1bc4c54..b87fa7fd69008c3f7e8fb42c50b7e1b94056fc8e 100644
--- a/chrome/renderer/benchmarking_extension.cc
+++ b/chrome/renderer/benchmarking_extension.cc
@@ -10,13 +10,38 @@
#include "chrome/common/benchmarking_messages.h"
#include "content/public/common/content_switches.h"
#include "content/public/renderer/render_thread.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebRenderingBenchmarkResults.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebCache.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
#include "v8/include/v8.h"
using WebKit::WebCache;
+using WebKit::WebFrame;
+using WebKit::WebView;
const char kBenchmarkingExtensionName[] = "v8/Benchmarking";
+// Benchmark results object that populates a json array
nduca 2012/06/12 17:42:09 Comments end with periods. Also, note its not a js
dmurph 2012/06/14 02:20:13 Done.
+class JsonBenchmarkResults : public WebRenderingBenchmarkResults {
nduca 2012/06/12 17:42:09 V8BenchmarkResults
dmurph 2012/06/14 02:20:13 Done.
+ public:
+ explicit JsonBenchmarkResults(v8::Handle<v8::Array> results_array)
+ : curr_result_index_(0), results_array_(results_array) { }
nduca 2012/06/12 17:42:09 check goog c++ style guide, this feels too compact
+ virtual ~JsonBenchmarkResults() {}
+
+ void addResult(const char *name, const char* unit, double resultValue) {
+ v8::Handle<v8::Object> result = v8::Object::New();
+ result->Set(v8::String::New("benchmark", 9), v8::String::New(name, -1));
+ result->Set(v8::String::New("unit", 4), v8::String::New(unit, -1));
+ result->Set(v8::String::New("time", 4), v8::Number::New(resultValue));
+ results_array_->Set(curr_result_index_++, result);
+ }
+
+ private:
+ unsigned int curr_result_index_;
nduca 2012/06/12 17:42:09 cur_result_index_. Not sure if this is the standar
dmurph 2012/06/14 02:20:13 Couldn't find a 'push', but instead of having that
+ v8::Handle<v8::Array> results_array_;
+};
+
namespace extensions_v8 {
class BenchmarkingWrapper : public v8::Extension {
@@ -57,6 +82,10 @@ class BenchmarkingWrapper : public v8::Extension {
" native function IsSingleProcess();"
" return IsSingleProcess();"
"};"
+ "chrome.benchmarking.runRenderingBenchmarks = function() {"
+ " native function RunRenderingBenchmarks();"
+ " return RunRenderingBenchmarks();"
+ "};"
"chrome.Interval = function() {"
" var start_ = 0;"
" var stop_ = 0;"
@@ -97,6 +126,8 @@ class BenchmarkingWrapper : public v8::Extension {
return v8::FunctionTemplate::New(IsSingleProcess);
} else if (name->Equals(v8::String::New("HiResTime"))) {
return v8::FunctionTemplate::New(HiResTime);
+ } else if (name->Equals(v8::String::New("RunRenderingBenchmarks"))) {
+ return v8::FunctionTemplate::New(RunRenderingBenchmarks);
}
return v8::Handle<v8::FunctionTemplate>();
@@ -167,6 +198,25 @@ class BenchmarkingWrapper : public v8::Extension {
return v8::Number::New(
static_cast<double>(base::TimeTicks::HighResNow().ToInternalValue()));
}
+
+ static v8::Handle<v8::Value> RunRenderingBenchmarks(
+ const v8::Arguments& args) {
+ 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);
+
+ JsonBenchmarkResults* results = new JsonBenchmarkResults(resultsArray);
nduca 2012/06/12 17:42:09 This looks good. But, where did we end up with Dar
dmurph 2012/06/14 02:20:13 I'm including it now, I just hadn't made it yet fo
+ web_view->runRenderingBenchmarks(*results);
+ delete results;
+
+ return resultsArray;
+ }
};
v8::Extension* BenchmarkingExtension::Get() {
« no previous file with comments | « no previous file | skia/skia.gyp » ('j') | skia/skia.gyp » ('J')

Powered by Google App Engine
This is Rietveld 408576698