Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(363)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/perf_ui/LineLevelProfile.js

Issue 2608043002: DevTools: extract modules (with extensions) (Closed)
Patch Set: fix externs (PerfUI) Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 Components.LineLevelProfile = class { 7 PerfUI.LineLevelProfile = class {
8 constructor() { 8 constructor() {
9 this._locationPool = new Bindings.LiveLocationPool(); 9 this._locationPool = new Bindings.LiveLocationPool();
10 this.reset(); 10 this.reset();
11 } 11 }
12 12
13 /** 13 /**
14 * @return {!Components.LineLevelProfile} 14 * @return {!PerfUI.LineLevelProfile}
15 */ 15 */
16 static instance() { 16 static instance() {
17 if (!Components.LineLevelProfile._instance) 17 if (!PerfUI.LineLevelProfile._instance)
18 Components.LineLevelProfile._instance = new Components.LineLevelProfile(); 18 PerfUI.LineLevelProfile._instance = new PerfUI.LineLevelProfile();
19 return Components.LineLevelProfile._instance; 19 return PerfUI.LineLevelProfile._instance;
20 } 20 }
21 21
22 /** 22 /**
23 * @param {!SDK.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;
(...skipping 30 matching lines...) Expand all
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 Workspace.workspace.uiSourceCodes().forEach( 69 Workspace.workspace.uiSourceCodes().forEach(
70 uiSourceCode => uiSourceCode.removeDecorationsForType(Components.LineLev elProfile.LineDecorator.type)); 70 uiSourceCode => uiSourceCode.removeDecorationsForType(PerfUI.LineLevelPr ofile.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 = Workspace.workspace.uiSourceCodeForURL(url); 73 var uiSourceCode = Workspace.workspace.uiSourceCodeForURL(url);
74 if (!uiSourceCode) 74 if (!uiSourceCode)
75 continue; 75 continue;
76 var target = Bindings.NetworkProject.targetForUISourceCode(uiSourceCode) | | SDK.targetManager.mainTarget(); 76 var target = Bindings.NetworkProject.targetForUISourceCode(uiSourceCode) | | SDK.targetManager.mainTarget();
77 var debuggerModel = target ? SDK.DebuggerModel.fromTarget(target) : null; 77 var debuggerModel = target ? SDK.DebuggerModel.fromTarget(target) : null;
78 if (!debuggerModel) 78 if (!debuggerModel)
79 continue; 79 continue;
80 for (var lineInfo of fileInfo[1]) { 80 for (var lineInfo of fileInfo[1]) {
81 var line = lineInfo[0] - 1; 81 var line = lineInfo[0] - 1;
82 var time = lineInfo[1]; 82 var time = lineInfo[1];
83 var rawLocation = debuggerModel.createRawLocationByURL(url, line, 0); 83 var rawLocation = debuggerModel.createRawLocationByURL(url, line, 0);
84 if (rawLocation) 84 if (rawLocation)
85 new Components.LineLevelProfile.Presentation(rawLocation, time, this._ locationPool); 85 new PerfUI.LineLevelProfile.Presentation(rawLocation, time, this._loca tionPool);
86 else if (uiSourceCode) 86 else if (uiSourceCode)
87 uiSourceCode.addLineDecoration(line, Components.LineLevelProfile.LineD ecorator.type, time); 87 uiSourceCode.addLineDecoration(line, PerfUI.LineLevelProfile.LineDecor ator.type, time);
88 } 88 }
89 } 89 }
90 } 90 }
91 }; 91 };
92 92
93 93
94 /** 94 /**
95 * @unrestricted 95 * @unrestricted
96 */ 96 */
97 Components.LineLevelProfile.Presentation = class { 97 PerfUI.LineLevelProfile.Presentation = class {
98 /** 98 /**
99 * @param {!SDK.DebuggerModel.Location} rawLocation 99 * @param {!SDK.DebuggerModel.Location} rawLocation
100 * @param {number} time 100 * @param {number} time
101 * @param {!Bindings.LiveLocationPool} locationPool 101 * @param {!Bindings.LiveLocationPool} locationPool
102 */ 102 */
103 constructor(rawLocation, time, locationPool) { 103 constructor(rawLocation, time, locationPool) {
104 this._time = time; 104 this._time = time;
105 Bindings.debuggerWorkspaceBinding.createLiveLocation(rawLocation, this.updat eLocation.bind(this), locationPool); 105 Bindings.debuggerWorkspaceBinding.createLiveLocation(rawLocation, this.updat eLocation.bind(this), locationPool);
106 } 106 }
107 107
108 /** 108 /**
109 * @param {!Bindings.LiveLocation} liveLocation 109 * @param {!Bindings.LiveLocation} liveLocation
110 */ 110 */
111 updateLocation(liveLocation) { 111 updateLocation(liveLocation) {
112 if (this._uiLocation) 112 if (this._uiLocation)
113 this._uiLocation.uiSourceCode.removeDecorationsForType(Components.LineLeve lProfile.LineDecorator.type); 113 this._uiLocation.uiSourceCode.removeDecorationsForType(PerfUI.LineLevelPro file.LineDecorator.type);
114 this._uiLocation = liveLocation.uiLocation(); 114 this._uiLocation = liveLocation.uiLocation();
115 if (this._uiLocation) { 115 if (this._uiLocation) {
116 this._uiLocation.uiSourceCode.addLineDecoration( 116 this._uiLocation.uiSourceCode.addLineDecoration(
117 this._uiLocation.lineNumber, Components.LineLevelProfile.LineDecorator .type, this._time); 117 this._uiLocation.lineNumber, PerfUI.LineLevelProfile.LineDecorator.typ e, this._time);
118 } 118 }
119 } 119 }
120 }; 120 };
121 121
122 /** 122 /**
123 * @implements {Sources.UISourceCodeFrame.LineDecorator} 123 * @implements {SourceFrame.UISourceCodeFrame.LineDecorator}
124 * @unrestricted 124 * @unrestricted
125 */ 125 */
126 Components.LineLevelProfile.LineDecorator = class { 126 PerfUI.LineLevelProfile.LineDecorator = class {
127 /** 127 /**
128 * @override 128 * @override
129 * @param {!Workspace.UISourceCode} uiSourceCode 129 * @param {!Workspace.UISourceCode} uiSourceCode
130 * @param {!TextEditor.CodeMirrorTextEditor} textEditor 130 * @param {!TextEditor.CodeMirrorTextEditor} textEditor
131 */ 131 */
132 decorate(uiSourceCode, textEditor) { 132 decorate(uiSourceCode, textEditor) {
133 var gutterType = 'CodeMirror-gutter-performance'; 133 var gutterType = 'CodeMirror-gutter-performance';
134 var decorations = uiSourceCode.decorationsForType(Components.LineLevelProfil e.LineDecorator.type); 134 var decorations = uiSourceCode.decorationsForType(PerfUI.LineLevelProfile.Li neDecorator.type);
135 textEditor.uninstallGutter(gutterType); 135 textEditor.uninstallGutter(gutterType);
136 if (!decorations || !decorations.size) 136 if (!decorations || !decorations.size)
137 return; 137 return;
138 textEditor.installGutter(gutterType, false); 138 textEditor.installGutter(gutterType, false);
139 for (var decoration of decorations) { 139 for (var decoration of decorations) {
140 var time = /** @type {number} */ (decoration.data()); 140 var time = /** @type {number} */ (decoration.data());
141 var text = Common.UIString('%.1f\xa0ms', time); 141 var text = Common.UIString('%.1f\xa0ms', time);
142 var intensity = Number.constrain(Math.log10(1 + 2 * time) / 5, 0.02, 1); 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'); 143 var element = createElementWithClass('div', 'text-editor-line-marker-perfo rmance');
144 element.textContent = text; 144 element.textContent = text;
145 element.style.backgroundColor = `hsla(44, 100%, 50%, ${intensity.toFixed(3 )})`; 145 element.style.backgroundColor = `hsla(44, 100%, 50%, ${intensity.toFixed(3 )})`;
146 textEditor.setGutterDecoration(decoration.range().startLine, gutterType, e lement); 146 textEditor.setGutterDecoration(decoration.range().startLine, gutterType, e lement);
147 } 147 }
148 } 148 }
149 }; 149 };
150 150
151 Components.LineLevelProfile.LineDecorator.type = 'performance'; 151 PerfUI.LineLevelProfile.LineDecorator.type = 'performance';
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698