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 /** |
|
alph
2016/11/08 17:10:25
empty line plz
| |
| 5 * @unrestricted | 5 * @unrestricted |
|
alph
2016/11/08 17:10:25
Can you plz remove this.
| |
| 6 */ | 6 */ |
| 7 WebInspector.LineLevelProfile = class { | 7 WebInspector.CoverageProfile = class { |
| 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.CoverageProfile} |
| 15 */ | 15 */ |
| 16 static instance() { | 16 static instance() { |
| 17 if (!WebInspector.LineLevelProfile._instance) | 17 if (!WebInspector.CoverageProfile._instance) |
| 18 WebInspector.LineLevelProfile._instance = new WebInspector.LineLevelProfil e(); | 18 WebInspector.CoverageProfile._instance = new WebInspector.CoverageProfile( ); |
| 19 return WebInspector.LineLevelProfile._instance; | 19 |
| 20 return WebInspector.CoverageProfile._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 | |
|
alph
2016/11/08 17:10:25
nit: here and below no need for empty lines
| |
| 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 |
| 58 _uiSourceCodeChanged(event) { | |
|
alph
2016/11/08 17:10:24
annotate
| |
| 59 WebInspector.workspace.uiSourceCodes().forEach( | |
| 60 uiSourceCode => uiSourceCode.removeAllLineDecorations(WebInspector.Cover ageProfile.LineDecorator.type)); | |
| 61 } | |
| 62 | |
| 66 _doUpdate() { | 63 _doUpdate() { |
| 67 // TODO(alph): use scriptId instead of urls for the target. | |
| 68 this._locationPool.disposeAll(); | 64 this._locationPool.disposeAll(); |
| 69 WebInspector.workspace.uiSourceCodes().forEach( | 65 WebInspector.workspace.uiSourceCodes().forEach( |
| 70 uiSourceCode => uiSourceCode.removeAllLineDecorations(WebInspector.LineL evelProfile.LineDecorator.type)); | 66 uiSourceCode => uiSourceCode.removeAllLineDecorations(WebInspector.Cover ageProfile.LineDecorator.type)); |
| 67 | |
| 68 WebInspector.workspace.uiSourceCodes().forEach( | |
| 69 uiSourceCode => uiSourceCode.addEventListener( | |
| 70 WebInspector.UISourceCode.Events.WorkingCopyChanged, this._uiSourceCodeChanged, this)); | |
| 71 | |
| 71 for (var fileInfo of this._files) { | 72 for (var fileInfo of this._files) { |
| 72 var url = /** @type {string} */ (fileInfo[0]); | 73 var url = /** @type {string} */ (fileInfo[0]); |
| 73 var uiSourceCode = WebInspector.workspace.uiSourceCodeForURL(url); | 74 var uiSourceCode = WebInspector.workspace.uiSourceCodeForURL(url); |
| 74 if (!uiSourceCode) | 75 if (!uiSourceCode) |
| 75 continue; | 76 continue; |
| 77 | |
| 76 var target = | 78 var target = |
| 77 WebInspector.NetworkProject.targetForUISourceCode(uiSourceCode) || Web Inspector.targetManager.mainTarget(); | 79 WebInspector.NetworkProject.targetForUISourceCode(uiSourceCode) || Web Inspector.targetManager.mainTarget(); |
| 78 var debuggerModel = target ? WebInspector.DebuggerModel.fromTarget(target) : null; | 80 var debuggerModel = target ? WebInspector.DebuggerModel.fromTarget(target) : null; |
| 79 if (!debuggerModel) | 81 if (!debuggerModel) |
| 80 continue; | 82 continue; |
| 83 | |
| 81 for (var lineInfo of fileInfo[1]) { | 84 for (var lineInfo of fileInfo[1]) { |
|
alph
2016/11/08 17:10:24
... var line of ...
| |
| 82 var line = lineInfo[0] - 1; | 85 var line = lineInfo; |
| 83 var time = lineInfo[1]; | 86 |
| 84 var rawLocation = debuggerModel.createRawLocationByURL(url, line, 0); | 87 var rawLocation = debuggerModel.createRawLocationByURL(url, line, 0); |
| 85 if (rawLocation) | 88 if (rawLocation) |
| 86 new WebInspector.LineLevelProfile.Presentation(rawLocation, time, this ._locationPool); | 89 new WebInspector.CoverageProfile.Presentation(rawLocation, this._locat ionPool); |
| 87 else if (uiSourceCode) | 90 else if (uiSourceCode) |
| 88 uiSourceCode.addLineDecoration(line, WebInspector.LineLevelProfile.Lin eDecorator.type, time); | 91 uiSourceCode.addLineDecoration(line, WebInspector.CoverageProfile.Line Decorator.type, 0); |
| 89 } | 92 } |
| 90 } | 93 } |
| 91 } | 94 } |
| 92 }; | 95 }; |
| 93 | 96 |
| 94 | 97 |
| 95 /** | 98 /** |
| 96 * @unrestricted | 99 * @unrestricted |
|
alph
2016/11/08 17:10:24
drop it
| |
| 97 */ | 100 */ |
| 98 WebInspector.LineLevelProfile.Presentation = class { | 101 WebInspector.CoverageProfile.Presentation = class { |
| 99 /** | 102 /** |
| 100 * @param {!WebInspector.DebuggerModel.Location} rawLocation | 103 * @param {!WebInspector.DebuggerModel.Location} rawLocation |
| 101 * @param {number} time | |
| 102 * @param {!WebInspector.LiveLocationPool} locationPool | 104 * @param {!WebInspector.LiveLocationPool} locationPool |
| 103 */ | 105 */ |
| 104 constructor(rawLocation, time, locationPool) { | 106 constructor(rawLocation, locationPool) { |
| 105 this._time = time; | |
| 106 WebInspector.debuggerWorkspaceBinding.createLiveLocation(rawLocation, this.u pdateLocation.bind(this), locationPool); | 107 WebInspector.debuggerWorkspaceBinding.createLiveLocation(rawLocation, this.u pdateLocation.bind(this), locationPool); |
| 107 } | 108 } |
| 108 | 109 |
| 109 /** | 110 /** |
| 110 * @param {!WebInspector.LiveLocation} liveLocation | 111 * @param {!WebInspector.LiveLocation} liveLocation |
| 111 */ | 112 */ |
| 112 updateLocation(liveLocation) { | 113 updateLocation(liveLocation) { |
| 113 if (this._uiLocation) | 114 if (this._uiLocation) |
| 114 this._uiLocation.uiSourceCode.removeLineDecoration( | 115 this._uiLocation.uiSourceCode.removeLineDecoration( |
| 115 this._uiLocation.lineNumber, WebInspector.LineLevelProfile.LineDecorat or.type); | 116 this._uiLocation.lineNumber, WebInspector.CoverageProfile.LineDecorato r.type); |
| 117 | |
| 116 this._uiLocation = liveLocation.uiLocation(); | 118 this._uiLocation = liveLocation.uiLocation(); |
| 117 if (this._uiLocation) | 119 if (this._uiLocation) |
| 118 this._uiLocation.uiSourceCode.addLineDecoration( | 120 this._uiLocation.uiSourceCode.addLineDecoration( |
| 119 this._uiLocation.lineNumber, WebInspector.LineLevelProfile.LineDecorat or.type, this._time); | 121 this._uiLocation.lineNumber, WebInspector.CoverageProfile.LineDecorato r.type, 0); |
| 120 } | 122 } |
| 121 }; | 123 }; |
| 122 | 124 |
| 123 /** | 125 /** |
| 124 * @implements {WebInspector.UISourceCodeFrame.LineDecorator} | 126 * @implements {WebInspector.UISourceCodeFrame.LineDecorator} |
| 125 * @unrestricted | 127 * @unrestricted |
|
alph
2016/11/08 17:10:25
drop the line
| |
| 126 */ | 128 */ |
| 127 WebInspector.LineLevelProfile.LineDecorator = class { | 129 WebInspector.CoverageProfile.LineDecorator = class { |
| 128 /** | 130 /** |
| 129 * @override | 131 * @override |
| 130 * @param {!WebInspector.UISourceCode} uiSourceCode | 132 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 131 * @param {!WebInspector.CodeMirrorTextEditor} textEditor | 133 * @param {!WebInspector.CodeMirrorTextEditor} textEditor |
| 132 */ | 134 */ |
| 133 decorate(uiSourceCode, textEditor) { | 135 decorate(uiSourceCode, textEditor) { |
| 134 var gutterType = 'CodeMirror-gutter-performance'; | 136 var gutterType = 'gutter-cssTracking'; |
| 135 var decorations = uiSourceCode.lineDecorations(WebInspector.LineLevelProfile .LineDecorator.type); | 137 |
| 138 var decorations = uiSourceCode.lineDecorations(WebInspector.CoverageProfile. LineDecorator.type); | |
| 136 textEditor.uninstallGutter(gutterType); | 139 textEditor.uninstallGutter(gutterType); |
| 137 if (!decorations) | 140 if (!decorations) |
| 138 return; | 141 return; |
| 142 | |
| 139 textEditor.installGutter(gutterType, false); | 143 textEditor.installGutter(gutterType, false); |
| 144 | |
| 140 for (var decoration of decorations.values()) { | 145 for (var decoration of decorations.values()) { |
| 141 var time = /** @type {number} */ (decoration.data()); | 146 var element = createElementWithClass('div', 'text-editor-line-marker-cssTr acking'); |
|
alph
2016/11/08 17:10:25
can we have a file type neutral name. We are going
| |
| 142 var text = WebInspector.UIString('%.1f\xa0ms', time); | 147 element.style.backgroundColor = 'red'; |
|
alph
2016/11/08 17:10:25
As long as the color is static, you can encode it
| |
| 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); | 148 textEditor.setGutterDecoration(decoration.line(), gutterType, element); |
| 148 } | 149 } |
| 149 } | 150 } |
| 150 }; | 151 }; |
| 151 | 152 |
| 152 WebInspector.LineLevelProfile.LineDecorator.type = 'performance'; | 153 WebInspector.CoverageProfile.LineDecorator.type = 'cssTracking'; |
| OLD | NEW |