| 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_ = ''; | |
| 21 }; | 16 }; |
| 22 | 17 |
| 23 | 18 |
| 24 RemoteDebuggerAgentStub.prototype.GetContextId = function() { | 19 RemoteDebuggerAgentStub.prototype.GetContextId = function() { |
| 25 RemoteDebuggerAgent.SetContextId(3); | 20 RemoteDebuggerAgent.SetContextId(3); |
| 26 }; | 21 }; |
| 27 | 22 |
| 28 | 23 |
| 29 RemoteDebuggerAgentStub.prototype.StopProfiling = function(modules) { | 24 /** |
| 30 this.activeProfilerModules_ &= ~modules; | 25 * @constructor |
| 26 */ |
| 27 RemoteProfilerAgentStub = function() { |
| 31 }; | 28 }; |
| 32 | 29 |
| 33 | 30 |
| 34 RemoteDebuggerAgentStub.prototype.StartProfiling = function(modules) { | 31 RemoteProfilerAgentStub.prototype.GetActiveProfilerModules = function() { |
| 35 var profModules = devtools.DebuggerAgent.ProfilerModules; | 32 ProfilerStubHelper.GetInstance().GetActiveProfilerModules(); |
| 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 } | |
| 54 }; | 33 }; |
| 55 | 34 |
| 56 | 35 |
| 57 RemoteDebuggerAgentStub.prototype.GetActiveProfilerModules = function() { | 36 RemoteProfilerAgentStub.prototype.GetLogLines = function(pos) { |
| 58 var self = this; | 37 ProfilerStubHelper.GetInstance().GetLogLines(pos); |
| 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); | |
| 82 }; | 38 }; |
| 83 | 39 |
| 84 | 40 |
| 85 /** | 41 /** |
| 86 * @constructor | 42 * @constructor |
| 87 */ | 43 */ |
| 88 RemoteToolsAgentStub = function() { | 44 RemoteToolsAgentStub = function() { |
| 89 }; | 45 }; |
| 90 | 46 |
| 91 | 47 |
| 92 RemoteToolsAgentStub.prototype.DispatchOnInjectedScript = function() { | 48 RemoteToolsAgentStub.prototype.DispatchOnInjectedScript = function() { |
| 93 }; | 49 }; |
| 94 | 50 |
| 95 | 51 |
| 96 RemoteToolsAgentStub.prototype.DispatchOnInspectorController = function() { | 52 RemoteToolsAgentStub.prototype.DispatchOnInspectorController = function() { |
| 97 }; | 53 }; |
| 98 | 54 |
| 99 | 55 |
| 100 RemoteToolsAgentStub.prototype.ExecuteVoidJavaScript = function() { | 56 RemoteToolsAgentStub.prototype.ExecuteVoidJavaScript = function() { |
| 101 }; | 57 }; |
| 102 | 58 |
| 103 | 59 |
| 104 RemoteDebuggerAgentStub.ProfilerLogBuffer = | 60 /** |
| 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 = |
| 105 'profiler,begin,1\n' + | 130 'profiler,begin,1\n' + |
| 106 'profiler,resume\n' + | 131 'profiler,resume\n' + |
| 107 'code-creation,LazyCompile,0x1000,256,"test1 http://aaa.js:1"\n' + | 132 'code-creation,LazyCompile,0x1000,256,"test1 http://aaa.js:1"\n' + |
| 108 'code-creation,LazyCompile,0x2000,256,"test2 http://bbb.js:2"\n' + | 133 'code-creation,LazyCompile,0x2000,256,"test2 http://bbb.js:2"\n' + |
| 109 'code-creation,LazyCompile,0x3000,256,"test3 http://ccc.js:3"\n' + | 134 'code-creation,LazyCompile,0x3000,256,"test3 http://ccc.js:3"\n' + |
| 110 'tick,0x1010,0x0,3\n' + | 135 'tick,0x1010,0x0,3\n' + |
| 111 'tick,0x2020,0x0,3,0x1010\n' + | 136 'tick,0x2020,0x0,3,0x1010\n' + |
| 112 'tick,0x2020,0x0,3,0x1010\n' + | 137 'tick,0x2020,0x0,3,0x1010\n' + |
| 113 'tick,0x3010,0x0,3,0x2020, 0x1010\n' + | 138 'tick,0x3010,0x0,3,0x2020, 0x1010\n' + |
| 114 'tick,0x2020,0x0,3,0x1010\n' + | 139 'tick,0x2020,0x0,3,0x1010\n' + |
| 115 'tick,0x2030,0x0,3,0x2020, 0x1010\n' + | 140 'tick,0x2030,0x0,3,0x2020, 0x1010\n' + |
| 116 'tick,0x2020,0x0,3,0x1010\n' + | 141 'tick,0x2020,0x0,3,0x1010\n' + |
| 117 'tick,0x1010,0x0,3\n' + | 142 'tick,0x1010,0x0,3\n' + |
| 118 'profiler,pause\n'; | 143 'profiler,pause\n'; |
| 119 | 144 |
| 120 | 145 |
| 121 RemoteDebuggerAgentStub.HeapSamples = [ | 146 ProfilerStubHelper.HeapSamples = [ |
| 122 'heap-js-cons-item,foo,1,100\n' + | 147 'heap-js-cons-item,foo,1,100\n' + |
| 123 'heap-js-cons-item,bar,20,2000\n' + | 148 'heap-js-cons-item,bar,20,2000\n' + |
| 124 'heap-js-cons-item,Object,5,100\n' + | 149 'heap-js-cons-item,Object,5,100\n' + |
| 125 'heap-js-ret-item,foo,bar;3\n' + | 150 'heap-js-ret-item,foo,bar;3\n' + |
| 126 'heap-js-ret-item,bar,foo;5\n' + | 151 'heap-js-ret-item,bar,foo;5\n' + |
| 127 'heap-js-ret-item,Object:0x1234,(roots);1\n', | 152 'heap-js-ret-item,Object:0x1234,(roots);1\n', |
| 128 | 153 |
| 129 'heap-js-cons-item,foo,2000,200000\n' + | 154 'heap-js-cons-item,foo,2000,200000\n' + |
| 130 'heap-js-cons-item,bar,10,1000\n' + | 155 'heap-js-cons-item,bar,10,1000\n' + |
| 131 'heap-js-cons-item,Object,6,120\n' + | 156 'heap-js-cons-item,Object,6,120\n' + |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 } else if ('{"seq":3,"type":"request","command":"scripts","arguments":{' + | 209 } else if ('{"seq":3,"type":"request","command":"scripts","arguments":{' + |
| 185 '"ids":[59],"includeSource":true}}' == cmd) { | 210 '"ids":[59],"includeSource":true}}' == cmd) { |
| 186 this.sendResponse_( | 211 this.sendResponse_( |
| 187 '{"seq":8,"request_seq":3,"type":"response","command":"scripts",' + | 212 '{"seq":8,"request_seq":3,"type":"response","command":"scripts",' + |
| 188 '"success":true,"body":[{"handle":1,"type":"script","name":' + | 213 '"success":true,"body":[{"handle":1,"type":"script","name":' + |
| 189 '"http://www/~test/t.js","id":59,"lineOffset":0,"columnOffset":0,' + | 214 '"http://www/~test/t.js","id":59,"lineOffset":0,"columnOffset":0,' + |
| 190 '"lineCount":1,"source":"function fib(n) {return n+1;}",' + | 215 '"lineCount":1,"source":"function fib(n) {return n+1;}",' + |
| 191 '"sourceLength":244,"scriptType":2,"compilationType":0,"context":{' + | 216 '"sourceLength":244,"scriptType":2,"compilationType":0,"context":{' + |
| 192 '"ref":0}}],"refs":[{"handle":0,"type":"context","data":"page,3}],"' + | 217 '"ref":0}}],"refs":[{"handle":0,"type":"context","data":"page,3}],"' + |
| 193 '"running":false}'); | 218 '"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 } |
| 194 } else { | 230 } else { |
| 195 debugPrint('Unexpected command: ' + cmd); | 231 debugPrint('Unexpected command: ' + cmd); |
| 196 } | 232 } |
| 197 }; | 233 }; |
| 198 | 234 |
| 199 | 235 |
| 200 RemoteDebuggerCommandExecutorStub.prototype.DebuggerPauseScript = function() { | 236 RemoteDebuggerCommandExecutorStub.prototype.DebuggerPauseScript = function() { |
| 201 }; | 237 }; |
| 202 | 238 |
| 203 | 239 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 223 }; | 259 }; |
| 224 | 260 |
| 225 | 261 |
| 226 DevToolsHostStub.prototype.setSetting = function() { | 262 DevToolsHostStub.prototype.setSetting = function() { |
| 227 }; | 263 }; |
| 228 | 264 |
| 229 | 265 |
| 230 window['RemoteDebuggerAgent'] = new RemoteDebuggerAgentStub(); | 266 window['RemoteDebuggerAgent'] = new RemoteDebuggerAgentStub(); |
| 231 window['RemoteDebuggerCommandExecutor'] = | 267 window['RemoteDebuggerCommandExecutor'] = |
| 232 new RemoteDebuggerCommandExecutorStub(); | 268 new RemoteDebuggerCommandExecutorStub(); |
| 269 window['RemoteProfilerAgent'] = new RemoteProfilerAgentStub(); |
| 233 window['RemoteToolsAgent'] = new RemoteToolsAgentStub(); | 270 window['RemoteToolsAgent'] = new RemoteToolsAgentStub(); |
| 234 InspectorFrontendHost = new DevToolsHostStub(); | 271 InspectorFrontendHost = new DevToolsHostStub(); |
| 235 | 272 |
| 236 } | 273 } |
| OLD | NEW |