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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/timeline/TimelineFrameModel.js

Issue 1613543003: Timeline: unify frame computation for threaded and single-thread scenarios (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« no previous file with comments | « third_party/WebKit/LayoutTests/inspector/tracing/frame-model-expected.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 } 191 }
192 }, 192 },
193 193
194 reset: function() 194 reset: function()
195 { 195 {
196 this._minimumRecordTime = Infinity; 196 this._minimumRecordTime = Infinity;
197 this._frames = []; 197 this._frames = [];
198 this._frameById = {}; 198 this._frameById = {};
199 this._lastFrame = null; 199 this._lastFrame = null;
200 this._lastLayerTree = null; 200 this._lastLayerTree = null;
201 this._hasThreadedCompositing = false;
202 this._mainFrameCommitted = false; 201 this._mainFrameCommitted = false;
203 this._mainFrameRequested = false; 202 this._mainFrameRequested = false;
204 this._framePendingCommit = null; 203 this._framePendingCommit = null;
205 this._lastBeginFrame = null; 204 this._lastBeginFrame = null;
206 this._lastNeedsBeginFrame = null; 205 this._lastNeedsBeginFrame = null;
207 }, 206 },
208 207
209 /** 208 /**
210 * @param {number} startTime 209 * @param {number} startTime
211 */ 210 */
212 handleBeginFrame: function(startTime) 211 handleBeginFrame: function(startTime)
213 { 212 {
214 if (!this._lastFrame) 213 if (!this._lastFrame)
215 this._startBackgroundFrame(startTime); 214 this._startFrame(startTime);
216 this._lastBeginFrame = startTime; 215 this._lastBeginFrame = startTime;
217 }, 216 },
218 217
219 /** 218 /**
220 * @param {number} startTime 219 * @param {number} startTime
221 */ 220 */
222 handleDrawFrame: function(startTime) 221 handleDrawFrame: function(startTime)
223 { 222 {
224 if (!this._lastFrame) { 223 if (!this._lastFrame) {
225 this._startBackgroundFrame(startTime); 224 this._startFrame(startTime);
226 return; 225 return;
227 } 226 }
228 227
229 // - if it wasn't drawn, it didn't happen! 228 // - if it wasn't drawn, it didn't happen!
230 // - only show frames that either did not wait for the main thread frame or had one committed. 229 // - only show frames that either did not wait for the main thread frame or had one committed.
231 if (this._mainFrameCommitted || !this._mainFrameRequested) { 230 if (this._mainFrameCommitted || !this._mainFrameRequested) {
232 if (this._lastNeedsBeginFrame) { 231 if (this._lastNeedsBeginFrame) {
233 this._lastFrame.idle = true; 232 this._lastFrame.idle = true;
234 var idleTimeEnd = this._framePendingActivation ? this._framePend ingActivation.triggerTime : (this._lastBeginFrame || this._lastNeedsBeginFrame); 233 var idleTimeEnd = this._framePendingActivation ? this._framePend ingActivation.triggerTime : (this._lastBeginFrame || this._lastNeedsBeginFrame);
235 this._startBackgroundFrame(idleTimeEnd); 234 this._startFrame(idleTimeEnd);
236 if (this._framePendingActivation) 235 if (this._framePendingActivation)
237 this._commitPendingFrame(); 236 this._commitPendingFrame();
238 this._lastNeedsBeginFrame = null; 237 this._lastNeedsBeginFrame = null;
239 this._lastBeginFrame = null; 238 this._lastBeginFrame = null;
240 } 239 }
241 this._startBackgroundFrame(startTime); 240 this._startFrame(startTime);
242 } 241 }
243 this._mainFrameCommitted = false; 242 this._mainFrameCommitted = false;
244 }, 243 },
245 244
246 handleActivateLayerTree: function() 245 handleActivateLayerTree: function()
247 { 246 {
248 if (!this._lastFrame) 247 if (!this._lastFrame)
249 return; 248 return;
250 if (this._framePendingActivation && !this._lastNeedsBeginFrame) 249 if (this._framePendingActivation && !this._lastNeedsBeginFrame)
251 this._commitPendingFrame(); 250 this._commitPendingFrame();
252 }, 251 },
253 252
254 handleRequestMainThreadFrame: function() 253 handleRequestMainThreadFrame: function()
255 { 254 {
256 if (!this._lastFrame) 255 if (!this._lastFrame)
257 return; 256 return;
258 this._mainFrameRequested = true; 257 this._mainFrameRequested = true;
259 }, 258 },
260 259
261 handleCompositeLayers: function() 260 handleCompositeLayers: function()
262 { 261 {
263 if (!this._hasThreadedCompositing || !this._framePendingCommit) 262 if (!this._framePendingCommit)
264 return; 263 return;
265 this._framePendingActivation = this._framePendingCommit; 264 this._framePendingActivation = this._framePendingCommit;
266 this._framePendingCommit = null; 265 this._framePendingCommit = null;
267 this._mainFrameRequested = false; 266 this._mainFrameRequested = false;
268 this._mainFrameCommitted = true; 267 this._mainFrameCommitted = true;
269 }, 268 },
270 269
271 /** 270 /**
272 * @param {!WebInspector.DeferredLayerTree} layerTree 271 * @param {!WebInspector.DeferredLayerTree} layerTree
273 */ 272 */
274 handleLayerTreeSnapshot: function(layerTree) 273 handleLayerTreeSnapshot: function(layerTree)
275 { 274 {
276 this._lastLayerTree = layerTree; 275 this._lastLayerTree = layerTree;
277 }, 276 },
278 277
279 /** 278 /**
280 * @param {number} startTime 279 * @param {number} startTime
281 * @param {boolean} needsBeginFrame 280 * @param {boolean} needsBeginFrame
282 */ 281 */
283 handleNeedFrameChanged: function(startTime, needsBeginFrame) 282 handleNeedFrameChanged: function(startTime, needsBeginFrame)
284 { 283 {
285 if (needsBeginFrame) 284 if (needsBeginFrame)
286 this._lastNeedsBeginFrame = startTime; 285 this._lastNeedsBeginFrame = startTime;
287 }, 286 },
288 287
289 /** 288 /**
290 * @param {number} startTime 289 * @param {number} startTime
291 */ 290 */
292 _startBackgroundFrame: function(startTime) 291 _startFrame: function(startTime)
293 {
294 if (!this._hasThreadedCompositing) {
295 this._lastFrame = null;
296 this._hasThreadedCompositing = true;
297 }
298 if (this._lastFrame)
299 this._flushFrame(this._lastFrame, startTime);
300
301 this._lastFrame = new WebInspector.TimelineFrame(startTime, startTime - this._minimumRecordTime);
302 },
303
304 /**
305 * @param {number} startTime
306 * @param {number=} frameId
307 */
308 _startMainThreadFrame: function(startTime, frameId)
309 { 292 {
310 if (this._lastFrame) 293 if (this._lastFrame)
311 this._flushFrame(this._lastFrame, startTime); 294 this._flushFrame(this._lastFrame, startTime);
312 this._lastFrame = new WebInspector.TimelineFrame(startTime, startTime - this._minimumRecordTime); 295 this._lastFrame = new WebInspector.TimelineFrame(startTime, startTime - this._minimumRecordTime);
313 this._lastFrame._mainFrameId = frameId;
314 }, 296 },
315 297
316 /** 298 /**
317 * @param {!WebInspector.TimelineFrame} frame 299 * @param {!WebInspector.TimelineFrame} frame
318 * @param {number} endTime 300 * @param {number} endTime
319 */ 301 */
320 _flushFrame: function(frame, endTime) 302 _flushFrame: function(frame, endTime)
321 { 303 {
322 frame._setLayerTree(this._lastLayerTree); 304 frame._setLayerTree(this._lastLayerTree);
323 frame._setEndTime(endTime); 305 frame._setEndTime(endTime);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 387
406 if (event.name === eventNames.SetLayerTreeId) { 388 if (event.name === eventNames.SetLayerTreeId) {
407 var sessionId = event.args["sessionId"] || event.args["data"]["sessi onId"]; 389 var sessionId = event.args["sessionId"] || event.args["data"]["sessi onId"];
408 if (this._sessionId === sessionId) 390 if (this._sessionId === sessionId)
409 this._layerTreeId = event.args["layerTreeId"] || event.args["dat a"]["layerTreeId"]; 391 this._layerTreeId = event.args["layerTreeId"] || event.args["dat a"]["layerTreeId"];
410 } else if (event.name === eventNames.TracingStartedInPage) { 392 } else if (event.name === eventNames.TracingStartedInPage) {
411 this._mainThread = event.thread; 393 this._mainThread = event.thread;
412 } else if (event.phase === WebInspector.TracingModel.Phase.SnapshotObjec t && event.name === eventNames.LayerTreeHostImplSnapshot && parseInt(event.id, 0 ) === this._layerTreeId) { 394 } else if (event.phase === WebInspector.TracingModel.Phase.SnapshotObjec t && event.name === eventNames.LayerTreeHostImplSnapshot && parseInt(event.id, 0 ) === this._layerTreeId) {
413 var snapshot = /** @type {!WebInspector.TracingModel.ObjectSnapshot} */ (event); 395 var snapshot = /** @type {!WebInspector.TracingModel.ObjectSnapshot} */ (event);
414 this.handleLayerTreeSnapshot(new WebInspector.DeferredTracingLayerTr ee(snapshot, this._target)); 396 this.handleLayerTreeSnapshot(new WebInspector.DeferredTracingLayerTr ee(snapshot, this._target));
415 } else if (event.thread === this._mainThread) {
416 this._addMainThreadTraceEvent(event);
417 } else { 397 } else {
418 this._addBackgroundTraceEvent(event); 398 this._processCompositorEvents(event);
399 if (event.thread === this._mainThread)
400 this._addMainThreadTraceEvent(event);
401 else if (this._lastFrame && event.selfTime && !WebInspector.TracingM odel.isTopLevelEvent(event))
402 this._lastFrame._addTimeForCategory(WebInspector.TimelineUIUtils .eventStyle(event).category.name, event.selfTime);
419 } 403 }
420 }, 404 },
421 405
422 /** 406 /**
423 * @param {!WebInspector.TracingModel.Event} event 407 * @param {!WebInspector.TracingModel.Event} event
424 */ 408 */
425 _addBackgroundTraceEvent: function(event) 409 _processCompositorEvents: function(event)
426 { 410 {
427 var eventNames = WebInspector.TimelineModel.RecordType; 411 var eventNames = WebInspector.TimelineModel.RecordType;
428 if (this._lastFrame && event.selfTime && !WebInspector.TracingModel.isTo pLevelEvent(event))
429 this._lastFrame._addTimeForCategory(WebInspector.TimelineUIUtils.eve ntStyle(event).category.name, event.selfTime);
430 412
431 if (event.args["layerTreeId"] !== this._layerTreeId) 413 if (event.args["layerTreeId"] !== this._layerTreeId)
432 return; 414 return;
433 415
434 var timestamp = event.startTime; 416 var timestamp = event.startTime;
435 if (event.name === eventNames.BeginFrame) 417 if (event.name === eventNames.BeginFrame)
436 this.handleBeginFrame(timestamp); 418 this.handleBeginFrame(timestamp);
437 else if (event.name === eventNames.DrawFrame) 419 else if (event.name === eventNames.DrawFrame)
438 this.handleDrawFrame(timestamp); 420 this.handleDrawFrame(timestamp);
439 else if (event.name === eventNames.ActivateLayerTree) 421 else if (event.name === eventNames.ActivateLayerTree)
440 this.handleActivateLayerTree(); 422 this.handleActivateLayerTree();
441 else if (event.name === eventNames.RequestMainThreadFrame) 423 else if (event.name === eventNames.RequestMainThreadFrame)
442 this.handleRequestMainThreadFrame(); 424 this.handleRequestMainThreadFrame();
443 else if (event.name === eventNames.NeedsBeginFrameChanged) 425 else if (event.name === eventNames.NeedsBeginFrameChanged)
444 this.handleNeedFrameChanged(timestamp, event.args["data"] && event.a rgs["data"]["needsBeginFrame"]); 426 this.handleNeedFrameChanged(timestamp, event.args["data"] && event.a rgs["data"]["needsBeginFrame"]);
445 }, 427 },
446 428
447 /** 429 /**
448 * @param {!WebInspector.TracingModel.Event} event 430 * @param {!WebInspector.TracingModel.Event} event
449 */ 431 */
450 _addMainThreadTraceEvent: function(event) 432 _addMainThreadTraceEvent: function(event)
451 { 433 {
452 var eventNames = WebInspector.TimelineModel.RecordType; 434 var eventNames = WebInspector.TimelineModel.RecordType;
453 var timestamp = event.startTime; 435 var timestamp = event.startTime;
454 var selfTime = event.selfTime || 0; 436 var selfTime = event.selfTime || 0;
455 437
456 if (!this._hasThreadedCompositing) {
457 if (event.name === eventNames.BeginMainThreadFrame)
458 this._startMainThreadFrame(timestamp, event.args["data"] && even t.args["data"]["frameId"]);
459 if (!this._lastFrame)
460 return;
461 if (!selfTime)
462 return;
463
464 var categoryName = WebInspector.TimelineUIUtils.eventStyle(event).ca tegory.name;
465 this._lastFrame._addTimeForCategory(categoryName, selfTime);
466 if (event.name === eventNames.Paint && event.args["data"]["layerId"] && event.picture && this._target)
467 this._lastFrame.paints.push(new WebInspector.LayerPaintEvent(eve nt, this._target));
468 return;
469 }
470
471 if (WebInspector.TracingModel.isTopLevelEvent(event)) { 438 if (WebInspector.TracingModel.isTopLevelEvent(event)) {
472 this._currentTaskTimeByCategory = {}; 439 this._currentTaskTimeByCategory = {};
473 this._lastTaskBeginTime = event.startTime; 440 this._lastTaskBeginTime = event.startTime;
474 } 441 }
475 if (!this._framePendingCommit && WebInspector.TracingTimelineFrameModel. _mainFrameMarkers.indexOf(event.name) >= 0) 442 if (!this._framePendingCommit && WebInspector.TracingTimelineFrameModel. _mainFrameMarkers.indexOf(event.name) >= 0)
476 this._framePendingCommit = new WebInspector.PendingFrame(this._lastT askBeginTime, this._currentTaskTimeByCategory); 443 this._framePendingCommit = new WebInspector.PendingFrame(this._lastT askBeginTime, this._currentTaskTimeByCategory);
477 if (!this._framePendingCommit) { 444 if (!this._framePendingCommit) {
478 this._addTimeForCategory(this._currentTaskTimeByCategory, event); 445 this._addTimeForCategory(this._currentTaskTimeByCategory, event);
479 return; 446 return;
480 } 447 }
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 WebInspector.PendingFrame = function(triggerTime, timeByCategory) 659 WebInspector.PendingFrame = function(triggerTime, timeByCategory)
693 { 660 {
694 /** @type {!Object.<string, number>} */ 661 /** @type {!Object.<string, number>} */
695 this.timeByCategory = timeByCategory; 662 this.timeByCategory = timeByCategory;
696 /** @type {!Array.<!WebInspector.LayerPaintEvent>} */ 663 /** @type {!Array.<!WebInspector.LayerPaintEvent>} */
697 this.paints = []; 664 this.paints = [];
698 /** @type {number|undefined} */ 665 /** @type {number|undefined} */
699 this.mainFrameId = undefined; 666 this.mainFrameId = undefined;
700 this.triggerTime = triggerTime; 667 this.triggerTime = triggerTime;
701 } 668 }
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/inspector/tracing/frame-model-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698