Chromium Code Reviews| 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" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 class BenchmarkingWrapper : public v8::Extension { | 22 class BenchmarkingWrapper : public v8::Extension { |
| 23 public: | 23 public: |
| 24 BenchmarkingWrapper() : | 24 BenchmarkingWrapper() : |
| 25 v8::Extension(kBenchmarkingExtensionName, | 25 v8::Extension(kBenchmarkingExtensionName, |
| 26 "if (typeof(chrome) == 'undefined') {" | 26 "if (typeof(chrome) == 'undefined') {" |
| 27 " chrome = {};" | 27 " chrome = {};" |
| 28 "};" | 28 "};" |
| 29 "if (typeof(chrome.benchmarking) == 'undefined') {" | 29 "if (typeof(chrome.benchmarking) == 'undefined') {" |
| 30 " chrome.benchmarking = {};" | 30 " chrome.benchmarking = {};" |
| 31 "};" | 31 "};" |
| 32 "chrome.benchmarking.clearCache = function() {" | 32 "chrome.benchmarking.clearCache = function() {" |
|
tonyg
2013/01/24 22:00:29
There are other useful methods in the benchmarking
Danh Nguyen
2013/02/07 16:56:32
Done.
| |
| 33 " native function ClearCache();" | 33 " native function ClearCache();" |
| 34 " ClearCache();" | 34 " ClearCache();" |
| 35 "};" | 35 "};" |
| 36 "chrome.benchmarking.clearHostResolverCache = function() {" | 36 "chrome.benchmarking.clearHostResolverCache = function() {" |
| 37 " native function ClearHostResolverCache();" | 37 " native function ClearHostResolverCache();" |
|
nduca
2013/02/06 07:40:06
we should probably move all network related stuff
Danh Nguyen
2013/02/07 16:56:32
Done.
| |
| 38 " ClearHostResolverCache();" | 38 " ClearHostResolverCache();" |
| 39 "};" | 39 "};" |
| 40 "chrome.benchmarking.clearPredictorCache = function() {" | 40 "chrome.benchmarking.clearPredictorCache = function() {" |
| 41 " native function ClearPredictorCache();" | 41 " native function ClearPredictorCache();" |
| 42 " ClearPredictorCache();" | 42 " ClearPredictorCache();" |
| 43 "};" | 43 "};" |
| 44 "chrome.benchmarking.closeConnections = function() {" | |
| 45 " native function CloseConnections();" | |
| 46 " CloseConnections();" | |
| 47 "};" | |
| 48 "chrome.benchmarking.counter = function(name) {" | 44 "chrome.benchmarking.counter = function(name) {" |
| 49 " native function GetCounter();" | 45 " native function GetCounter();" |
| 50 " return GetCounter(name);" | 46 " return GetCounter(name);" |
| 51 "};" | 47 "};" |
| 52 "chrome.benchmarking.enableSpdy = function(name) {" | 48 "chrome.benchmarking.enableSpdy = function(name) {" |
| 53 " native function EnableSpdy();" | 49 " native function EnableSpdy();" |
| 54 " EnableSpdy(name);" | 50 " EnableSpdy(name);" |
| 55 "};" | 51 "};" |
| 56 "chrome.benchmarking.isSingleProcess = function() {" | 52 "chrome.benchmarking.isSingleProcess = function() {" |
| 57 " native function IsSingleProcess();" | 53 " native function IsSingleProcess();" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 74 " var stop = stop_;" | 70 " var stop = stop_;" |
| 75 " if (stop == 0 && start_ != 0)" | 71 " if (stop == 0 && start_ != 0)" |
| 76 " stop = HiResTime();" | 72 " stop = HiResTime();" |
| 77 " return Math.ceil(stop - start_);" | 73 " return Math.ceil(stop - start_);" |
| 78 " };" | 74 " };" |
| 79 "}" | 75 "}" |
| 80 ) {} | 76 ) {} |
| 81 | 77 |
| 82 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( | 78 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( |
| 83 v8::Handle<v8::String> name) { | 79 v8::Handle<v8::String> name) { |
| 84 if (name->Equals(v8::String::New("CloseConnections"))) { | 80 if (name->Equals(v8::String::New("ClearCache"))) { |
| 85 return v8::FunctionTemplate::New(CloseConnections); | |
| 86 } else if (name->Equals(v8::String::New("ClearCache"))) { | |
| 87 return v8::FunctionTemplate::New(ClearCache); | 81 return v8::FunctionTemplate::New(ClearCache); |
| 88 } else if (name->Equals(v8::String::New("ClearHostResolverCache"))) { | 82 } else if (name->Equals(v8::String::New("ClearHostResolverCache"))) { |
| 89 return v8::FunctionTemplate::New(ClearHostResolverCache); | 83 return v8::FunctionTemplate::New(ClearHostResolverCache); |
| 90 } else if (name->Equals(v8::String::New("ClearPredictorCache"))) { | 84 } else if (name->Equals(v8::String::New("ClearPredictorCache"))) { |
| 91 return v8::FunctionTemplate::New(ClearPredictorCache); | 85 return v8::FunctionTemplate::New(ClearPredictorCache); |
| 92 } else if (name->Equals(v8::String::New("EnableSpdy"))) { | 86 } else if (name->Equals(v8::String::New("EnableSpdy"))) { |
| 93 return v8::FunctionTemplate::New(EnableSpdy); | 87 return v8::FunctionTemplate::New(EnableSpdy); |
| 94 } else if (name->Equals(v8::String::New("GetCounter"))) { | 88 } else if (name->Equals(v8::String::New("GetCounter"))) { |
| 95 return v8::FunctionTemplate::New(GetCounter); | 89 return v8::FunctionTemplate::New(GetCounter); |
| 96 } else if (name->Equals(v8::String::New("IsSingleProcess"))) { | 90 } else if (name->Equals(v8::String::New("IsSingleProcess"))) { |
| 97 return v8::FunctionTemplate::New(IsSingleProcess); | 91 return v8::FunctionTemplate::New(IsSingleProcess); |
| 98 } else if (name->Equals(v8::String::New("HiResTime"))) { | 92 } else if (name->Equals(v8::String::New("HiResTime"))) { |
| 99 return v8::FunctionTemplate::New(HiResTime); | 93 return v8::FunctionTemplate::New(HiResTime); |
| 100 } | 94 } |
| 101 | 95 |
| 102 return v8::Handle<v8::FunctionTemplate>(); | 96 return v8::Handle<v8::FunctionTemplate>(); |
| 103 } | 97 } |
| 104 | 98 |
| 105 static v8::Handle<v8::Value> CloseConnections(const v8::Arguments& args) { | |
| 106 content::RenderThread::Get()->Send( | |
| 107 new ChromeViewHostMsg_CloseCurrentConnections()); | |
| 108 return v8::Undefined(); | |
| 109 } | |
| 110 | |
| 111 static v8::Handle<v8::Value> ClearCache(const v8::Arguments& args) { | 99 static v8::Handle<v8::Value> ClearCache(const v8::Arguments& args) { |
| 112 int rv; | 100 int rv; |
| 113 content::RenderThread::Get()->Send(new ChromeViewHostMsg_ClearCache(&rv)); | 101 content::RenderThread::Get()->Send(new ChromeViewHostMsg_ClearCache(&rv)); |
| 114 WebCache::clear(); | 102 WebCache::clear(); |
| 115 return v8::Undefined(); | 103 return v8::Undefined(); |
| 116 } | 104 } |
| 117 | 105 |
| 118 static v8::Handle<v8::Value> ClearHostResolverCache( | 106 static v8::Handle<v8::Value> ClearHostResolverCache( |
| 119 const v8::Arguments& args) { | 107 const v8::Arguments& args) { |
| 120 int rv; | 108 int rv; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 return v8::Number::New( | 151 return v8::Number::New( |
| 164 static_cast<double>(base::TimeTicks::HighResNow().ToInternalValue())); | 152 static_cast<double>(base::TimeTicks::HighResNow().ToInternalValue())); |
| 165 } | 153 } |
| 166 }; | 154 }; |
| 167 | 155 |
| 168 v8::Extension* BenchmarkingExtension::Get() { | 156 v8::Extension* BenchmarkingExtension::Get() { |
| 169 return new BenchmarkingWrapper(); | 157 return new BenchmarkingWrapper(); |
| 170 } | 158 } |
| 171 | 159 |
| 172 } // namespace extensions_v8 | 160 } // namespace extensions_v8 |
| OLD | NEW |