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

Side by Side Diff: chrome/renderer/benchmarking_extension.cc

Issue 11801024: Fixed browser crash when using Debug build: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed failure on win perf bot. Created 7 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/chrome_switches.cc ('k') | chrome/renderer/chrome_content_renderer_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "content/public/common/content_switches.h" 10 #include "content/public/common/content_switches.h"
12 #include "content/public/renderer/render_thread.h" 11 #include "content/public/renderer/render_thread.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCache.h"
14 #include "v8/include/v8.h" 12 #include "v8/include/v8.h"
15 13
16 using WebKit::WebCache;
17
18 const char kBenchmarkingExtensionName[] = "v8/Benchmarking"; 14 const char kBenchmarkingExtensionName[] = "v8/Benchmarking";
19 15
20 namespace extensions_v8 { 16 namespace extensions_v8 {
21 17
22 class BenchmarkingWrapper : public v8::Extension { 18 class BenchmarkingWrapper : public v8::Extension {
23 public: 19 public:
24 BenchmarkingWrapper() : 20 BenchmarkingWrapper() :
25 v8::Extension(kBenchmarkingExtensionName, 21 v8::Extension(kBenchmarkingExtensionName,
26 "if (typeof(chrome) == 'undefined') {" 22 "if (typeof(chrome) == 'undefined') {"
27 " chrome = {};" 23 " chrome = {};"
28 "};" 24 "};"
29 "if (typeof(chrome.benchmarking) == 'undefined') {" 25 "if (typeof(chrome.benchmarking) == 'undefined') {"
30 " chrome.benchmarking = {};" 26 " chrome.benchmarking = {};"
31 "};" 27 "};"
32 "chrome.benchmarking.clearCache = function() {"
33 " native function ClearCache();"
34 " ClearCache();"
35 "};"
36 "chrome.benchmarking.clearHostResolverCache = function() {"
37 " native function ClearHostResolverCache();"
38 " ClearHostResolverCache();"
39 "};"
40 "chrome.benchmarking.clearPredictorCache = function() {"
41 " native function ClearPredictorCache();"
42 " ClearPredictorCache();"
43 "};"
44 "chrome.benchmarking.closeConnections = function() {"
45 " native function CloseConnections();"
46 " CloseConnections();"
47 "};"
48 "chrome.benchmarking.counter = function(name) {" 28 "chrome.benchmarking.counter = function(name) {"
49 " native function GetCounter();" 29 " native function GetCounter();"
50 " return GetCounter(name);" 30 " return GetCounter(name);"
51 "};" 31 "};"
52 "chrome.benchmarking.enableSpdy = function(name) {"
53 " native function EnableSpdy();"
54 " EnableSpdy(name);"
55 "};"
56 "chrome.benchmarking.isSingleProcess = function() {" 32 "chrome.benchmarking.isSingleProcess = function() {"
57 " native function IsSingleProcess();" 33 " native function IsSingleProcess();"
58 " return IsSingleProcess();" 34 " return IsSingleProcess();"
59 "};" 35 "};"
60 "chrome.Interval = function() {" 36 "chrome.Interval = function() {"
61 " var start_ = 0;" 37 " var start_ = 0;"
62 " var stop_ = 0;" 38 " var stop_ = 0;"
63 " native function HiResTime();" 39 " native function HiResTime();"
64 " this.start = function() {" 40 " this.start = function() {"
65 " stop_ = 0;" 41 " stop_ = 0;"
66 " start_ = HiResTime();" 42 " start_ = HiResTime();"
67 " };" 43 " };"
68 " this.stop = function() {" 44 " this.stop = function() {"
69 " stop_ = HiResTime();" 45 " stop_ = HiResTime();"
70 " if (start_ == 0)" 46 " if (start_ == 0)"
71 " stop_ = 0;" 47 " stop_ = 0;"
72 " };" 48 " };"
73 " this.microseconds = function() {" 49 " this.microseconds = function() {"
74 " var stop = stop_;" 50 " var stop = stop_;"
75 " if (stop == 0 && start_ != 0)" 51 " if (stop == 0 && start_ != 0)"
76 " stop = HiResTime();" 52 " stop = HiResTime();"
77 " return Math.ceil(stop - start_);" 53 " return Math.ceil(stop - start_);"
78 " };" 54 " };"
79 "}" 55 "}"
80 ) {} 56 ) {}
81 57
82 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( 58 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
83 v8::Handle<v8::String> name) OVERRIDE { 59 v8::Handle<v8::String> name) {
84 if (name->Equals(v8::String::New("CloseConnections"))) { 60 if (name->Equals(v8::String::New("GetCounter"))) {
85 return v8::FunctionTemplate::New(CloseConnections);
86 } else if (name->Equals(v8::String::New("ClearCache"))) {
87 return v8::FunctionTemplate::New(ClearCache);
88 } else if (name->Equals(v8::String::New("ClearHostResolverCache"))) {
89 return v8::FunctionTemplate::New(ClearHostResolverCache);
90 } else if (name->Equals(v8::String::New("ClearPredictorCache"))) {
91 return v8::FunctionTemplate::New(ClearPredictorCache);
92 } else if (name->Equals(v8::String::New("EnableSpdy"))) {
93 return v8::FunctionTemplate::New(EnableSpdy);
94 } else if (name->Equals(v8::String::New("GetCounter"))) {
95 return v8::FunctionTemplate::New(GetCounter); 61 return v8::FunctionTemplate::New(GetCounter);
96 } else if (name->Equals(v8::String::New("IsSingleProcess"))) { 62 } else if (name->Equals(v8::String::New("IsSingleProcess"))) {
97 return v8::FunctionTemplate::New(IsSingleProcess); 63 return v8::FunctionTemplate::New(IsSingleProcess);
98 } else if (name->Equals(v8::String::New("HiResTime"))) { 64 } else if (name->Equals(v8::String::New("HiResTime"))) {
99 return v8::FunctionTemplate::New(HiResTime); 65 return v8::FunctionTemplate::New(HiResTime);
100 } 66 }
101 67
102 return v8::Handle<v8::FunctionTemplate>(); 68 return v8::Handle<v8::FunctionTemplate>();
103 } 69 }
104 70
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) {
112 int rv;
113 content::RenderThread::Get()->Send(new ChromeViewHostMsg_ClearCache(&rv));
114 WebCache::clear();
115 return v8::Undefined();
116 }
117
118 static v8::Handle<v8::Value> ClearHostResolverCache(
119 const v8::Arguments& args) {
120 int rv;
121 content::RenderThread::Get()->Send(
122 new ChromeViewHostMsg_ClearHostResolverCache(&rv));
123 return v8::Undefined();
124 }
125
126 static v8::Handle<v8::Value> ClearPredictorCache(
127 const v8::Arguments& args) {
128 int rv;
129 content::RenderThread::Get()->Send(
130 new ChromeViewHostMsg_ClearPredictorCache(&rv));
131 return v8::Undefined();
132 }
133
134 static v8::Handle<v8::Value> EnableSpdy(const v8::Arguments& args) {
135 if (!args.Length() || !args[0]->IsBoolean())
136 return v8::Undefined();
137
138 content::RenderThread::Get()->Send(new ChromeViewHostMsg_EnableSpdy(
139 args[0]->BooleanValue()));
140 return v8::Undefined();
141 }
142
143 static v8::Handle<v8::Value> GetCounter(const v8::Arguments& args) { 71 static v8::Handle<v8::Value> GetCounter(const v8::Arguments& args) {
144 if (!args.Length() || !args[0]->IsString() || !base::StatsTable::current()) 72 if (!args.Length() || !args[0]->IsString() || !base::StatsTable::current())
145 return v8::Undefined(); 73 return v8::Undefined();
146 74
147 // Extract the name argument 75 // Extract the name argument
148 char name[256]; 76 char name[256];
149 name[0] = 'c'; 77 name[0] = 'c';
150 name[1] = ':'; 78 name[1] = ':';
151 args[0]->ToString()->WriteAscii(&name[2], 0, sizeof(name) - 3); 79 args[0]->ToString()->WriteAscii(&name[2], 0, sizeof(name) - 3);
152 80
(...skipping 10 matching lines...) Expand all
163 return v8::Number::New( 91 return v8::Number::New(
164 static_cast<double>(base::TimeTicks::HighResNow().ToInternalValue())); 92 static_cast<double>(base::TimeTicks::HighResNow().ToInternalValue()));
165 } 93 }
166 }; 94 };
167 95
168 v8::Extension* BenchmarkingExtension::Get() { 96 v8::Extension* BenchmarkingExtension::Get() {
169 return new BenchmarkingWrapper(); 97 return new BenchmarkingWrapper();
170 } 98 }
171 99
172 } // namespace extensions_v8 100 } // namespace extensions_v8
OLDNEW
« no previous file with comments | « chrome/common/chrome_switches.cc ('k') | chrome/renderer/chrome_content_renderer_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698