| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 * @unrestricted | 5 * @unrestricted |
| 6 */ | 6 */ |
| 7 WebInspector.LineLevelProfile = class { | 7 Components.LineLevelProfile = class { |
| 8 constructor() { | 8 constructor() { |
| 9 this._locationPool = new WebInspector.LiveLocationPool(); | 9 this._locationPool = new Bindings.LiveLocationPool(); |
| 10 this.reset(); | 10 this.reset(); |
| 11 } | 11 } |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * @return {!WebInspector.LineLevelProfile} | 14 * @return {!Components.LineLevelProfile} |
| 15 */ | 15 */ |
| 16 static instance() { | 16 static instance() { |
| 17 if (!WebInspector.LineLevelProfile._instance) | 17 if (!Components.LineLevelProfile._instance) |
| 18 WebInspector.LineLevelProfile._instance = new WebInspector.LineLevelProfil
e(); | 18 Components.LineLevelProfile._instance = new Components.LineLevelProfile(); |
| 19 return WebInspector.LineLevelProfile._instance; | 19 return Components.LineLevelProfile._instance; |
| 20 } | 20 } |
| 21 | 21 |
| 22 /** | 22 /** |
| 23 * @param {!WebInspector.CPUProfileDataModel} profile | 23 * @param {!SDK.CPUProfileDataModel} profile |
| 24 */ | 24 */ |
| 25 appendCPUProfile(profile) { | 25 appendCPUProfile(profile) { |
| 26 var nodesToGo = [profile.profileHead]; | 26 var nodesToGo = [profile.profileHead]; |
| 27 var sampleDuration = (profile.profileEndTime - profile.profileStartTime) / p
rofile.totalHitCount; | 27 var sampleDuration = (profile.profileEndTime - profile.profileStartTime) / p
rofile.totalHitCount; |
| 28 while (nodesToGo.length) { | 28 while (nodesToGo.length) { |
| 29 var nodes = nodesToGo.pop().children; | 29 var nodes = nodesToGo.pop().children; |
| 30 for (var i = 0; i < nodes.length; ++i) { | 30 for (var i = 0; i < nodes.length; ++i) { |
| 31 var node = nodes[i]; | 31 var node = nodes[i]; |
| 32 nodesToGo.push(node); | 32 nodesToGo.push(node); |
| 33 if (!node.url || !node.positionTicks) | 33 if (!node.url || !node.positionTicks) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 59 return; | 59 return; |
| 60 this._updateTimer = setTimeout(() => { | 60 this._updateTimer = setTimeout(() => { |
| 61 this._updateTimer = null; | 61 this._updateTimer = null; |
| 62 this._doUpdate(); | 62 this._doUpdate(); |
| 63 }, 0); | 63 }, 0); |
| 64 } | 64 } |
| 65 | 65 |
| 66 _doUpdate() { | 66 _doUpdate() { |
| 67 // TODO(alph): use scriptId instead of urls for the target. | 67 // TODO(alph): use scriptId instead of urls for the target. |
| 68 this._locationPool.disposeAll(); | 68 this._locationPool.disposeAll(); |
| 69 WebInspector.workspace.uiSourceCodes().forEach( | 69 Workspace.workspace.uiSourceCodes().forEach( |
| 70 uiSourceCode => uiSourceCode.removeAllLineDecorations(WebInspector.LineL
evelProfile.LineDecorator.type)); | 70 uiSourceCode => uiSourceCode.removeAllLineDecorations(Components.LineLev
elProfile.LineDecorator.type)); |
| 71 for (var fileInfo of this._files) { | 71 for (var fileInfo of this._files) { |
| 72 var url = /** @type {string} */ (fileInfo[0]); | 72 var url = /** @type {string} */ (fileInfo[0]); |
| 73 var uiSourceCode = WebInspector.workspace.uiSourceCodeForURL(url); | 73 var uiSourceCode = Workspace.workspace.uiSourceCodeForURL(url); |
| 74 if (!uiSourceCode) | 74 if (!uiSourceCode) |
| 75 continue; | 75 continue; |
| 76 var target = | 76 var target = |
| 77 WebInspector.NetworkProject.targetForUISourceCode(uiSourceCode) || Web
Inspector.targetManager.mainTarget(); | 77 Bindings.NetworkProject.targetForUISourceCode(uiSourceCode) || SDK.tar
getManager.mainTarget(); |
| 78 var debuggerModel = target ? WebInspector.DebuggerModel.fromTarget(target)
: null; | 78 var debuggerModel = target ? SDK.DebuggerModel.fromTarget(target) : null; |
| 79 if (!debuggerModel) | 79 if (!debuggerModel) |
| 80 continue; | 80 continue; |
| 81 for (var lineInfo of fileInfo[1]) { | 81 for (var lineInfo of fileInfo[1]) { |
| 82 var line = lineInfo[0] - 1; | 82 var line = lineInfo[0] - 1; |
| 83 var time = lineInfo[1]; | 83 var time = lineInfo[1]; |
| 84 var rawLocation = debuggerModel.createRawLocationByURL(url, line, 0); | 84 var rawLocation = debuggerModel.createRawLocationByURL(url, line, 0); |
| 85 if (rawLocation) | 85 if (rawLocation) |
| 86 new WebInspector.LineLevelProfile.Presentation(rawLocation, time, this
._locationPool); | 86 new Components.LineLevelProfile.Presentation(rawLocation, time, this._
locationPool); |
| 87 else if (uiSourceCode) | 87 else if (uiSourceCode) |
| 88 uiSourceCode.addLineDecoration(line, WebInspector.LineLevelProfile.Lin
eDecorator.type, time); | 88 uiSourceCode.addLineDecoration(line, Components.LineLevelProfile.LineD
ecorator.type, time); |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 | 94 |
| 95 /** | 95 /** |
| 96 * @unrestricted | 96 * @unrestricted |
| 97 */ | 97 */ |
| 98 WebInspector.LineLevelProfile.Presentation = class { | 98 Components.LineLevelProfile.Presentation = class { |
| 99 /** | 99 /** |
| 100 * @param {!WebInspector.DebuggerModel.Location} rawLocation | 100 * @param {!SDK.DebuggerModel.Location} rawLocation |
| 101 * @param {number} time | 101 * @param {number} time |
| 102 * @param {!WebInspector.LiveLocationPool} locationPool | 102 * @param {!Bindings.LiveLocationPool} locationPool |
| 103 */ | 103 */ |
| 104 constructor(rawLocation, time, locationPool) { | 104 constructor(rawLocation, time, locationPool) { |
| 105 this._time = time; | 105 this._time = time; |
| 106 WebInspector.debuggerWorkspaceBinding.createLiveLocation(rawLocation, this.u
pdateLocation.bind(this), locationPool); | 106 Bindings.debuggerWorkspaceBinding.createLiveLocation(rawLocation, this.updat
eLocation.bind(this), locationPool); |
| 107 } | 107 } |
| 108 | 108 |
| 109 /** | 109 /** |
| 110 * @param {!WebInspector.LiveLocation} liveLocation | 110 * @param {!Bindings.LiveLocation} liveLocation |
| 111 */ | 111 */ |
| 112 updateLocation(liveLocation) { | 112 updateLocation(liveLocation) { |
| 113 if (this._uiLocation) | 113 if (this._uiLocation) |
| 114 this._uiLocation.uiSourceCode.removeLineDecoration( | 114 this._uiLocation.uiSourceCode.removeLineDecoration( |
| 115 this._uiLocation.lineNumber, WebInspector.LineLevelProfile.LineDecorat
or.type); | 115 this._uiLocation.lineNumber, Components.LineLevelProfile.LineDecorator
.type); |
| 116 this._uiLocation = liveLocation.uiLocation(); | 116 this._uiLocation = liveLocation.uiLocation(); |
| 117 if (this._uiLocation) | 117 if (this._uiLocation) |
| 118 this._uiLocation.uiSourceCode.addLineDecoration( | 118 this._uiLocation.uiSourceCode.addLineDecoration( |
| 119 this._uiLocation.lineNumber, WebInspector.LineLevelProfile.LineDecorat
or.type, this._time); | 119 this._uiLocation.lineNumber, Components.LineLevelProfile.LineDecorator
.type, this._time); |
| 120 } | 120 } |
| 121 }; | 121 }; |
| 122 | 122 |
| 123 /** | 123 /** |
| 124 * @implements {WebInspector.UISourceCodeFrame.LineDecorator} | 124 * @implements {Sources.UISourceCodeFrame.LineDecorator} |
| 125 * @unrestricted | 125 * @unrestricted |
| 126 */ | 126 */ |
| 127 WebInspector.LineLevelProfile.LineDecorator = class { | 127 Components.LineLevelProfile.LineDecorator = class { |
| 128 /** | 128 /** |
| 129 * @override | 129 * @override |
| 130 * @param {!WebInspector.UISourceCode} uiSourceCode | 130 * @param {!Workspace.UISourceCode} uiSourceCode |
| 131 * @param {!WebInspector.CodeMirrorTextEditor} textEditor | 131 * @param {!TextEditor.CodeMirrorTextEditor} textEditor |
| 132 */ | 132 */ |
| 133 decorate(uiSourceCode, textEditor) { | 133 decorate(uiSourceCode, textEditor) { |
| 134 var gutterType = 'CodeMirror-gutter-performance'; | 134 var gutterType = 'CodeMirror-gutter-performance'; |
| 135 var decorations = uiSourceCode.lineDecorations(WebInspector.LineLevelProfile
.LineDecorator.type); | 135 var decorations = uiSourceCode.lineDecorations(Components.LineLevelProfile.L
ineDecorator.type); |
| 136 textEditor.uninstallGutter(gutterType); | 136 textEditor.uninstallGutter(gutterType); |
| 137 if (!decorations) | 137 if (!decorations) |
| 138 return; | 138 return; |
| 139 textEditor.installGutter(gutterType, false); | 139 textEditor.installGutter(gutterType, false); |
| 140 for (var decoration of decorations.values()) { | 140 for (var decoration of decorations.values()) { |
| 141 var time = /** @type {number} */ (decoration.data()); | 141 var time = /** @type {number} */ (decoration.data()); |
| 142 var text = WebInspector.UIString('%.1f\xa0ms', time); | 142 var text = Common.UIString('%.1f\xa0ms', time); |
| 143 var intensity = Number.constrain(Math.log10(1 + 2 * time) / 5, 0.02, 1); | 143 var intensity = Number.constrain(Math.log10(1 + 2 * time) / 5, 0.02, 1); |
| 144 var element = createElementWithClass('div', 'text-editor-line-marker-perfo
rmance'); | 144 var element = createElementWithClass('div', 'text-editor-line-marker-perfo
rmance'); |
| 145 element.textContent = text; | 145 element.textContent = text; |
| 146 element.style.backgroundColor = `hsla(44, 100%, 50%, ${intensity.toFixed(3
)})`; | 146 element.style.backgroundColor = `hsla(44, 100%, 50%, ${intensity.toFixed(3
)})`; |
| 147 textEditor.setGutterDecoration(decoration.line(), gutterType, element); | 147 textEditor.setGutterDecoration(decoration.line(), gutterType, element); |
| 148 } | 148 } |
| 149 } | 149 } |
| 150 }; | 150 }; |
| 151 | 151 |
| 152 WebInspector.LineLevelProfile.LineDecorator.type = 'performance'; | 152 Components.LineLevelProfile.LineDecorator.type = 'performance'; |
| OLD | NEW |