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