| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 /** | 25 /** |
| 26 * @implements {WebInspector.Searchable} | 26 * @implements {UI.Searchable} |
| 27 * @unrestricted | 27 * @unrestricted |
| 28 */ | 28 */ |
| 29 WebInspector.CPUProfileView = class extends WebInspector.ProfileView { | 29 Profiler.CPUProfileView = class extends Profiler.ProfileView { |
| 30 /** | 30 /** |
| 31 * @param {!WebInspector.CPUProfileHeader} profileHeader | 31 * @param {!Profiler.CPUProfileHeader} profileHeader |
| 32 */ | 32 */ |
| 33 constructor(profileHeader) { | 33 constructor(profileHeader) { |
| 34 super(); | 34 super(); |
| 35 this._profileHeader = profileHeader; | 35 this._profileHeader = profileHeader; |
| 36 this.profile = new WebInspector.CPUProfileDataModel(profileHeader._profile |
| profileHeader.protocolProfile()); | 36 this.profile = new SDK.CPUProfileDataModel(profileHeader._profile || profile
Header.protocolProfile()); |
| 37 this.adjustedTotal = this.profile.profileHead.total; | 37 this.adjustedTotal = this.profile.profileHead.total; |
| 38 this.adjustedTotal -= this.profile.idleNode ? this.profile.idleNode.total :
0; | 38 this.adjustedTotal -= this.profile.idleNode ? this.profile.idleNode.total :
0; |
| 39 this.initialize(new WebInspector.CPUProfileView.NodeFormatter(this)); | 39 this.initialize(new Profiler.CPUProfileView.NodeFormatter(this)); |
| 40 } | 40 } |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * @override | 43 * @override |
| 44 */ | 44 */ |
| 45 wasShown() { | 45 wasShown() { |
| 46 super.wasShown(); | 46 super.wasShown(); |
| 47 var lineLevelProfile = WebInspector.LineLevelProfile.instance(); | 47 var lineLevelProfile = Components.LineLevelProfile.instance(); |
| 48 lineLevelProfile.reset(); | 48 lineLevelProfile.reset(); |
| 49 lineLevelProfile.appendCPUProfile(this.profile); | 49 lineLevelProfile.appendCPUProfile(this.profile); |
| 50 } | 50 } |
| 51 | 51 |
| 52 /** | 52 /** |
| 53 * @override | 53 * @override |
| 54 * @param {string} columnId | 54 * @param {string} columnId |
| 55 * @return {string} | 55 * @return {string} |
| 56 */ | 56 */ |
| 57 columnHeader(columnId) { | 57 columnHeader(columnId) { |
| 58 switch (columnId) { | 58 switch (columnId) { |
| 59 case 'self': | 59 case 'self': |
| 60 return WebInspector.UIString('Self Time'); | 60 return Common.UIString('Self Time'); |
| 61 case 'total': | 61 case 'total': |
| 62 return WebInspector.UIString('Total Time'); | 62 return Common.UIString('Total Time'); |
| 63 } | 63 } |
| 64 return ''; | 64 return ''; |
| 65 } | 65 } |
| 66 | 66 |
| 67 /** | 67 /** |
| 68 * @override | 68 * @override |
| 69 * @return {!WebInspector.FlameChartDataProvider} | 69 * @return {!UI.FlameChartDataProvider} |
| 70 */ | 70 */ |
| 71 createFlameChartDataProvider() { | 71 createFlameChartDataProvider() { |
| 72 return new WebInspector.CPUFlameChartDataProvider(this.profile, this._profil
eHeader.target()); | 72 return new Profiler.CPUFlameChartDataProvider(this.profile, this._profileHea
der.target()); |
| 73 } | 73 } |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 /** | 76 /** |
| 77 * @unrestricted | 77 * @unrestricted |
| 78 */ | 78 */ |
| 79 WebInspector.CPUProfileType = class extends WebInspector.ProfileType { | 79 Profiler.CPUProfileType = class extends Profiler.ProfileType { |
| 80 constructor() { | 80 constructor() { |
| 81 super(WebInspector.CPUProfileType.TypeId, WebInspector.UIString('Record Java
Script CPU Profile')); | 81 super(Profiler.CPUProfileType.TypeId, Common.UIString('Record JavaScript CPU
Profile')); |
| 82 this._recording = false; | 82 this._recording = false; |
| 83 | 83 |
| 84 this._nextAnonymousConsoleProfileNumber = 1; | 84 this._nextAnonymousConsoleProfileNumber = 1; |
| 85 this._anonymousConsoleProfileIdToTitle = {}; | 85 this._anonymousConsoleProfileIdToTitle = {}; |
| 86 | 86 |
| 87 WebInspector.CPUProfileType.instance = this; | 87 Profiler.CPUProfileType.instance = this; |
| 88 WebInspector.targetManager.addModelListener( | 88 SDK.targetManager.addModelListener( |
| 89 WebInspector.CPUProfilerModel, WebInspector.CPUProfilerModel.Events.Cons
oleProfileStarted, | 89 SDK.CPUProfilerModel, SDK.CPUProfilerModel.Events.ConsoleProfileStarted, |
| 90 this._consoleProfileStarted, this); | 90 this._consoleProfileStarted, this); |
| 91 WebInspector.targetManager.addModelListener( | 91 SDK.targetManager.addModelListener( |
| 92 WebInspector.CPUProfilerModel, WebInspector.CPUProfilerModel.Events.Cons
oleProfileFinished, | 92 SDK.CPUProfilerModel, SDK.CPUProfilerModel.Events.ConsoleProfileFinished
, |
| 93 this._consoleProfileFinished, this); | 93 this._consoleProfileFinished, this); |
| 94 } | 94 } |
| 95 | 95 |
| 96 /** | 96 /** |
| 97 * @override | 97 * @override |
| 98 * @return {string} | 98 * @return {string} |
| 99 */ | 99 */ |
| 100 typeName() { | 100 typeName() { |
| 101 return 'CPU'; | 101 return 'CPU'; |
| 102 } | 102 } |
| 103 | 103 |
| 104 /** | 104 /** |
| 105 * @override | 105 * @override |
| 106 * @return {string} | 106 * @return {string} |
| 107 */ | 107 */ |
| 108 fileExtension() { | 108 fileExtension() { |
| 109 return '.cpuprofile'; | 109 return '.cpuprofile'; |
| 110 } | 110 } |
| 111 | 111 |
| 112 get buttonTooltip() { | 112 get buttonTooltip() { |
| 113 return this._recording ? WebInspector.UIString('Stop CPU profiling') : WebIn
spector.UIString('Start CPU profiling'); | 113 return this._recording ? Common.UIString('Stop CPU profiling') : Common.UISt
ring('Start CPU profiling'); |
| 114 } | 114 } |
| 115 | 115 |
| 116 /** | 116 /** |
| 117 * @override | 117 * @override |
| 118 * @return {boolean} | 118 * @return {boolean} |
| 119 */ | 119 */ |
| 120 buttonClicked() { | 120 buttonClicked() { |
| 121 if (this._recording) { | 121 if (this._recording) { |
| 122 this.stopRecordingProfile(); | 122 this.stopRecordingProfile(); |
| 123 return false; | 123 return false; |
| 124 } else { | 124 } else { |
| 125 this.startRecordingProfile(); | 125 this.startRecordingProfile(); |
| 126 return true; | 126 return true; |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 | 129 |
| 130 get treeItemTitle() { | 130 get treeItemTitle() { |
| 131 return WebInspector.UIString('CPU PROFILES'); | 131 return Common.UIString('CPU PROFILES'); |
| 132 } | 132 } |
| 133 | 133 |
| 134 get description() { | 134 get description() { |
| 135 return WebInspector.UIString( | 135 return Common.UIString( |
| 136 'CPU profiles show where the execution time is spent in your page\'s Jav
aScript functions.'); | 136 'CPU profiles show where the execution time is spent in your page\'s Jav
aScript functions.'); |
| 137 } | 137 } |
| 138 | 138 |
| 139 /** | 139 /** |
| 140 * @param {!WebInspector.Event} event | 140 * @param {!Common.Event} event |
| 141 */ | 141 */ |
| 142 _consoleProfileStarted(event) { | 142 _consoleProfileStarted(event) { |
| 143 var data = /** @type {!WebInspector.CPUProfilerModel.EventData} */ (event.da
ta); | 143 var data = /** @type {!SDK.CPUProfilerModel.EventData} */ (event.data); |
| 144 var resolvedTitle = data.title; | 144 var resolvedTitle = data.title; |
| 145 if (!resolvedTitle) { | 145 if (!resolvedTitle) { |
| 146 resolvedTitle = WebInspector.UIString('Profile %s', this._nextAnonymousCon
soleProfileNumber++); | 146 resolvedTitle = Common.UIString('Profile %s', this._nextAnonymousConsolePr
ofileNumber++); |
| 147 this._anonymousConsoleProfileIdToTitle[data.id] = resolvedTitle; | 147 this._anonymousConsoleProfileIdToTitle[data.id] = resolvedTitle; |
| 148 } | 148 } |
| 149 this._addMessageToConsole( | 149 this._addMessageToConsole( |
| 150 WebInspector.ConsoleMessage.MessageType.Profile, data.scriptLocation, | 150 SDK.ConsoleMessage.MessageType.Profile, data.scriptLocation, |
| 151 WebInspector.UIString('Profile \'%s\' started.', resolvedTitle)); | 151 Common.UIString('Profile \'%s\' started.', resolvedTitle)); |
| 152 } | 152 } |
| 153 | 153 |
| 154 /** | 154 /** |
| 155 * @param {!WebInspector.Event} event | 155 * @param {!Common.Event} event |
| 156 */ | 156 */ |
| 157 _consoleProfileFinished(event) { | 157 _consoleProfileFinished(event) { |
| 158 var data = /** @type {!WebInspector.CPUProfilerModel.EventData} */ (event.da
ta); | 158 var data = /** @type {!SDK.CPUProfilerModel.EventData} */ (event.data); |
| 159 var cpuProfile = /** @type {!Protocol.Profiler.Profile} */ (data.cpuProfile)
; | 159 var cpuProfile = /** @type {!Protocol.Profiler.Profile} */ (data.cpuProfile)
; |
| 160 var resolvedTitle = data.title; | 160 var resolvedTitle = data.title; |
| 161 if (typeof resolvedTitle === 'undefined') { | 161 if (typeof resolvedTitle === 'undefined') { |
| 162 resolvedTitle = this._anonymousConsoleProfileIdToTitle[data.id]; | 162 resolvedTitle = this._anonymousConsoleProfileIdToTitle[data.id]; |
| 163 delete this._anonymousConsoleProfileIdToTitle[data.id]; | 163 delete this._anonymousConsoleProfileIdToTitle[data.id]; |
| 164 } | 164 } |
| 165 var profile = new WebInspector.CPUProfileHeader(data.scriptLocation.target()
, this, resolvedTitle); | 165 var profile = new Profiler.CPUProfileHeader(data.scriptLocation.target(), th
is, resolvedTitle); |
| 166 profile.setProtocolProfile(cpuProfile); | 166 profile.setProtocolProfile(cpuProfile); |
| 167 this.addProfile(profile); | 167 this.addProfile(profile); |
| 168 this._addMessageToConsole( | 168 this._addMessageToConsole( |
| 169 WebInspector.ConsoleMessage.MessageType.ProfileEnd, data.scriptLocation, | 169 SDK.ConsoleMessage.MessageType.ProfileEnd, data.scriptLocation, |
| 170 WebInspector.UIString('Profile \'%s\' finished.', resolvedTitle)); | 170 Common.UIString('Profile \'%s\' finished.', resolvedTitle)); |
| 171 } | 171 } |
| 172 | 172 |
| 173 /** | 173 /** |
| 174 * @param {string} type | 174 * @param {string} type |
| 175 * @param {!WebInspector.DebuggerModel.Location} scriptLocation | 175 * @param {!SDK.DebuggerModel.Location} scriptLocation |
| 176 * @param {string} messageText | 176 * @param {string} messageText |
| 177 */ | 177 */ |
| 178 _addMessageToConsole(type, scriptLocation, messageText) { | 178 _addMessageToConsole(type, scriptLocation, messageText) { |
| 179 var script = scriptLocation.script(); | 179 var script = scriptLocation.script(); |
| 180 var target = scriptLocation.target(); | 180 var target = scriptLocation.target(); |
| 181 var message = new WebInspector.ConsoleMessage( | 181 var message = new SDK.ConsoleMessage( |
| 182 target, WebInspector.ConsoleMessage.MessageSource.ConsoleAPI, WebInspect
or.ConsoleMessage.MessageLevel.Debug, | 182 target, SDK.ConsoleMessage.MessageSource.ConsoleAPI, SDK.ConsoleMessage.
MessageLevel.Debug, |
| 183 messageText, type, undefined, undefined, undefined, undefined, [{ | 183 messageText, type, undefined, undefined, undefined, undefined, [{ |
| 184 functionName: '', | 184 functionName: '', |
| 185 scriptId: scriptLocation.scriptId, | 185 scriptId: scriptLocation.scriptId, |
| 186 url: script ? script.contentURL() : '', | 186 url: script ? script.contentURL() : '', |
| 187 lineNumber: scriptLocation.lineNumber, | 187 lineNumber: scriptLocation.lineNumber, |
| 188 columnNumber: scriptLocation.columnNumber || 0 | 188 columnNumber: scriptLocation.columnNumber || 0 |
| 189 }]); | 189 }]); |
| 190 | 190 |
| 191 target.consoleModel.addMessage(message); | 191 target.consoleModel.addMessage(message); |
| 192 } | 192 } |
| 193 | 193 |
| 194 startRecordingProfile() { | 194 startRecordingProfile() { |
| 195 var target = WebInspector.context.flavor(WebInspector.Target); | 195 var target = UI.context.flavor(SDK.Target); |
| 196 if (this._profileBeingRecorded || !target) | 196 if (this._profileBeingRecorded || !target) |
| 197 return; | 197 return; |
| 198 var profile = new WebInspector.CPUProfileHeader(target, this); | 198 var profile = new Profiler.CPUProfileHeader(target, this); |
| 199 this.setProfileBeingRecorded(profile); | 199 this.setProfileBeingRecorded(profile); |
| 200 WebInspector.targetManager.suspendAllTargets(); | 200 SDK.targetManager.suspendAllTargets(); |
| 201 this.addProfile(profile); | 201 this.addProfile(profile); |
| 202 profile.updateStatus(WebInspector.UIString('Recording\u2026')); | 202 profile.updateStatus(Common.UIString('Recording\u2026')); |
| 203 this._recording = true; | 203 this._recording = true; |
| 204 target.cpuProfilerModel.startRecording(); | 204 target.cpuProfilerModel.startRecording(); |
| 205 } | 205 } |
| 206 | 206 |
| 207 stopRecordingProfile() { | 207 stopRecordingProfile() { |
| 208 this._recording = false; | 208 this._recording = false; |
| 209 if (!this._profileBeingRecorded || !this._profileBeingRecorded.target()) | 209 if (!this._profileBeingRecorded || !this._profileBeingRecorded.target()) |
| 210 return; | 210 return; |
| 211 | 211 |
| 212 var recordedProfile; | 212 var recordedProfile; |
| 213 | 213 |
| 214 /** | 214 /** |
| 215 * @param {?Protocol.Profiler.Profile} profile | 215 * @param {?Protocol.Profiler.Profile} profile |
| 216 * @this {WebInspector.CPUProfileType} | 216 * @this {Profiler.CPUProfileType} |
| 217 */ | 217 */ |
| 218 function didStopProfiling(profile) { | 218 function didStopProfiling(profile) { |
| 219 if (!this._profileBeingRecorded) | 219 if (!this._profileBeingRecorded) |
| 220 return; | 220 return; |
| 221 console.assert(profile); | 221 console.assert(profile); |
| 222 this._profileBeingRecorded.setProtocolProfile(profile); | 222 this._profileBeingRecorded.setProtocolProfile(profile); |
| 223 this._profileBeingRecorded.updateStatus(''); | 223 this._profileBeingRecorded.updateStatus(''); |
| 224 recordedProfile = this._profileBeingRecorded; | 224 recordedProfile = this._profileBeingRecorded; |
| 225 this.setProfileBeingRecorded(null); | 225 this.setProfileBeingRecorded(null); |
| 226 } | 226 } |
| 227 | 227 |
| 228 /** | 228 /** |
| 229 * @this {WebInspector.CPUProfileType} | 229 * @this {Profiler.CPUProfileType} |
| 230 */ | 230 */ |
| 231 function fireEvent() { | 231 function fireEvent() { |
| 232 this.dispatchEventToListeners(WebInspector.ProfileType.Events.ProfileCompl
ete, recordedProfile); | 232 this.dispatchEventToListeners(Profiler.ProfileType.Events.ProfileComplete,
recordedProfile); |
| 233 } | 233 } |
| 234 | 234 |
| 235 this._profileBeingRecorded.target() | 235 this._profileBeingRecorded.target() |
| 236 .cpuProfilerModel.stopRecording() | 236 .cpuProfilerModel.stopRecording() |
| 237 .then(didStopProfiling.bind(this)) | 237 .then(didStopProfiling.bind(this)) |
| 238 .then(WebInspector.targetManager.resumeAllTargets.bind(WebInspector.targ
etManager)) | 238 .then(SDK.targetManager.resumeAllTargets.bind(SDK.targetManager)) |
| 239 .then(fireEvent.bind(this)); | 239 .then(fireEvent.bind(this)); |
| 240 } | 240 } |
| 241 | 241 |
| 242 /** | 242 /** |
| 243 * @override | 243 * @override |
| 244 * @param {string} title | 244 * @param {string} title |
| 245 * @return {!WebInspector.ProfileHeader} | 245 * @return {!Profiler.ProfileHeader} |
| 246 */ | 246 */ |
| 247 createProfileLoadedFromFile(title) { | 247 createProfileLoadedFromFile(title) { |
| 248 return new WebInspector.CPUProfileHeader(null, this, title); | 248 return new Profiler.CPUProfileHeader(null, this, title); |
| 249 } | 249 } |
| 250 | 250 |
| 251 /** | 251 /** |
| 252 * @override | 252 * @override |
| 253 */ | 253 */ |
| 254 profileBeingRecordedRemoved() { | 254 profileBeingRecordedRemoved() { |
| 255 this.stopRecordingProfile(); | 255 this.stopRecordingProfile(); |
| 256 } | 256 } |
| 257 }; | 257 }; |
| 258 | 258 |
| 259 WebInspector.CPUProfileType.TypeId = 'CPU'; | 259 Profiler.CPUProfileType.TypeId = 'CPU'; |
| 260 | 260 |
| 261 /** | 261 /** |
| 262 * @unrestricted | 262 * @unrestricted |
| 263 */ | 263 */ |
| 264 WebInspector.CPUProfileHeader = class extends WebInspector.WritableProfileHeader
{ | 264 Profiler.CPUProfileHeader = class extends Profiler.WritableProfileHeader { |
| 265 /** | 265 /** |
| 266 * @param {?WebInspector.Target} target | 266 * @param {?SDK.Target} target |
| 267 * @param {!WebInspector.CPUProfileType} type | 267 * @param {!Profiler.CPUProfileType} type |
| 268 * @param {string=} title | 268 * @param {string=} title |
| 269 */ | 269 */ |
| 270 constructor(target, type, title) { | 270 constructor(target, type, title) { |
| 271 super(target, type, title); | 271 super(target, type, title); |
| 272 } | 272 } |
| 273 | 273 |
| 274 /** | 274 /** |
| 275 * @override | 275 * @override |
| 276 * @return {!WebInspector.ProfileView} | 276 * @return {!Profiler.ProfileView} |
| 277 */ | 277 */ |
| 278 createView() { | 278 createView() { |
| 279 return new WebInspector.CPUProfileView(this); | 279 return new Profiler.CPUProfileView(this); |
| 280 } | 280 } |
| 281 | 281 |
| 282 /** | 282 /** |
| 283 * @return {!Protocol.Profiler.Profile} | 283 * @return {!Protocol.Profiler.Profile} |
| 284 */ | 284 */ |
| 285 protocolProfile() { | 285 protocolProfile() { |
| 286 return this._protocolProfile; | 286 return this._protocolProfile; |
| 287 } | 287 } |
| 288 }; | 288 }; |
| 289 | 289 |
| 290 /** | 290 /** |
| 291 * @implements {WebInspector.ProfileDataGridNode.Formatter} | 291 * @implements {Profiler.ProfileDataGridNode.Formatter} |
| 292 * @unrestricted | 292 * @unrestricted |
| 293 */ | 293 */ |
| 294 WebInspector.CPUProfileView.NodeFormatter = class { | 294 Profiler.CPUProfileView.NodeFormatter = class { |
| 295 constructor(profileView) { | 295 constructor(profileView) { |
| 296 this._profileView = profileView; | 296 this._profileView = profileView; |
| 297 } | 297 } |
| 298 | 298 |
| 299 /** | 299 /** |
| 300 * @override | 300 * @override |
| 301 * @param {number} value | 301 * @param {number} value |
| 302 * @return {string} | 302 * @return {string} |
| 303 */ | 303 */ |
| 304 formatValue(value) { | 304 formatValue(value) { |
| 305 return WebInspector.UIString('%.1f\u2009ms', value); | 305 return Common.UIString('%.1f\u2009ms', value); |
| 306 } | 306 } |
| 307 | 307 |
| 308 /** | 308 /** |
| 309 * @override | 309 * @override |
| 310 * @param {number} value | 310 * @param {number} value |
| 311 * @param {!WebInspector.ProfileDataGridNode} node | 311 * @param {!Profiler.ProfileDataGridNode} node |
| 312 * @return {string} | 312 * @return {string} |
| 313 */ | 313 */ |
| 314 formatPercent(value, node) { | 314 formatPercent(value, node) { |
| 315 return node.profileNode === this._profileView.profile.idleNode ? '' : WebIns
pector.UIString('%.2f\u2009%%', value); | 315 return node.profileNode === this._profileView.profile.idleNode ? '' : Common
.UIString('%.2f\u2009%%', value); |
| 316 } | 316 } |
| 317 | 317 |
| 318 /** | 318 /** |
| 319 * @override | 319 * @override |
| 320 * @param {!WebInspector.ProfileDataGridNode} node | 320 * @param {!Profiler.ProfileDataGridNode} node |
| 321 * @return {?Element} | 321 * @return {?Element} |
| 322 */ | 322 */ |
| 323 linkifyNode(node) { | 323 linkifyNode(node) { |
| 324 return this._profileView.linkifier().maybeLinkifyConsoleCallFrame( | 324 return this._profileView.linkifier().maybeLinkifyConsoleCallFrame( |
| 325 this._profileView.target(), node.profileNode.callFrame, 'profile-node-fi
le'); | 325 this._profileView.target(), node.profileNode.callFrame, 'profile-node-fi
le'); |
| 326 } | 326 } |
| 327 }; | 327 }; |
| 328 | 328 |
| 329 /** | 329 /** |
| 330 * @unrestricted | 330 * @unrestricted |
| 331 */ | 331 */ |
| 332 WebInspector.CPUFlameChartDataProvider = class extends WebInspector.ProfileFlame
ChartDataProvider { | 332 Profiler.CPUFlameChartDataProvider = class extends Profiler.ProfileFlameChartDat
aProvider { |
| 333 /** | 333 /** |
| 334 * @param {!WebInspector.CPUProfileDataModel} cpuProfile | 334 * @param {!SDK.CPUProfileDataModel} cpuProfile |
| 335 * @param {?WebInspector.Target} target | 335 * @param {?SDK.Target} target |
| 336 */ | 336 */ |
| 337 constructor(cpuProfile, target) { | 337 constructor(cpuProfile, target) { |
| 338 super(target); | 338 super(target); |
| 339 this._cpuProfile = cpuProfile; | 339 this._cpuProfile = cpuProfile; |
| 340 } | 340 } |
| 341 | 341 |
| 342 /** | 342 /** |
| 343 * @override | 343 * @override |
| 344 * @return {!WebInspector.FlameChart.TimelineData} | 344 * @return {!UI.FlameChart.TimelineData} |
| 345 */ | 345 */ |
| 346 _calculateTimelineData() { | 346 _calculateTimelineData() { |
| 347 /** @type {!Array.<?WebInspector.CPUFlameChartDataProvider.ChartEntry>} */ | 347 /** @type {!Array.<?Profiler.CPUFlameChartDataProvider.ChartEntry>} */ |
| 348 var entries = []; | 348 var entries = []; |
| 349 /** @type {!Array.<number>} */ | 349 /** @type {!Array.<number>} */ |
| 350 var stack = []; | 350 var stack = []; |
| 351 var maxDepth = 5; | 351 var maxDepth = 5; |
| 352 | 352 |
| 353 function onOpenFrame() { | 353 function onOpenFrame() { |
| 354 stack.push(entries.length); | 354 stack.push(entries.length); |
| 355 // Reserve space for the entry, as they have to be ordered by startTime. | 355 // Reserve space for the entry, as they have to be ordered by startTime. |
| 356 // The entry itself will be put there in onCloseFrame. | 356 // The entry itself will be put there in onCloseFrame. |
| 357 entries.push(null); | 357 entries.push(null); |
| 358 } | 358 } |
| 359 /** | 359 /** |
| 360 * @param {number} depth | 360 * @param {number} depth |
| 361 * @param {!WebInspector.CPUProfileNode} node | 361 * @param {!SDK.CPUProfileNode} node |
| 362 * @param {number} startTime | 362 * @param {number} startTime |
| 363 * @param {number} totalTime | 363 * @param {number} totalTime |
| 364 * @param {number} selfTime | 364 * @param {number} selfTime |
| 365 */ | 365 */ |
| 366 function onCloseFrame(depth, node, startTime, totalTime, selfTime) { | 366 function onCloseFrame(depth, node, startTime, totalTime, selfTime) { |
| 367 var index = stack.pop(); | 367 var index = stack.pop(); |
| 368 entries[index] = | 368 entries[index] = |
| 369 new WebInspector.CPUFlameChartDataProvider.ChartEntry(depth, totalTime
, startTime, selfTime, node); | 369 new Profiler.CPUFlameChartDataProvider.ChartEntry(depth, totalTime, st
artTime, selfTime, node); |
| 370 maxDepth = Math.max(maxDepth, depth); | 370 maxDepth = Math.max(maxDepth, depth); |
| 371 } | 371 } |
| 372 this._cpuProfile.forEachFrame(onOpenFrame, onCloseFrame); | 372 this._cpuProfile.forEachFrame(onOpenFrame, onCloseFrame); |
| 373 | 373 |
| 374 /** @type {!Array<!WebInspector.CPUProfileNode>} */ | 374 /** @type {!Array<!SDK.CPUProfileNode>} */ |
| 375 var entryNodes = new Array(entries.length); | 375 var entryNodes = new Array(entries.length); |
| 376 var entryLevels = new Uint16Array(entries.length); | 376 var entryLevels = new Uint16Array(entries.length); |
| 377 var entryTotalTimes = new Float32Array(entries.length); | 377 var entryTotalTimes = new Float32Array(entries.length); |
| 378 var entrySelfTimes = new Float32Array(entries.length); | 378 var entrySelfTimes = new Float32Array(entries.length); |
| 379 var entryStartTimes = new Float64Array(entries.length); | 379 var entryStartTimes = new Float64Array(entries.length); |
| 380 var minimumBoundary = this.minimumBoundary(); | 380 var minimumBoundary = this.minimumBoundary(); |
| 381 | 381 |
| 382 for (var i = 0; i < entries.length; ++i) { | 382 for (var i = 0; i < entries.length; ++i) { |
| 383 var entry = entries[i]; | 383 var entry = entries[i]; |
| 384 entryNodes[i] = entry.node; | 384 entryNodes[i] = entry.node; |
| 385 entryLevels[i] = entry.depth; | 385 entryLevels[i] = entry.depth; |
| 386 entryTotalTimes[i] = entry.duration; | 386 entryTotalTimes[i] = entry.duration; |
| 387 entryStartTimes[i] = entry.startTime; | 387 entryStartTimes[i] = entry.startTime; |
| 388 entrySelfTimes[i] = entry.selfTime; | 388 entrySelfTimes[i] = entry.selfTime; |
| 389 } | 389 } |
| 390 | 390 |
| 391 this._maxStackDepth = maxDepth; | 391 this._maxStackDepth = maxDepth; |
| 392 | 392 |
| 393 this._timelineData = new WebInspector.FlameChart.TimelineData(entryLevels, e
ntryTotalTimes, entryStartTimes, null); | 393 this._timelineData = new UI.FlameChart.TimelineData(entryLevels, entryTotalT
imes, entryStartTimes, null); |
| 394 | 394 |
| 395 /** @type {!Array<!WebInspector.CPUProfileNode>} */ | 395 /** @type {!Array<!SDK.CPUProfileNode>} */ |
| 396 this._entryNodes = entryNodes; | 396 this._entryNodes = entryNodes; |
| 397 this._entrySelfTimes = entrySelfTimes; | 397 this._entrySelfTimes = entrySelfTimes; |
| 398 | 398 |
| 399 return this._timelineData; | 399 return this._timelineData; |
| 400 } | 400 } |
| 401 | 401 |
| 402 /** | 402 /** |
| 403 * @override | 403 * @override |
| 404 * @param {number} entryIndex | 404 * @param {number} entryIndex |
| 405 * @return {?Element} | 405 * @return {?Element} |
| (...skipping 13 matching lines...) Expand all Loading... |
| 419 entryInfo.push({title: title, value: value}); | 419 entryInfo.push({title: title, value: value}); |
| 420 } | 420 } |
| 421 /** | 421 /** |
| 422 * @param {number} ms | 422 * @param {number} ms |
| 423 * @return {string} | 423 * @return {string} |
| 424 */ | 424 */ |
| 425 function millisecondsToString(ms) { | 425 function millisecondsToString(ms) { |
| 426 if (ms === 0) | 426 if (ms === 0) |
| 427 return '0'; | 427 return '0'; |
| 428 if (ms < 1000) | 428 if (ms < 1000) |
| 429 return WebInspector.UIString('%.1f\u2009ms', ms); | 429 return Common.UIString('%.1f\u2009ms', ms); |
| 430 return Number.secondsToString(ms / 1000, true); | 430 return Number.secondsToString(ms / 1000, true); |
| 431 } | 431 } |
| 432 var name = WebInspector.beautifyFunctionName(node.functionName); | 432 var name = UI.beautifyFunctionName(node.functionName); |
| 433 pushEntryInfoRow(WebInspector.UIString('Name'), name); | 433 pushEntryInfoRow(Common.UIString('Name'), name); |
| 434 var selfTime = millisecondsToString(this._entrySelfTimes[entryIndex]); | 434 var selfTime = millisecondsToString(this._entrySelfTimes[entryIndex]); |
| 435 var totalTime = millisecondsToString(timelineData.entryTotalTimes[entryIndex
]); | 435 var totalTime = millisecondsToString(timelineData.entryTotalTimes[entryIndex
]); |
| 436 pushEntryInfoRow(WebInspector.UIString('Self time'), selfTime); | 436 pushEntryInfoRow(Common.UIString('Self time'), selfTime); |
| 437 pushEntryInfoRow(WebInspector.UIString('Total time'), totalTime); | 437 pushEntryInfoRow(Common.UIString('Total time'), totalTime); |
| 438 var linkifier = new WebInspector.Linkifier(); | 438 var linkifier = new Components.Linkifier(); |
| 439 var link = linkifier.maybeLinkifyConsoleCallFrame(this._target, node.callFra
me); | 439 var link = linkifier.maybeLinkifyConsoleCallFrame(this._target, node.callFra
me); |
| 440 if (link) | 440 if (link) |
| 441 pushEntryInfoRow(WebInspector.UIString('URL'), link.textContent); | 441 pushEntryInfoRow(Common.UIString('URL'), link.textContent); |
| 442 linkifier.dispose(); | 442 linkifier.dispose(); |
| 443 pushEntryInfoRow(WebInspector.UIString('Aggregated self time'), Number.secon
dsToString(node.self / 1000, true)); | 443 pushEntryInfoRow(Common.UIString('Aggregated self time'), Number.secondsToSt
ring(node.self / 1000, true)); |
| 444 pushEntryInfoRow(WebInspector.UIString('Aggregated total time'), Number.seco
ndsToString(node.total / 1000, true)); | 444 pushEntryInfoRow(Common.UIString('Aggregated total time'), Number.secondsToS
tring(node.total / 1000, true)); |
| 445 if (node.deoptReason) | 445 if (node.deoptReason) |
| 446 pushEntryInfoRow(WebInspector.UIString('Not optimized'), node.deoptReason)
; | 446 pushEntryInfoRow(Common.UIString('Not optimized'), node.deoptReason); |
| 447 | 447 |
| 448 return WebInspector.ProfileView.buildPopoverTable(entryInfo); | 448 return Profiler.ProfileView.buildPopoverTable(entryInfo); |
| 449 } | 449 } |
| 450 }; | 450 }; |
| 451 | 451 |
| 452 /** | 452 /** |
| 453 * @unrestricted | 453 * @unrestricted |
| 454 */ | 454 */ |
| 455 WebInspector.CPUFlameChartDataProvider.ChartEntry = class { | 455 Profiler.CPUFlameChartDataProvider.ChartEntry = class { |
| 456 /** | 456 /** |
| 457 * @param {number} depth | 457 * @param {number} depth |
| 458 * @param {number} duration | 458 * @param {number} duration |
| 459 * @param {number} startTime | 459 * @param {number} startTime |
| 460 * @param {number} selfTime | 460 * @param {number} selfTime |
| 461 * @param {!WebInspector.CPUProfileNode} node | 461 * @param {!SDK.CPUProfileNode} node |
| 462 */ | 462 */ |
| 463 constructor(depth, duration, startTime, selfTime, node) { | 463 constructor(depth, duration, startTime, selfTime, node) { |
| 464 this.depth = depth; | 464 this.depth = depth; |
| 465 this.duration = duration; | 465 this.duration = duration; |
| 466 this.startTime = startTime; | 466 this.startTime = startTime; |
| 467 this.selfTime = selfTime; | 467 this.selfTime = selfTime; |
| 468 this.node = node; | 468 this.node = node; |
| 469 } | 469 } |
| 470 }; | 470 }; |
| OLD | NEW |