| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 /** | 5 /** |
| 6 * @fileoverview These stubs emulate backend functionality and allows | 6 * @fileoverview These stubs emulate backend functionality and allows |
| 7 * DevTools frontend to function as a standalone web app. | 7 * DevTools frontend to function as a standalone web app. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 if (!window['RemoteDebuggerAgent']) { | 10 if (!window['RemoteDebuggerAgent']) { |
| 11 | 11 |
| 12 /** | 12 /** |
| 13 * @constructor | 13 * @constructor |
| 14 */ | 14 */ |
| 15 RemoteDebuggerAgentStub = function() { | 15 RemoteDebuggerAgentStub = function() { |
| 16 this.activeProfilerModules_ = |
| 17 devtools.DebuggerAgent.ProfilerModules.PROFILER_MODULE_NONE; |
| 18 this.profileLogPos_ = 0; |
| 19 this.heapProfSample_ = 0; |
| 20 this.heapProfLog_ = ''; |
| 16 }; | 21 }; |
| 17 | 22 |
| 18 | 23 |
| 19 RemoteDebuggerAgentStub.prototype.GetContextId = function() { | 24 RemoteDebuggerAgentStub.prototype.GetContextId = function() { |
| 20 RemoteDebuggerAgent.SetContextId(3); | 25 RemoteDebuggerAgent.SetContextId(3); |
| 21 }; | 26 }; |
| 22 | 27 |
| 23 | 28 |
| 24 /** | 29 RemoteDebuggerAgentStub.prototype.StopProfiling = function(modules) { |
| 25 * @constructor | 30 this.activeProfilerModules_ &= ~modules; |
| 26 */ | |
| 27 RemoteProfilerAgentStub = function() { | |
| 28 }; | 31 }; |
| 29 | 32 |
| 30 | 33 |
| 31 RemoteProfilerAgentStub.prototype.GetActiveProfilerModules = function() { | 34 RemoteDebuggerAgentStub.prototype.StartProfiling = function(modules) { |
| 32 ProfilerStubHelper.GetInstance().GetActiveProfilerModules(); | 35 var profModules = devtools.DebuggerAgent.ProfilerModules; |
| 36 if (modules & profModules.PROFILER_MODULE_HEAP_SNAPSHOT) { |
| 37 if (modules & profModules.PROFILER_MODULE_HEAP_STATS) { |
| 38 this.heapProfLog_ += |
| 39 'heap-sample-begin,"Heap","allocated",' + |
| 40 (new Date()).getTime() + '\n' + |
| 41 'heap-sample-stats,"Heap","allocated",10000,1000\n'; |
| 42 this.heapProfLog_ += |
| 43 'heap-sample-item,STRING_TYPE,100,1000\n' + |
| 44 'heap-sample-item,CODE_TYPE,10,200\n' + |
| 45 'heap-sample-item,MAP_TYPE,20,350\n'; |
| 46 this.heapProfLog_ += RemoteDebuggerAgentStub.HeapSamples[this.heapProfSamp
le_++]; |
| 47 this.heapProfSample_ %= RemoteDebuggerAgentStub.HeapSamples.length; |
| 48 this.heapProfLog_ += |
| 49 'heap-sample-end,"Heap","allocated"\n'; |
| 50 } |
| 51 } else { |
| 52 this.activeProfilerModules_ |= modules; |
| 53 } |
| 33 }; | 54 }; |
| 34 | 55 |
| 35 | 56 |
| 36 RemoteProfilerAgentStub.prototype.GetLogLines = function(pos) { | 57 RemoteDebuggerAgentStub.prototype.GetActiveProfilerModules = function() { |
| 37 ProfilerStubHelper.GetInstance().GetLogLines(pos); | 58 var self = this; |
| 59 setTimeout(function() { |
| 60 RemoteDebuggerAgent.DidGetActiveProfilerModules( |
| 61 self.activeProfilerModules_); |
| 62 }, 100); |
| 63 }; |
| 64 |
| 65 |
| 66 RemoteDebuggerAgentStub.prototype.GetNextLogLines = function() { |
| 67 var profModules = devtools.DebuggerAgent.ProfilerModules; |
| 68 var logLines = ''; |
| 69 if (this.activeProfilerModules_ & profModules.PROFILER_MODULE_CPU) { |
| 70 if (this.profileLogPos_ < RemoteDebuggerAgentStub.ProfilerLogBuffer.length)
{ |
| 71 this.profileLogPos_ += RemoteDebuggerAgentStub.ProfilerLogBuffer.length; |
| 72 logLines += RemoteDebuggerAgentStub.ProfilerLogBuffer; |
| 73 } |
| 74 } |
| 75 if (this.heapProfLog_) { |
| 76 logLines += this.heapProfLog_; |
| 77 this.heapProfLog_ = ''; |
| 78 } |
| 79 setTimeout(function() { |
| 80 RemoteDebuggerAgent.DidGetNextLogLines(logLines); |
| 81 }, 100); |
| 38 }; | 82 }; |
| 39 | 83 |
| 40 | 84 |
| 41 /** | 85 /** |
| 42 * @constructor | 86 * @constructor |
| 43 */ | 87 */ |
| 44 RemoteToolsAgentStub = function() { | 88 RemoteToolsAgentStub = function() { |
| 45 }; | 89 }; |
| 46 | 90 |
| 47 | 91 |
| 48 RemoteToolsAgentStub.prototype.DispatchOnInjectedScript = function() { | 92 RemoteToolsAgentStub.prototype.DispatchOnInjectedScript = function() { |
| 49 }; | 93 }; |
| 50 | 94 |
| 51 | 95 |
| 52 RemoteToolsAgentStub.prototype.DispatchOnInspectorController = function() { | 96 RemoteToolsAgentStub.prototype.DispatchOnInspectorController = function() { |
| 53 }; | 97 }; |
| 54 | 98 |
| 55 | 99 |
| 56 RemoteToolsAgentStub.prototype.ExecuteVoidJavaScript = function() { | 100 RemoteToolsAgentStub.prototype.ExecuteVoidJavaScript = function() { |
| 57 }; | 101 }; |
| 58 | 102 |
| 59 | 103 |
| 60 /** | 104 RemoteDebuggerAgentStub.ProfilerLogBuffer = |
| 61 * @constructor | |
| 62 */ | |
| 63 ProfilerStubHelper = function() { | |
| 64 this.activeProfilerModules_ = | |
| 65 devtools.ProfilerAgent.ProfilerModules.PROFILER_MODULE_NONE; | |
| 66 this.heapProfSample_ = 0; | |
| 67 this.log_ = ''; | |
| 68 }; | |
| 69 | |
| 70 | |
| 71 ProfilerStubHelper.GetInstance = function() { | |
| 72 if (!ProfilerStubHelper.instance_) { | |
| 73 ProfilerStubHelper.instance_ = new ProfilerStubHelper(); | |
| 74 } | |
| 75 return ProfilerStubHelper.instance_; | |
| 76 }; | |
| 77 | |
| 78 | |
| 79 ProfilerStubHelper.prototype.StopProfiling = function(modules) { | |
| 80 this.activeProfilerModules_ &= ~modules; | |
| 81 }; | |
| 82 | |
| 83 | |
| 84 ProfilerStubHelper.prototype.StartProfiling = function(modules) { | |
| 85 var profModules = devtools.ProfilerAgent.ProfilerModules; | |
| 86 if (modules & profModules.PROFILER_MODULE_HEAP_SNAPSHOT) { | |
| 87 if (modules & profModules.PROFILER_MODULE_HEAP_STATS) { | |
| 88 this.log_ += | |
| 89 'heap-sample-begin,"Heap","allocated",' + | |
| 90 (new Date()).getTime() + '\n' + | |
| 91 'heap-sample-stats,"Heap","allocated",10000,1000\n'; | |
| 92 this.log_ += | |
| 93 'heap-sample-item,STRING_TYPE,100,1000\n' + | |
| 94 'heap-sample-item,CODE_TYPE,10,200\n' + | |
| 95 'heap-sample-item,MAP_TYPE,20,350\n'; | |
| 96 this.log_ += | |
| 97 ProfilerStubHelper.HeapSamples[this.heapProfSample_++]; | |
| 98 this.heapProfSample_ %= ProfilerStubHelper.HeapSamples.length; | |
| 99 this.log_ += | |
| 100 'heap-sample-end,"Heap","allocated"\n'; | |
| 101 } | |
| 102 } else { | |
| 103 if (modules & profModules.PROFILER_MODULE_CPU) { | |
| 104 this.log_ += ProfilerStubHelper.ProfilerLogBuffer; | |
| 105 } | |
| 106 this.activeProfilerModules_ |= modules; | |
| 107 } | |
| 108 }; | |
| 109 | |
| 110 | |
| 111 ProfilerStubHelper.prototype.GetActiveProfilerModules = function() { | |
| 112 var self = this; | |
| 113 setTimeout(function() { | |
| 114 RemoteProfilerAgent.DidGetActiveProfilerModules( | |
| 115 self.activeProfilerModules_); | |
| 116 }, 100); | |
| 117 }; | |
| 118 | |
| 119 | |
| 120 ProfilerStubHelper.prototype.GetLogLines = function(pos) { | |
| 121 var profModules = devtools.ProfilerAgent.ProfilerModules; | |
| 122 var logLines = this.log_.substr(pos); | |
| 123 setTimeout(function() { | |
| 124 RemoteProfilerAgent.DidGetLogLines(pos + logLines.length, logLines); | |
| 125 }, 100); | |
| 126 }; | |
| 127 | |
| 128 | |
| 129 ProfilerStubHelper.ProfilerLogBuffer = | |
| 130 'profiler,begin,1\n' + | 105 'profiler,begin,1\n' + |
| 131 'profiler,resume\n' + | 106 'profiler,resume\n' + |
| 132 'code-creation,LazyCompile,0x1000,256,"test1 http://aaa.js:1"\n' + | 107 'code-creation,LazyCompile,0x1000,256,"test1 http://aaa.js:1"\n' + |
| 133 'code-creation,LazyCompile,0x2000,256,"test2 http://bbb.js:2"\n' + | 108 'code-creation,LazyCompile,0x2000,256,"test2 http://bbb.js:2"\n' + |
| 134 'code-creation,LazyCompile,0x3000,256,"test3 http://ccc.js:3"\n' + | 109 'code-creation,LazyCompile,0x3000,256,"test3 http://ccc.js:3"\n' + |
| 135 'tick,0x1010,0x0,3\n' + | 110 'tick,0x1010,0x0,3\n' + |
| 136 'tick,0x2020,0x0,3,0x1010\n' + | 111 'tick,0x2020,0x0,3,0x1010\n' + |
| 137 'tick,0x2020,0x0,3,0x1010\n' + | 112 'tick,0x2020,0x0,3,0x1010\n' + |
| 138 'tick,0x3010,0x0,3,0x2020, 0x1010\n' + | 113 'tick,0x3010,0x0,3,0x2020, 0x1010\n' + |
| 139 'tick,0x2020,0x0,3,0x1010\n' + | 114 'tick,0x2020,0x0,3,0x1010\n' + |
| 140 'tick,0x2030,0x0,3,0x2020, 0x1010\n' + | 115 'tick,0x2030,0x0,3,0x2020, 0x1010\n' + |
| 141 'tick,0x2020,0x0,3,0x1010\n' + | 116 'tick,0x2020,0x0,3,0x1010\n' + |
| 142 'tick,0x1010,0x0,3\n' + | 117 'tick,0x1010,0x0,3\n' + |
| 143 'profiler,pause\n'; | 118 'profiler,pause\n'; |
| 144 | 119 |
| 145 | 120 |
| 146 ProfilerStubHelper.HeapSamples = [ | 121 RemoteDebuggerAgentStub.HeapSamples = [ |
| 147 'heap-js-cons-item,foo,1,100\n' + | 122 'heap-js-cons-item,foo,1,100\n' + |
| 148 'heap-js-cons-item,bar,20,2000\n' + | 123 'heap-js-cons-item,bar,20,2000\n' + |
| 149 'heap-js-cons-item,Object,5,100\n' + | 124 'heap-js-cons-item,Object,5,100\n' + |
| 150 'heap-js-ret-item,foo,bar;3\n' + | 125 'heap-js-ret-item,foo,bar;3\n' + |
| 151 'heap-js-ret-item,bar,foo;5\n' + | 126 'heap-js-ret-item,bar,foo;5\n' + |
| 152 'heap-js-ret-item,Object:0x1234,(roots);1\n', | 127 'heap-js-ret-item,Object:0x1234,(roots);1\n', |
| 153 | 128 |
| 154 'heap-js-cons-item,foo,2000,200000\n' + | 129 'heap-js-cons-item,foo,2000,200000\n' + |
| 155 'heap-js-cons-item,bar,10,1000\n' + | 130 'heap-js-cons-item,bar,10,1000\n' + |
| 156 'heap-js-cons-item,Object,6,120\n' + | 131 'heap-js-cons-item,Object,6,120\n' + |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 } else if ('{"seq":3,"type":"request","command":"scripts","arguments":{' + | 184 } else if ('{"seq":3,"type":"request","command":"scripts","arguments":{' + |
| 210 '"ids":[59],"includeSource":true}}' == cmd) { | 185 '"ids":[59],"includeSource":true}}' == cmd) { |
| 211 this.sendResponse_( | 186 this.sendResponse_( |
| 212 '{"seq":8,"request_seq":3,"type":"response","command":"scripts",' + | 187 '{"seq":8,"request_seq":3,"type":"response","command":"scripts",' + |
| 213 '"success":true,"body":[{"handle":1,"type":"script","name":' + | 188 '"success":true,"body":[{"handle":1,"type":"script","name":' + |
| 214 '"http://www/~test/t.js","id":59,"lineOffset":0,"columnOffset":0,' + | 189 '"http://www/~test/t.js","id":59,"lineOffset":0,"columnOffset":0,' + |
| 215 '"lineCount":1,"source":"function fib(n) {return n+1;}",' + | 190 '"lineCount":1,"source":"function fib(n) {return n+1;}",' + |
| 216 '"sourceLength":244,"scriptType":2,"compilationType":0,"context":{' + | 191 '"sourceLength":244,"scriptType":2,"compilationType":0,"context":{' + |
| 217 '"ref":0}}],"refs":[{"handle":0,"type":"context","data":"page,3}],"' + | 192 '"ref":0}}],"refs":[{"handle":0,"type":"context","data":"page,3}],"' + |
| 218 '"running":false}'); | 193 '"running":false}'); |
| 219 } else if (cmd.indexOf('"command":"profile"') != -1) { | |
| 220 var cmdObj = JSON.parse(cmd); | |
| 221 if (cmdObj.arguments.command == 'resume') { | |
| 222 ProfilerStubHelper.GetInstance().StartProfiling( | |
| 223 parseInt(cmdObj.arguments.modules)); | |
| 224 } else if (cmdObj.arguments.command == 'pause') { | |
| 225 ProfilerStubHelper.GetInstance().StopProfiling( | |
| 226 parseInt(cmdObj.arguments.modules)); | |
| 227 } else { | |
| 228 debugPrint('Unexpected profile command: ' + cmdObj.arguments.command); | |
| 229 } | |
| 230 } else { | 194 } else { |
| 231 debugPrint('Unexpected command: ' + cmd); | 195 debugPrint('Unexpected command: ' + cmd); |
| 232 } | 196 } |
| 233 }; | 197 }; |
| 234 | 198 |
| 235 | 199 |
| 236 RemoteDebuggerCommandExecutorStub.prototype.DebuggerPauseScript = function() { | 200 RemoteDebuggerCommandExecutorStub.prototype.DebuggerPauseScript = function() { |
| 237 }; | 201 }; |
| 238 | 202 |
| 239 | 203 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 259 }; | 223 }; |
| 260 | 224 |
| 261 | 225 |
| 262 DevToolsHostStub.prototype.setSetting = function() { | 226 DevToolsHostStub.prototype.setSetting = function() { |
| 263 }; | 227 }; |
| 264 | 228 |
| 265 | 229 |
| 266 window['RemoteDebuggerAgent'] = new RemoteDebuggerAgentStub(); | 230 window['RemoteDebuggerAgent'] = new RemoteDebuggerAgentStub(); |
| 267 window['RemoteDebuggerCommandExecutor'] = | 231 window['RemoteDebuggerCommandExecutor'] = |
| 268 new RemoteDebuggerCommandExecutorStub(); | 232 new RemoteDebuggerCommandExecutorStub(); |
| 269 window['RemoteProfilerAgent'] = new RemoteProfilerAgentStub(); | |
| 270 window['RemoteToolsAgent'] = new RemoteToolsAgentStub(); | 233 window['RemoteToolsAgent'] = new RemoteToolsAgentStub(); |
| 271 InspectorFrontendHost = new DevToolsHostStub(); | 234 InspectorFrontendHost = new DevToolsHostStub(); |
| 272 | 235 |
| 273 } | 236 } |
| OLD | NEW |