Chromium Code Reviews| 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 WebInspector.LineMarkingProfile = class { |
|
caseq
2016/11/04 21:10:02
CoverageProfile?
| |
| 8 constructor() { | 8 constructor() { |
| 9 this._locationPool = new WebInspector.LiveLocationPool(); | 9 this._locationPool = new WebInspector.LiveLocationPool(); |
| 10 this.reset(); | 10 this.reset(); |
| 11 } | 11 } |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * @return {!WebInspector.LineLevelProfile} | 14 * @return {!WebInspector.LineMarkingProfile} |
| 15 */ | 15 */ |
| 16 static instance() { | 16 static instance() { |
| 17 if (!WebInspector.LineLevelProfile._instance) | 17 if (!WebInspector.LineMarkingProfile._instance) |
| 18 WebInspector.LineLevelProfile._instance = new WebInspector.LineLevelProfil e(); | 18 WebInspector.LineMarkingProfile._instance = new WebInspector.LineMarkingPr ofile(); |
| 19 return WebInspector.LineLevelProfile._instance; | 19 |
| 20 return WebInspector.LineMarkingProfile._instance; | |
| 20 } | 21 } |
| 21 | 22 |
| 22 /** | 23 /** |
| 23 * @param {!WebInspector.CPUProfileDataModel} profile | 24 * @param {string} url |
| 25 * @param {number} line | |
| 24 */ | 26 */ |
| 25 appendCPUProfile(profile) { | 27 appendUnusedRule(url, line) { |
| 26 var nodesToGo = [profile.profileHead]; | 28 if (!url) |
| 27 var sampleDuration = (profile.profileEndTime - profile.profileStartTime) / p rofile.totalHitCount; | 29 return; |
| 28 while (nodesToGo.length) { | 30 |
| 29 var nodes = nodesToGo.pop().children; | 31 var fileInfo = this._files.get(url); |
| 30 for (var i = 0; i < nodes.length; ++i) { | 32 if (!fileInfo) { |
| 31 var node = nodes[i]; | 33 fileInfo = new Set(); |
| 32 nodesToGo.push(node); | 34 this._files.set(url, fileInfo); |
| 33 if (!node.url || !node.positionTicks) | |
| 34 continue; | |
| 35 var fileInfo = this._files.get(node.url); | |
| 36 if (!fileInfo) { | |
| 37 fileInfo = new Map(); | |
| 38 this._files.set(node.url, fileInfo); | |
| 39 } | |
| 40 for (var j = 0; j < node.positionTicks.length; ++j) { | |
| 41 var lineInfo = node.positionTicks[j]; | |
| 42 var line = lineInfo.line; | |
| 43 var time = lineInfo.ticks * sampleDuration; | |
| 44 fileInfo.set(line, (fileInfo.get(line) || 0) + time); | |
| 45 } | |
| 46 } | |
| 47 } | 35 } |
| 36 | |
| 37 fileInfo.add(line); | |
| 38 | |
| 48 this._scheduleUpdate(); | 39 this._scheduleUpdate(); |
| 49 } | 40 } |
| 50 | 41 |
| 51 reset() { | 42 reset() { |
| 52 /** @type {!Map<string, !Map<number, number>>} */ | 43 /** @type {!Map<string, !Set<number>>} */ |
| 53 this._files = new Map(); | 44 this._files = new Map(); |
| 54 this._scheduleUpdate(); | 45 this._scheduleUpdate(); |
| 55 } | 46 } |
| 56 | 47 |
| 57 _scheduleUpdate() { | 48 _scheduleUpdate() { |
| 58 if (this._updateTimer) | 49 if (this._updateTimer) |
| 59 return; | 50 return; |
| 51 | |
| 60 this._updateTimer = setTimeout(() => { | 52 this._updateTimer = setTimeout(() => { |
| 61 this._updateTimer = null; | 53 this._updateTimer = null; |
| 62 this._doUpdate(); | 54 this._doUpdate(); |
| 63 }, 0); | 55 }, 0); |
| 64 } | 56 } |
| 65 | 57 |
| 66 _doUpdate() { | 58 _doUpdate() { |
| 67 // TODO(alph): use scriptId instead of urls for the target. | |
| 68 this._locationPool.disposeAll(); | 59 this._locationPool.disposeAll(); |
| 69 WebInspector.workspace.uiSourceCodes().forEach( | 60 WebInspector.workspace.uiSourceCodes().forEach( |
| 70 uiSourceCode => uiSourceCode.removeAllLineDecorations(WebInspector.LineL evelProfile.LineDecorator.type)); | 61 uiSourceCode => uiSourceCode.removeAllLineDecorations(WebInspector.LineM arkingProfile.LineDecorator.type)); |
| 62 | |
| 71 for (var fileInfo of this._files) { | 63 for (var fileInfo of this._files) { |
| 72 var url = /** @type {string} */ (fileInfo[0]); | 64 var url = /** @type {string} */ (fileInfo[0]); |
| 73 var uiSourceCode = WebInspector.workspace.uiSourceCodeForURL(url); | 65 var uiSourceCode = WebInspector.workspace.uiSourceCodeForURL(url); |
| 74 if (!uiSourceCode) | 66 if (!uiSourceCode) |
| 75 continue; | 67 continue; |
| 68 | |
| 76 var target = | 69 var target = |
| 77 WebInspector.NetworkProject.targetForUISourceCode(uiSourceCode) || Web Inspector.targetManager.mainTarget(); | 70 WebInspector.NetworkProject.targetForUISourceCode(uiSourceCode) || Web Inspector.targetManager.mainTarget(); |
| 78 var debuggerModel = target ? WebInspector.DebuggerModel.fromTarget(target) : null; | 71 var debuggerModel = target ? WebInspector.DebuggerModel.fromTarget(target) : null; |
| 79 if (!debuggerModel) | 72 if (!debuggerModel) |
| 80 continue; | 73 continue; |
| 74 | |
| 81 for (var lineInfo of fileInfo[1]) { | 75 for (var lineInfo of fileInfo[1]) { |
| 82 var line = lineInfo[0] - 1; | 76 var line = lineInfo; |
| 83 var time = lineInfo[1]; | 77 |
| 84 var rawLocation = debuggerModel.createRawLocationByURL(url, line, 0); | 78 var rawLocation = debuggerModel.createRawLocationByURL(url, line, 0); |
| 85 if (rawLocation) | 79 if (rawLocation) |
| 86 new WebInspector.LineLevelProfile.Presentation(rawLocation, time, this ._locationPool); | 80 new WebInspector.LineMarkingProfile.Presentation(rawLocation, this._lo cationPool); |
| 87 else if (uiSourceCode) | 81 else if (uiSourceCode) |
| 88 uiSourceCode.addLineDecoration(line, WebInspector.LineLevelProfile.Lin eDecorator.type, time); | 82 uiSourceCode.addLineDecoration(line, WebInspector.LineMarkingProfile.L ineDecorator.type, 0); |
| 89 } | 83 } |
| 90 } | 84 } |
| 91 } | 85 } |
| 92 }; | 86 }; |
| 93 | 87 |
| 94 | 88 |
| 95 /** | 89 /** |
| 96 * @unrestricted | 90 * @unrestricted |
| 97 */ | 91 */ |
| 98 WebInspector.LineLevelProfile.Presentation = class { | 92 WebInspector.LineMarkingProfile.Presentation = class { |
| 99 /** | 93 /** |
| 100 * @param {!WebInspector.DebuggerModel.Location} rawLocation | 94 * @param {!WebInspector.DebuggerModel.Location} rawLocation |
| 101 * @param {number} time | |
| 102 * @param {!WebInspector.LiveLocationPool} locationPool | 95 * @param {!WebInspector.LiveLocationPool} locationPool |
| 103 */ | 96 */ |
| 104 constructor(rawLocation, time, locationPool) { | 97 constructor(rawLocation, locationPool) { |
| 105 this._time = time; | |
| 106 WebInspector.debuggerWorkspaceBinding.createLiveLocation(rawLocation, this.u pdateLocation.bind(this), locationPool); | 98 WebInspector.debuggerWorkspaceBinding.createLiveLocation(rawLocation, this.u pdateLocation.bind(this), locationPool); |
| 107 } | 99 } |
| 108 | 100 |
| 109 /** | 101 /** |
| 110 * @param {!WebInspector.LiveLocation} liveLocation | 102 * @param {!WebInspector.LiveLocation} liveLocation |
| 111 */ | 103 */ |
| 112 updateLocation(liveLocation) { | 104 updateLocation(liveLocation) { |
| 113 if (this._uiLocation) | 105 if (this._uiLocation) |
| 114 this._uiLocation.uiSourceCode.removeLineDecoration( | 106 this._uiLocation.uiSourceCode.removeLineDecoration( |
| 115 this._uiLocation.lineNumber, WebInspector.LineLevelProfile.LineDecorat or.type); | 107 this._uiLocation.lineNumber, WebInspector.LineMarkingProfile.LineDecor ator.type); |
| 108 | |
| 116 this._uiLocation = liveLocation.uiLocation(); | 109 this._uiLocation = liveLocation.uiLocation(); |
| 117 if (this._uiLocation) | 110 if (this._uiLocation) |
| 118 this._uiLocation.uiSourceCode.addLineDecoration( | 111 this._uiLocation.uiSourceCode.addLineDecoration( |
| 119 this._uiLocation.lineNumber, WebInspector.LineLevelProfile.LineDecorat or.type, this._time); | 112 this._uiLocation.lineNumber, WebInspector.LineMarkingProfile.LineDecor ator.type, 0); |
| 120 } | 113 } |
| 121 }; | 114 }; |
| 122 | 115 |
| 123 /** | 116 /** |
| 124 * @implements {WebInspector.UISourceCodeFrame.LineDecorator} | 117 * @implements {WebInspector.UISourceCodeFrame.LineDecorator} |
| 125 * @unrestricted | 118 * @unrestricted |
| 126 */ | 119 */ |
| 127 WebInspector.LineLevelProfile.LineDecorator = class { | 120 WebInspector.LineMarkingProfile.LineDecorator = class { |
| 128 /** | 121 /** |
| 129 * @override | 122 * @override |
| 130 * @param {!WebInspector.UISourceCode} uiSourceCode | 123 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 131 * @param {!WebInspector.CodeMirrorTextEditor} textEditor | 124 * @param {!WebInspector.CodeMirrorTextEditor} textEditor |
| 132 */ | 125 */ |
| 133 decorate(uiSourceCode, textEditor) { | 126 decorate(uiSourceCode, textEditor) { |
| 134 var gutterType = 'CodeMirror-gutter-performance'; | 127 var gutterType = 'CodeMirror-gutter-cssTracking'; |
| 135 var decorations = uiSourceCode.lineDecorations(WebInspector.LineLevelProfile .LineDecorator.type); | 128 |
| 129 var decorations = uiSourceCode.lineDecorations(WebInspector.LineMarkingProfi le.LineDecorator.type); | |
| 136 textEditor.uninstallGutter(gutterType); | 130 textEditor.uninstallGutter(gutterType); |
| 137 if (!decorations) | 131 if (!decorations) |
| 138 return; | 132 return; |
| 133 | |
| 139 textEditor.installGutter(gutterType, false); | 134 textEditor.installGutter(gutterType, false); |
| 135 | |
| 140 for (var decoration of decorations.values()) { | 136 for (var decoration of decorations.values()) { |
| 141 var time = /** @type {number} */ (decoration.data()); | 137 var element = createElementWithClass('div', 'text-editor-line-marker-cssTr acking'); |
| 142 var text = WebInspector.UIString('%.1f\xa0ms', time); | 138 element.style.backgroundColor = 'red'; |
| 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'); | |
| 145 element.textContent = text; | |
| 146 element.style.backgroundColor = `hsla(44, 100%, 50%, ${intensity.toFixed(3 )})`; | |
| 147 textEditor.setGutterDecoration(decoration.line(), gutterType, element); | 139 textEditor.setGutterDecoration(decoration.line(), gutterType, element); |
| 148 } | 140 } |
| 149 } | 141 } |
| 150 }; | 142 }; |
| 151 | 143 |
| 152 WebInspector.LineLevelProfile.LineDecorator.type = 'performance'; | 144 WebInspector.LineMarkingProfile.LineDecorator.type = 'cssTracking'; |
| OLD | NEW |