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

Side by Side Diff: Source/devtools/front_end/network/NetworkOverview.js

Issue 1178563002: DevTools: Refactor network panel overview (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: update test. Created 5 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 /** 5 /**
6 * @constructor 6 * @constructor
7 * @extends {WebInspector.VBox} 7 * @extends {WebInspector.TimelineOverviewBase}
8 */ 8 */
9 WebInspector.NetworkOverview = function() 9 WebInspector.NetworkOverview = function()
10 { 10 {
11 WebInspector.VBox.call(this); 11 WebInspector.TimelineOverviewBase.call(this);
12 this.element.classList.add("network-overview"); 12 this.element.classList.add("network-overview");
13 13
14 /** @type {!WebInspector.OverviewGrid} */
15 this._overviewGrid = new WebInspector.OverviewGrid("network");
16 /** @type {!Element} */
17 this._overviewContainer = this._overviewGrid.element.createChild("div", "net work-overview-canvas-container");
18 this._overviewCanvas = this._overviewContainer.createChild("canvas", "networ k-overview-canvas");
19 /** @type {!WebInspector.NetworkTransferTimeCalculator} */
20 this._calculator = new WebInspector.NetworkTransferTimeCalculator();
21 /** @type {number} */ 14 /** @type {number} */
22 this._numBands = 1; 15 this._numBands = 1;
23 /** @type {number} */ 16 /** @type {number} */
24 this._windowStart = 0; 17 this._windowStart = 0;
25 /** @type {number} */ 18 /** @type {number} */
26 this._windowEnd = 0; 19 this._windowEnd = 0;
27 /** @type {boolean} */ 20 /** @type {boolean} */
28 this._restoringWindow = false; 21 this._restoringWindow = false;
29 /** @type {boolean} */ 22 /** @type {boolean} */
30 this._updateScheduled = false; 23 this._updateScheduled = false;
31 /** @type {number} */ 24 /** @type {number} */
32 this._canvasWidth = 0; 25 this._canvasWidth = 0;
33 /** @type {number} */ 26 /** @type {number} */
34 this._canvasHeight = 0; 27 this._canvasHeight = 0;
35 28
36 this._overviewGrid.addEventListener(WebInspector.OverviewGrid.Events.WindowC hanged, this._onWindowChanged, this);
37 this.element.appendChild(this._overviewGrid.element);
38 WebInspector.targetManager.addModelListener(WebInspector.ResourceTreeModel, WebInspector.ResourceTreeModel.EventTypes.Load, this._loadEventFired, this); 29 WebInspector.targetManager.addModelListener(WebInspector.ResourceTreeModel, WebInspector.ResourceTreeModel.EventTypes.Load, this._loadEventFired, this);
39 WebInspector.targetManager.addModelListener(WebInspector.ResourceTreeModel, WebInspector.ResourceTreeModel.EventTypes.DOMContentLoaded, this._domContentLoad edEventFired, this); 30 WebInspector.targetManager.addModelListener(WebInspector.ResourceTreeModel, WebInspector.ResourceTreeModel.EventTypes.DOMContentLoaded, this._domContentLoad edEventFired, this);
40 31
41 this.reset(); 32 this.reset();
42 } 33 }
43 34
44 /** @type {number} */ 35 /** @type {number} */
45 WebInspector.NetworkOverview._bandHeight = 3; 36 WebInspector.NetworkOverview._bandHeight = 3;
46 37
47 /** @type {number} */ 38 /** @type {number} */
48 WebInspector.NetworkOverview._dividersBarHeight = 20; 39 WebInspector.NetworkOverview._dividersBarHeight = 20;
49 40
50 /** @enum {string} */
51 WebInspector.NetworkOverview.Events = {
52 WindowChanged: "WindowChanged"
53 }
54
55 /** @typedef {{start: number, end: number}} */ 41 /** @typedef {{start: number, end: number}} */
56 WebInspector.NetworkOverview.Window; 42 WebInspector.NetworkOverview.Window;
57 43
58 WebInspector.NetworkOverview.prototype = { 44 WebInspector.NetworkOverview.prototype = {
59 /** 45 /**
60 * @param {number} windowStart
61 * @param {number} windowEnd
62 */
63 setWindow: function(windowStart, windowEnd)
64 {
65 var startTime = this._calculator.minimumBoundary();
66 var totalTime = this._calculator.boundarySpan();
67 this._overviewGrid.setWindow(Math.max(windowStart - startTime, 0) / tota lTime, (windowEnd - startTime) / totalTime);
68 },
69
70 /**
71 * @param {?WebInspector.FilmStripModel} filmStripModel 46 * @param {?WebInspector.FilmStripModel} filmStripModel
72 */ 47 */
73 setFilmStripModel: function(filmStripModel) 48 setFilmStripModel: function(filmStripModel)
74 { 49 {
75 this._filmStripModel = filmStripModel; 50 this._filmStripModel = filmStripModel;
76 this.scheduleUpdate(); 51 this.scheduleUpdate();
77 }, 52 },
78 53
79 /** 54 /**
80 * @param {number} time 55 * @param {number} time
81 */ 56 */
82 selectFilmStripFrame: function(time) 57 selectFilmStripFrame: function(time)
83 { 58 {
84 this._selectedFilmStripTime = time; 59 this._selectedFilmStripTime = time;
85 this.scheduleUpdate(); 60 this.scheduleUpdate();
86 }, 61 },
87 62
88 clearFilmStripFrame: function() 63 clearFilmStripFrame: function()
89 { 64 {
90 this._selectedFilmStripTime = -1; 65 this._selectedFilmStripTime = -1;
91 this.scheduleUpdate(); 66 this.scheduleUpdate();
92 }, 67 },
93 68
94 /** 69 /**
95 * @param {!WebInspector.Event} event 70 * @param {!WebInspector.Event} event
96 */ 71 */
97 _onWindowChanged: function(event)
98 {
99 if (this._restoringWindow)
100 return;
101 var startTime = this._calculator.minimumBoundary();
102 var totalTime = this._calculator.boundarySpan();
103 var left = this._overviewGrid.windowLeft();
104 var right = this._overviewGrid.windowRight();
105 if (left === 0 && right === 1) {
106 this._windowStart = 0;
107 this._windowEnd = 0;
108 } else {
109 this._windowStart = startTime + left * totalTime;
110 this._windowEnd = startTime + right * totalTime;
111 }
112 this.dispatchEventToListeners(WebInspector.NetworkOverview.Events.Window Changed, {start: this._windowStart, end: this._windowEnd});
113 },
114
115 /**
116 * @param {!WebInspector.Event} event
117 */
118 _loadEventFired: function(event) 72 _loadEventFired: function(event)
119 { 73 {
120 var data = /** @type {number} */ (event.data); 74 var data = /** @type {number} */ (event.data);
121 if (data) 75 if (data)
122 this._loadEvents.push(data); 76 this._loadEvents.push(data);
123 this.scheduleUpdate(); 77 this.scheduleUpdate();
124 }, 78 },
125 79
126 /** 80 /**
127 * @param {!WebInspector.Event} event 81 * @param {!WebInspector.Event} event
(...skipping 19 matching lines...) Expand all
147 var result = this._nextBand++; 101 var result = this._nextBand++;
148 this._bandMap.set(connectionId, result); 102 this._bandMap.set(connectionId, result);
149 return result; 103 return result;
150 }, 104 },
151 105
152 /** 106 /**
153 * @param {!WebInspector.NetworkRequest} request 107 * @param {!WebInspector.NetworkRequest} request
154 */ 108 */
155 updateRequest: function(request) 109 updateRequest: function(request)
156 { 110 {
157 if (!this._requestsList.length) {
158 // When events start coming in, we need to reset user-friendly 0 - 1 000ms calculator.
159 this._calculator.reset();
160 this.onResize();
161 }
162 this._calculator.updateBoundaries(request);
163 if (!this._requestsSet.has(request)) { 111 if (!this._requestsSet.has(request)) {
164 this._requestsSet.add(request); 112 this._requestsSet.add(request);
165 this._requestsList.push(request); 113 this._requestsList.push(request);
166 } 114 }
167 this.scheduleUpdate(); 115 this.scheduleUpdate();
168 }, 116 },
169 117
170 /** 118 /**
171 * @override 119 * @override
172 */ 120 */
173 wasShown: function() 121 wasShown: function()
174 { 122 {
175 this.onResize(); 123 this.onResize();
176 }, 124 },
177 125
178 /** 126 /**
179 * @override 127 * @override
180 */ 128 */
181 onResize: function() 129 onResize: function()
182 { 130 {
183 var width = this._overviewContainer.offsetWidth; 131 var width = this.element.offsetWidth;
184 var height = this._overviewContainer.offsetHeight; 132 var height = this.element.offsetHeight;
185 this._calculator.setDisplayWindow(width); 133 this._calculator.setDisplayWindow(width);
186 this._resetCanvas(width, height); 134 this.resetCanvas();
187 var numBands = (((height - WebInspector.NetworkOverview._dividersBarHeig ht - 1) / WebInspector.NetworkOverview._bandHeight) - 1) | 0; 135 var numBands = (((height - 1) / WebInspector.NetworkOverview._bandHeight ) - 1) | 0;
188 this._numBands = (numBands > 0) ? numBands : 1; 136 this._numBands = (numBands > 0) ? numBands : 1;
189 this.scheduleUpdate(); 137 this.scheduleUpdate();
190 }, 138 },
191 139
140 /**
141 * @override
142 */
192 reset: function() 143 reset: function()
193 { 144 {
194 this._calculator.reset();
195 this._calculator.setInitialUserFriendlyBoundaries();
196 this._overviewGrid.reset();
197 this._windowStart = 0; 145 this._windowStart = 0;
198 this._windowEnd = 0; 146 this._windowEnd = 0;
199 /** @type {?WebInspector.FilmStripModel} */ 147 /** @type {?WebInspector.FilmStripModel} */
200 this._filmStripModel = null; 148 this._filmStripModel = null;
201 149
202 /** @type {number} */ 150 /** @type {number} */
203 this._span = 1; 151 this._span = 1;
204 /** @type {!WebInspector.NetworkTimeBoundary} */ 152 /** @type {?WebInspector.NetworkTimeBoundary} */
205 this._lastBoundary = this._calculator.boundary(); 153 this._lastBoundary = null;
206 /** @type {number} */ 154 /** @type {number} */
207 this._nextBand = 0; 155 this._nextBand = 0;
208 /** @type {!Map.<string, number>} */ 156 /** @type {!Map.<string, number>} */
209 this._bandMap = new Map(); 157 this._bandMap = new Map();
210 /** @type {!Array.<!WebInspector.NetworkRequest>} */ 158 /** @type {!Array.<!WebInspector.NetworkRequest>} */
211 this._requestsList = []; 159 this._requestsList = [];
212 /** @type {!Set.<!WebInspector.NetworkRequest>} */ 160 /** @type {!Set.<!WebInspector.NetworkRequest>} */
213 this._requestsSet = new Set(); 161 this._requestsSet = new Set();
214 /** @type {!Array.<number>} */ 162 /** @type {!Array.<number>} */
215 this._loadEvents = []; 163 this._loadEvents = [];
216 /** @type {!Array.<number>} */ 164 /** @type {!Array.<number>} */
217 this._domContentLoadedEvents = []; 165 this._domContentLoadedEvents = [];
218 166
219 // Clear screen. 167 // Clear screen.
220 var width = this._overviewContainer.offsetWidth; 168 this.resetCanvas();
221 var height = this._overviewContainer.offsetHeight;
222 this._resetCanvas(width, height);
223 this._update();
224 }, 169 },
225 170
226 /** 171 /**
227 * @protected 172 * @protected
228 */ 173 */
229 scheduleUpdate: function() 174 scheduleUpdate: function()
230 { 175 {
231 if (this._updateScheduled || !this.isShowing()) 176 if (this._updateScheduled || !this.isShowing())
232 return; 177 return;
233 this._updateScheduled = true; 178 this._updateScheduled = true;
234 this.element.window().requestAnimationFrame(this._update.bind(this)); 179 this.element.window().requestAnimationFrame(this.update.bind(this));
235 }, 180 },
236 181
237 _update: function() 182 /**
183 * @override
184 */
185 update: function()
238 { 186 {
239 this._updateScheduled = false; 187 this._updateScheduled = false;
240 188
241 var newBoundary = this._calculator.boundary(); 189 var newBoundary = new WebInspector.NetworkTimeBoundary(this._calculator. minimumBoundary(), this._calculator.maximumBoundary());
242 if (!newBoundary.equals(this._lastBoundary)) { 190 if (!this._lastBoundary || !newBoundary.equals(this._lastBoundary)) {
243 var span = this._calculator.boundarySpan(); 191 var span = this._calculator.boundarySpan();
244 while (this._span < span) 192 while (this._span < span)
245 this._span *= 1.25; 193 this._span *= 1.25;
246 this._calculator.updateBoundariesForEventTime(this._calculator.minim umBoundary() + this._span); 194 this._calculator.setBounds(this._calculator.minimumBoundary(), this. _calculator.minimumBoundary() + this._span);
247 this._lastBoundary = this._calculator.boundary(); 195 this._lastBoundary = new WebInspector.NetworkTimeBoundary(this._calc ulator.minimumBoundary(), this._calculator.maximumBoundary());
248 this._overviewGrid.updateDividers(this._calculator);
249 if (this._windowStart || this._windowEnd) { 196 if (this._windowStart || this._windowEnd) {
250 this._restoringWindow = true; 197 this._restoringWindow = true;
251 var startTime = this._calculator.minimumBoundary(); 198 var startTime = this._calculator.minimumBoundary();
252 var totalTime = this._calculator.boundarySpan(); 199 var totalTime = this._calculator.boundarySpan();
253 var left = (this._windowStart - startTime) / totalTime; 200 var left = (this._windowStart - startTime) / totalTime;
254 var right = (this._windowEnd - startTime) / totalTime; 201 var right = (this._windowEnd - startTime) / totalTime;
255 this._overviewGrid.setWindow(left, right);
256 this._restoringWindow = false; 202 this._restoringWindow = false;
257 } 203 }
258 } 204 }
259 205
260 var context = this._overviewCanvas.getContext("2d"); 206 var context = this._canvas.getContext("2d");
261 var calculator = this._calculator; 207 var calculator = this._calculator;
262 var linesByType = {}; 208 var linesByType = {};
263 var paddingTop = WebInspector.NetworkOverview._dividersBarHeight; 209 var paddingTop = 2;
264 210
265 /** 211 /**
266 * @param {string} type 212 * @param {string} type
267 * @param {string} strokeStyle 213 * @param {string} strokeStyle
268 */ 214 */
269 function drawLines(type, strokeStyle) 215 function drawLines(type, strokeStyle)
270 { 216 {
271 var lines = linesByType[type]; 217 var lines = linesByType[type];
272 if (!lines) 218 if (!lines)
273 return; 219 return;
274 var n = lines.length; 220 var n = lines.length;
275 context.beginPath(); 221 context.beginPath();
276 context.strokeStyle = strokeStyle; 222 context.strokeStyle = strokeStyle;
277 for (var i = 0; i < n;) { 223 for (var i = 0; i < n;) {
278 var y = lines[i++] * WebInspector.NetworkOverview._bandHeight + 2 + paddingTop; 224 var y = lines[i++] * WebInspector.NetworkOverview._bandHeight + paddingTop;
279 var startTime = lines[i++]; 225 var startTime = lines[i++];
280 var endTime = lines[i++]; 226 var endTime = lines[i++];
281 if (endTime === Number.MAX_VALUE) 227 if (endTime === Number.MAX_VALUE)
282 endTime = calculator.maximumBoundary(); 228 endTime = calculator.maximumBoundary();
283 context.moveTo(calculator.computePosition(startTime), y); 229 context.moveTo(calculator.computePosition(startTime), y);
284 context.lineTo(calculator.computePosition(endTime) + 1, y); 230 context.lineTo(calculator.computePosition(endTime) + 1, y);
285 } 231 }
286 context.stroke(); 232 context.stroke();
287 } 233 }
288 234
(...skipping 16 matching lines...) Expand all
305 var requests = this._requestsList; 251 var requests = this._requestsList;
306 var n = requests.length; 252 var n = requests.length;
307 for (var i = 0; i < n; ++i) { 253 for (var i = 0; i < n; ++i) {
308 var request = requests[i]; 254 var request = requests[i];
309 var band = this._bandId(request.connectionId); 255 var band = this._bandId(request.connectionId);
310 var y = (band === -1) ? 0 : (band % this._numBands + 1); 256 var y = (band === -1) ? 0 : (band % this._numBands + 1);
311 var timeRanges = WebInspector.RequestTimingView.calculateRequestTime Ranges(request); 257 var timeRanges = WebInspector.RequestTimingView.calculateRequestTime Ranges(request);
312 for (var j = 0; j < timeRanges.length; ++j) { 258 for (var j = 0; j < timeRanges.length; ++j) {
313 var type = timeRanges[j].name; 259 var type = timeRanges[j].name;
314 if (band !== -1 || type === WebInspector.RequestTimeRangeNames.T otal) 260 if (band !== -1 || type === WebInspector.RequestTimeRangeNames.T otal)
315 addLine(type, y, timeRanges[j].start, timeRanges[j].end); 261 addLine(type, y, timeRanges[j].start * 1000, timeRanges[j].e nd * 1000);
316 } 262 }
317 } 263 }
318 264
319 context.clearRect(0, 0, this._overviewCanvas.width, this._overviewCanvas .height); 265 context.clearRect(0, 0, this._canvas.width, this._canvas.height);
320 context.save(); 266 context.save();
321 context.scale(window.devicePixelRatio, window.devicePixelRatio); 267 context.scale(window.devicePixelRatio, window.devicePixelRatio);
322 context.fillStyle = "white";
323 context.lineWidth = 0;
324 context.fillRect(0, paddingTop, this._canvasWidth, this._canvasHeight - paddingTop);
325 context.lineWidth = 2; 268 context.lineWidth = 2;
326 drawLines(WebInspector.RequestTimeRangeNames.Total, "#CCCCCC"); 269 drawLines(WebInspector.RequestTimeRangeNames.Total, "#CCCCCC");
327 drawLines(WebInspector.RequestTimeRangeNames.Blocking, "#AAAAAA"); 270 drawLines(WebInspector.RequestTimeRangeNames.Blocking, "#AAAAAA");
328 drawLines(WebInspector.RequestTimeRangeNames.Connecting, "#FF9800"); 271 drawLines(WebInspector.RequestTimeRangeNames.Connecting, "#FF9800");
329 drawLines(WebInspector.RequestTimeRangeNames.ServiceWorker, "#FF9800"); 272 drawLines(WebInspector.RequestTimeRangeNames.ServiceWorker, "#FF9800");
330 drawLines(WebInspector.RequestTimeRangeNames.ServiceWorkerPreparation, " #FF9800"); 273 drawLines(WebInspector.RequestTimeRangeNames.ServiceWorkerPreparation, " #FF9800");
331 drawLines(WebInspector.RequestTimeRangeNames.Proxy, "#A1887F"); 274 drawLines(WebInspector.RequestTimeRangeNames.Proxy, "#A1887F");
332 drawLines(WebInspector.RequestTimeRangeNames.DNS, "#009688"); 275 drawLines(WebInspector.RequestTimeRangeNames.DNS, "#009688");
333 drawLines(WebInspector.RequestTimeRangeNames.SSL, "#9C27B0"); 276 drawLines(WebInspector.RequestTimeRangeNames.SSL, "#9C27B0");
334 drawLines(WebInspector.RequestTimeRangeNames.Sending, "#B0BEC5"); 277 drawLines(WebInspector.RequestTimeRangeNames.Sending, "#B0BEC5");
(...skipping 14 matching lines...) Expand all
349 context.strokeStyle = "#FF8080"; // Keep in sync with .network-red-divid er CSS rule. 292 context.strokeStyle = "#FF8080"; // Keep in sync with .network-red-divid er CSS rule.
350 for (var i = this._loadEvents.length; i >= 0; --i) { 293 for (var i = this._loadEvents.length; i >= 0; --i) {
351 var x = Math.round(calculator.computePosition(this._loadEvents[i])); 294 var x = Math.round(calculator.computePosition(this._loadEvents[i]));
352 context.moveTo(x + 0.5, 0); 295 context.moveTo(x + 0.5, 0);
353 context.lineTo(x + 0.5, this._canvasHeight); 296 context.lineTo(x + 0.5, this._canvasHeight);
354 } 297 }
355 context.stroke(); 298 context.stroke();
356 299
357 context.strokeStyle = "#063"; // Keep in sync with .network-frame-divide r CSS rule. 300 context.strokeStyle = "#063"; // Keep in sync with .network-frame-divide r CSS rule.
358 context.fillStyle = "#085"; // Keep in sync with .network-frame-divider CSS rule. 301 context.fillStyle = "#085"; // Keep in sync with .network-frame-divider CSS rule.
302 var /** @const */ radius = 4;
359 var frames = this._filmStripModel ? this._filmStripModel.frames() : []; 303 var frames = this._filmStripModel ? this._filmStripModel.frames() : [];
360 for (var i = 0; i < frames.length; ++i) { 304 for (var i = 0; i < frames.length; ++i) {
361 var x = Math.round(calculator.computePosition(frames[i].timestamp / 1000)); 305 var x = Math.round(calculator.computePosition(frames[i].timestamp));
362 context.beginPath(); 306 context.beginPath();
363 context.arc(x, 20, 4, 0, 2*Math.PI, false); 307 context.arc(x, radius, radius, 0, 2*Math.PI, false);
364 context.fill(); 308 context.fill();
365 context.stroke(); 309 context.stroke();
366 } 310 }
367 311
368 if (this._selectedFilmStripTime !== -1) { 312 if (this._selectedFilmStripTime !== -1) {
369 context.fillStyle = "#FFE3C7"; // Keep in sync with .network-frame- divider CSS rule. 313 context.fillStyle = "#FFE3C7"; // Keep in sync with .network-frame- divider CSS rule.
370 var x = Math.round(calculator.computePosition(this._selectedFilmStr ipTime)); 314 var x = Math.round(calculator.computePosition(this._selectedFilmStr ipTime));
371 context.beginPath(); 315 context.beginPath();
372 context.arc(x, 20, 4, 0, 2 * Math.PI, false); 316 context.arc(x, radius, radius, 0, 2 * Math.PI, false);
373 context.fill(); 317 context.fill();
374 context.stroke(); 318 context.stroke();
375 } 319 }
376 context.restore(); 320 context.restore();
377 }, 321 },
378 322
379 /** 323 __proto__: WebInspector.TimelineOverviewBase.prototype
380 * @param {number} width
381 * @param {number} height
382 */
383 _resetCanvas: function(width, height)
384 {
385 this._canvasWidth = width;
386 this._canvasHeight = height;
387 this._overviewCanvas.width = width * window.devicePixelRatio;
388 this._overviewCanvas.height = height * window.devicePixelRatio;
389 this._overviewGrid.updateDividers(this._calculator);
390 },
391
392 __proto__: WebInspector.VBox.prototype
393 } 324 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/network/NetworkLogView.js ('k') | Source/devtools/front_end/network/NetworkPanel.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698