OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/stats_table.h" | 6 #include "base/stats_table.h" |
| 7 #include "base/time.h" |
7 #include "net/http/http_network_layer.h" | 8 #include "net/http/http_network_layer.h" |
8 #include "third_party/WebKit/WebKit/chromium/public/WebCache.h" | 9 #include "third_party/WebKit/WebKit/chromium/public/WebCache.h" |
9 #include "webkit/extensions/v8/benchmarking_extension.h" | 10 #include "webkit/extensions/v8/benchmarking_extension.h" |
10 #include "webkit/glue/webkit_glue.h" | 11 #include "webkit/glue/webkit_glue.h" |
11 | 12 |
12 using WebKit::WebCache; | 13 using WebKit::WebCache; |
13 | 14 |
14 namespace extensions_v8 { | 15 namespace extensions_v8 { |
15 | 16 |
16 const char* kBenchmarkingExtensionName = "v8/Benchmarking"; | 17 const char* kBenchmarkingExtensionName = "v8/Benchmarking"; |
(...skipping 21 matching lines...) Expand all Loading... |
38 " return GetCounter(name);" | 39 " return GetCounter(name);" |
39 "};" | 40 "};" |
40 "chrome.benchmarking.enableSpdy = function(name) {" | 41 "chrome.benchmarking.enableSpdy = function(name) {" |
41 " native function EnableSpdy();" | 42 " native function EnableSpdy();" |
42 " EnableSpdy(name);" | 43 " EnableSpdy(name);" |
43 "};" | 44 "};" |
44 "chrome.benchmarking.isSingleProcess = function() {" | 45 "chrome.benchmarking.isSingleProcess = function() {" |
45 " native function IsSingleProcess();" | 46 " native function IsSingleProcess();" |
46 " return IsSingleProcess();" | 47 " return IsSingleProcess();" |
47 "};" | 48 "};" |
| 49 "chrome.Interval = function() {" |
| 50 " var start_ = 0;" |
| 51 " var stop_ = 0;" |
| 52 " native function HiResTime();" |
| 53 " this.start = function() {" |
| 54 " stop_ = 0;" |
| 55 " start_ = HiResTime();" |
| 56 " };" |
| 57 " this.stop = function() {" |
| 58 " stop_ = HiResTime();" |
| 59 " if (start_ == 0)" |
| 60 " stop_ = 0;" |
| 61 " };" |
| 62 " this.microseconds = function() {" |
| 63 " var stop = stop_;" |
| 64 " if (stop == 0 && start_ != 0)" |
| 65 " stop = HiResTime();" |
| 66 " return Math.ceil(stop - start_);" |
| 67 " };" |
| 68 "}" |
48 ) {} | 69 ) {} |
49 | 70 |
50 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( | 71 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( |
51 v8::Handle<v8::String> name) { | 72 v8::Handle<v8::String> name) { |
52 if (name->Equals(v8::String::New("CloseConnections"))) { | 73 if (name->Equals(v8::String::New("CloseConnections"))) { |
53 return v8::FunctionTemplate::New(CloseConnections); | 74 return v8::FunctionTemplate::New(CloseConnections); |
54 } else if (name->Equals(v8::String::New("ClearCache"))) { | 75 } else if (name->Equals(v8::String::New("ClearCache"))) { |
55 return v8::FunctionTemplate::New(ClearCache); | 76 return v8::FunctionTemplate::New(ClearCache); |
56 } else if (name->Equals(v8::String::New("EnableSpdy"))) { | 77 } else if (name->Equals(v8::String::New("EnableSpdy"))) { |
57 return v8::FunctionTemplate::New(EnableSpdy); | 78 return v8::FunctionTemplate::New(EnableSpdy); |
58 } else if (name->Equals(v8::String::New("GetCounter"))) { | 79 } else if (name->Equals(v8::String::New("GetCounter"))) { |
59 return v8::FunctionTemplate::New(GetCounter); | 80 return v8::FunctionTemplate::New(GetCounter); |
60 } else if (name->Equals(v8::String::New("IsSingleProcess"))) { | 81 } else if (name->Equals(v8::String::New("IsSingleProcess"))) { |
61 return v8::FunctionTemplate::New(IsSingleProcess); | 82 return v8::FunctionTemplate::New(IsSingleProcess); |
| 83 } else if (name->Equals(v8::String::New("HiResTime"))) { |
| 84 return v8::FunctionTemplate::New(HiResTime); |
62 } | 85 } |
| 86 |
63 return v8::Handle<v8::FunctionTemplate>(); | 87 return v8::Handle<v8::FunctionTemplate>(); |
64 } | 88 } |
65 | 89 |
66 static v8::Handle<v8::Value> CloseConnections(const v8::Arguments& args) { | 90 static v8::Handle<v8::Value> CloseConnections(const v8::Arguments& args) { |
67 webkit_glue::CloseCurrentConnections(); | 91 webkit_glue::CloseCurrentConnections(); |
68 return v8::Undefined(); | 92 return v8::Undefined(); |
69 } | 93 } |
70 | 94 |
71 static v8::Handle<v8::Value> ClearCache(const v8::Arguments& args) { | 95 static v8::Handle<v8::Value> ClearCache(const v8::Arguments& args) { |
72 webkit_glue::ClearCache(); | 96 webkit_glue::ClearCache(); |
(...skipping 19 matching lines...) Expand all Loading... |
92 name[1] = ':'; | 116 name[1] = ':'; |
93 args[0]->ToString()->WriteAscii(&name[2], 0, sizeof(name) - 3); | 117 args[0]->ToString()->WriteAscii(&name[2], 0, sizeof(name) - 3); |
94 | 118 |
95 int counter = StatsTable::current()->GetCounterValue(name); | 119 int counter = StatsTable::current()->GetCounterValue(name); |
96 return v8::Integer::New(counter); | 120 return v8::Integer::New(counter); |
97 } | 121 } |
98 | 122 |
99 static v8::Handle<v8::Value> IsSingleProcess(const v8::Arguments& args) { | 123 static v8::Handle<v8::Value> IsSingleProcess(const v8::Arguments& args) { |
100 return v8::Boolean::New(webkit_glue::IsSingleProcess()); | 124 return v8::Boolean::New(webkit_glue::IsSingleProcess()); |
101 } | 125 } |
| 126 |
| 127 static v8::Handle<v8::Value> HiResTime(const v8::Arguments& args) { |
| 128 return v8::Number::New( |
| 129 static_cast<double>(base::TimeTicks::HighResNow().ToInternalValue())); |
| 130 } |
102 }; | 131 }; |
103 | 132 |
104 v8::Extension* BenchmarkingExtension::Get() { | 133 v8::Extension* BenchmarkingExtension::Get() { |
105 return new BenchmarkingWrapper(); | 134 return new BenchmarkingWrapper(); |
106 } | 135 } |
107 | 136 |
108 } // namespace extensions_v8 | 137 } // namespace extensions_v8 |
OLD | NEW |