OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/renderer/benchmarking_extension.h" | 5 #include "chrome/renderer/benchmarking_extension.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/stats_table.h" | 8 #include "base/metrics/stats_table.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "chrome/common/benchmarking_messages.h" | 10 #include "chrome/common/benchmarking_messages.h" |
11 #include "content/public/common/content_switches.h" | 11 #include "content/public/common/content_switches.h" |
12 #include "content/public/renderer/render_thread.h" | 12 #include "content/public/renderer/render_thread.h" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRenderingBenchmark Results.h" | |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCache.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCache.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | |
14 #include "v8/include/v8.h" | 17 #include "v8/include/v8.h" |
15 | 18 |
16 using WebKit::WebCache; | 19 using WebKit::WebCache; |
20 using WebKit::WebFrame; | |
21 using WebKit::WebView; | |
17 | 22 |
18 const char kBenchmarkingExtensionName[] = "v8/Benchmarking"; | 23 const char kBenchmarkingExtensionName[] = "v8/Benchmarking"; |
19 | 24 |
25 // 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.
| |
26 class JsonBenchmarkResults : public WebRenderingBenchmarkResults { | |
nduca
2012/06/12 17:42:09
V8BenchmarkResults
dmurph
2012/06/14 02:20:13
Done.
| |
27 public: | |
28 explicit JsonBenchmarkResults(v8::Handle<v8::Array> results_array) | |
29 : curr_result_index_(0), results_array_(results_array) { } | |
nduca
2012/06/12 17:42:09
check goog c++ style guide, this feels too compact
| |
30 virtual ~JsonBenchmarkResults() {} | |
31 | |
32 void addResult(const char *name, const char* unit, double resultValue) { | |
33 v8::Handle<v8::Object> result = v8::Object::New(); | |
34 result->Set(v8::String::New("benchmark", 9), v8::String::New(name, -1)); | |
35 result->Set(v8::String::New("unit", 4), v8::String::New(unit, -1)); | |
36 result->Set(v8::String::New("time", 4), v8::Number::New(resultValue)); | |
37 results_array_->Set(curr_result_index_++, result); | |
38 } | |
39 | |
40 private: | |
41 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
| |
42 v8::Handle<v8::Array> results_array_; | |
43 }; | |
44 | |
20 namespace extensions_v8 { | 45 namespace extensions_v8 { |
21 | 46 |
22 class BenchmarkingWrapper : public v8::Extension { | 47 class BenchmarkingWrapper : public v8::Extension { |
23 public: | 48 public: |
24 BenchmarkingWrapper() : | 49 BenchmarkingWrapper() : |
25 v8::Extension(kBenchmarkingExtensionName, | 50 v8::Extension(kBenchmarkingExtensionName, |
26 "if (typeof(chrome) == 'undefined') {" | 51 "if (typeof(chrome) == 'undefined') {" |
27 " chrome = {};" | 52 " chrome = {};" |
28 "};" | 53 "};" |
29 "if (typeof(chrome.benchmarking) == 'undefined') {" | 54 "if (typeof(chrome.benchmarking) == 'undefined') {" |
(...skipping 20 matching lines...) Expand all Loading... | |
50 " return GetCounter(name);" | 75 " return GetCounter(name);" |
51 "};" | 76 "};" |
52 "chrome.benchmarking.enableSpdy = function(name) {" | 77 "chrome.benchmarking.enableSpdy = function(name) {" |
53 " native function EnableSpdy();" | 78 " native function EnableSpdy();" |
54 " EnableSpdy(name);" | 79 " EnableSpdy(name);" |
55 "};" | 80 "};" |
56 "chrome.benchmarking.isSingleProcess = function() {" | 81 "chrome.benchmarking.isSingleProcess = function() {" |
57 " native function IsSingleProcess();" | 82 " native function IsSingleProcess();" |
58 " return IsSingleProcess();" | 83 " return IsSingleProcess();" |
59 "};" | 84 "};" |
85 "chrome.benchmarking.runRenderingBenchmarks = function() {" | |
86 " native function RunRenderingBenchmarks();" | |
87 " return RunRenderingBenchmarks();" | |
88 "};" | |
60 "chrome.Interval = function() {" | 89 "chrome.Interval = function() {" |
61 " var start_ = 0;" | 90 " var start_ = 0;" |
62 " var stop_ = 0;" | 91 " var stop_ = 0;" |
63 " native function HiResTime();" | 92 " native function HiResTime();" |
64 " this.start = function() {" | 93 " this.start = function() {" |
65 " stop_ = 0;" | 94 " stop_ = 0;" |
66 " start_ = HiResTime();" | 95 " start_ = HiResTime();" |
67 " };" | 96 " };" |
68 " this.stop = function() {" | 97 " this.stop = function() {" |
69 " stop_ = HiResTime();" | 98 " stop_ = HiResTime();" |
(...skipping 20 matching lines...) Expand all Loading... | |
90 } else if (name->Equals(v8::String::New("ClearPredictorCache"))) { | 119 } else if (name->Equals(v8::String::New("ClearPredictorCache"))) { |
91 return v8::FunctionTemplate::New(ClearPredictorCache); | 120 return v8::FunctionTemplate::New(ClearPredictorCache); |
92 } else if (name->Equals(v8::String::New("EnableSpdy"))) { | 121 } else if (name->Equals(v8::String::New("EnableSpdy"))) { |
93 return v8::FunctionTemplate::New(EnableSpdy); | 122 return v8::FunctionTemplate::New(EnableSpdy); |
94 } else if (name->Equals(v8::String::New("GetCounter"))) { | 123 } else if (name->Equals(v8::String::New("GetCounter"))) { |
95 return v8::FunctionTemplate::New(GetCounter); | 124 return v8::FunctionTemplate::New(GetCounter); |
96 } else if (name->Equals(v8::String::New("IsSingleProcess"))) { | 125 } else if (name->Equals(v8::String::New("IsSingleProcess"))) { |
97 return v8::FunctionTemplate::New(IsSingleProcess); | 126 return v8::FunctionTemplate::New(IsSingleProcess); |
98 } else if (name->Equals(v8::String::New("HiResTime"))) { | 127 } else if (name->Equals(v8::String::New("HiResTime"))) { |
99 return v8::FunctionTemplate::New(HiResTime); | 128 return v8::FunctionTemplate::New(HiResTime); |
129 } else if (name->Equals(v8::String::New("RunRenderingBenchmarks"))) { | |
130 return v8::FunctionTemplate::New(RunRenderingBenchmarks); | |
100 } | 131 } |
101 | 132 |
102 return v8::Handle<v8::FunctionTemplate>(); | 133 return v8::Handle<v8::FunctionTemplate>(); |
103 } | 134 } |
104 | 135 |
105 static v8::Handle<v8::Value> CloseConnections(const v8::Arguments& args) { | 136 static v8::Handle<v8::Value> CloseConnections(const v8::Arguments& args) { |
106 content::RenderThread::Get()->Send( | 137 content::RenderThread::Get()->Send( |
107 new ChromeViewHostMsg_CloseCurrentConnections()); | 138 new ChromeViewHostMsg_CloseCurrentConnections()); |
108 return v8::Undefined(); | 139 return v8::Undefined(); |
109 } | 140 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 | 191 |
161 static v8::Handle<v8::Value> IsSingleProcess(const v8::Arguments& args) { | 192 static v8::Handle<v8::Value> IsSingleProcess(const v8::Arguments& args) { |
162 return v8::Boolean::New( | 193 return v8::Boolean::New( |
163 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)); | 194 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)); |
164 } | 195 } |
165 | 196 |
166 static v8::Handle<v8::Value> HiResTime(const v8::Arguments& args) { | 197 static v8::Handle<v8::Value> HiResTime(const v8::Arguments& args) { |
167 return v8::Number::New( | 198 return v8::Number::New( |
168 static_cast<double>(base::TimeTicks::HighResNow().ToInternalValue())); | 199 static_cast<double>(base::TimeTicks::HighResNow().ToInternalValue())); |
169 } | 200 } |
201 | |
202 static v8::Handle<v8::Value> RunRenderingBenchmarks( | |
203 const v8::Arguments& args) { | |
204 WebFrame* web_frame = WebFrame::frameForEnteredContext(); | |
205 if (!web_frame) | |
206 return v8::Undefined(); | |
207 | |
208 WebView* web_view = web_frame->view(); | |
209 if (!web_view) | |
210 return v8::Undefined(); | |
211 | |
212 v8::Handle<v8::Array> resultsArray = v8::Array::New(0); | |
213 | |
214 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
| |
215 web_view->runRenderingBenchmarks(*results); | |
216 delete results; | |
217 | |
218 return resultsArray; | |
219 } | |
170 }; | 220 }; |
171 | 221 |
172 v8::Extension* BenchmarkingExtension::Get() { | 222 v8::Extension* BenchmarkingExtension::Get() { |
173 return new BenchmarkingWrapper(); | 223 return new BenchmarkingWrapper(); |
174 } | 224 } |
175 | 225 |
176 } // namespace extensions_v8 | 226 } // namespace extensions_v8 |
OLD | NEW |