| OLD | NEW |
| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 FrameAdded: "FrameAdded" | 44 FrameAdded: "FrameAdded" |
| 45 } | 45 } |
| 46 | 46 |
| 47 WebInspector.TimelineFrameModel._mainFrameMarkers = [ | 47 WebInspector.TimelineFrameModel._mainFrameMarkers = [ |
| 48 WebInspector.TimelineModel.RecordType.ScheduleStyleRecalculation, | 48 WebInspector.TimelineModel.RecordType.ScheduleStyleRecalculation, |
| 49 WebInspector.TimelineModel.RecordType.InvalidateLayout, | 49 WebInspector.TimelineModel.RecordType.InvalidateLayout, |
| 50 WebInspector.TimelineModel.RecordType.BeginFrame, | 50 WebInspector.TimelineModel.RecordType.BeginFrame, |
| 51 WebInspector.TimelineModel.RecordType.ScrollLayer | 51 WebInspector.TimelineModel.RecordType.ScrollLayer |
| 52 ]; | 52 ]; |
| 53 | 53 |
| 54 WebInspector.TimelineFrameModel._tracingMainFrameMarkers = [ |
| 55 WebInspector.TracingTimelineModel.RecordType.ScheduleStyleRecalculation, |
| 56 WebInspector.TracingTimelineModel.RecordType.InvalidateLayout, |
| 57 WebInspector.TracingTimelineModel.RecordType.BeginMainThreadFrame, |
| 58 WebInspector.TracingTimelineModel.RecordType.ScrollLayer |
| 59 ]; |
| 60 |
| 54 WebInspector.TimelineFrameModel.prototype = { | 61 WebInspector.TimelineFrameModel.prototype = { |
| 55 /** | 62 /** |
| 56 * @return {!Array.<!WebInspector.TimelineFrame>} | 63 * @return {!Array.<!WebInspector.TimelineFrame>} |
| 57 */ | 64 */ |
| 58 frames: function() | 65 frames: function() |
| 59 { | 66 { |
| 60 return this._frames; | 67 return this._frames; |
| 61 }, | 68 }, |
| 62 | 69 |
| 63 /** | 70 /** |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 */ | 176 */ |
| 170 _addTraceEvent: function(event) | 177 _addTraceEvent: function(event) |
| 171 { | 178 { |
| 172 var eventNames = WebInspector.TracingTimelineModel.RecordType; | 179 var eventNames = WebInspector.TracingTimelineModel.RecordType; |
| 173 | 180 |
| 174 if (event.name === eventNames.SetLayerTreeId) { | 181 if (event.name === eventNames.SetLayerTreeId) { |
| 175 if (this._sessionId === event.args["sessionId"]) | 182 if (this._sessionId === event.args["sessionId"]) |
| 176 this._layerTreeId = event.args["layerTreeId"]; | 183 this._layerTreeId = event.args["layerTreeId"]; |
| 177 return; | 184 return; |
| 178 } | 185 } |
| 186 if (event.name === eventNames.TracingStartedInPage) { |
| 187 this._mainThread = event.thread; |
| 188 return; |
| 189 } |
| 190 if (event.thread === this._mainThread) |
| 191 this._addMainThreadTraceEvent(event); |
| 192 else |
| 193 this._addBackgroundTraceEvent(event); |
| 194 }, |
| 195 |
| 196 /** |
| 197 * @param {!WebInspector.TracingModel.Event} event |
| 198 */ |
| 199 _addBackgroundTraceEvent: function(event) |
| 200 { |
| 201 var eventNames = WebInspector.TracingTimelineModel.RecordType; |
| 202 |
| 179 if (event.phase === WebInspector.TracingModel.Phase.SnapshotObject && ev
ent.name === eventNames.LayerTreeHostImplSnapshot && parseInt(event.id, 0) === t
his._layerTreeId) { | 203 if (event.phase === WebInspector.TracingModel.Phase.SnapshotObject && ev
ent.name === eventNames.LayerTreeHostImplSnapshot && parseInt(event.id, 0) === t
his._layerTreeId) { |
| 180 this.handleLayerTreeSnapshot(new WebInspector.DeferredTracingLayerTr
ee(this.target(), event.args["snapshot"]["active_tree"]["root_layer"])); | 204 this.handleLayerTreeSnapshot(new WebInspector.DeferredTracingLayerTr
ee(this.target(), event.args["snapshot"]["active_tree"]["root_layer"])); |
| 181 return; | 205 return; |
| 182 } | 206 } |
| 207 if (this._lastFrame && event.selfTime) |
| 208 this._lastFrame._addTimeForCategory(WebInspector.TracingTimelineUIUt
ils.eventStyle(event).category.name, event.selfTime); |
| 183 | 209 |
| 184 if (event.args["layerTreeId"] !== this._layerTreeId) | 210 if (event.args["layerTreeId"] !== this._layerTreeId) |
| 185 return; | 211 return; |
| 186 | 212 |
| 187 var timestamp = event.startTime; | 213 var timestamp = event.startTime; |
| 188 if (event.name === eventNames.BeginFrame) | 214 if (event.name === eventNames.BeginFrame) |
| 189 this.handleBeginFrame(timestamp); | 215 this.handleBeginFrame(timestamp); |
| 190 else if (event.name === eventNames.DrawFrame) | 216 else if (event.name === eventNames.DrawFrame) |
| 191 this.handleDrawFrame(timestamp); | 217 this.handleDrawFrame(timestamp); |
| 192 else if (event.name === eventNames.ActivateLayerTree) | 218 else if (event.name === eventNames.ActivateLayerTree) |
| 193 this.handleActivateLayerTree(); | 219 this.handleActivateLayerTree(); |
| 194 else if (event.name === eventNames.RequestMainThreadFrame) | 220 else if (event.name === eventNames.RequestMainThreadFrame) |
| 195 this.handleRequestMainThreadFrame(); | 221 this.handleRequestMainThreadFrame(); |
| 196 else if (event.name === eventNames.CompositeLayers) | |
| 197 this.handleCompositeLayers(); | |
| 198 | |
| 199 // FIXME: we also need to process main thread events, so we can assign t
ime spent by categories | |
| 200 // to frames. However, this requires that we can map trace event names t
o Timeline categories. | |
| 201 }, | 222 }, |
| 202 | 223 |
| 203 /** | 224 /** |
| 225 * @param {!WebInspector.TracingModel.Event} event |
| 226 */ |
| 227 _addMainThreadTraceEvent: function(event) |
| 228 { |
| 229 var eventNames = WebInspector.TracingTimelineModel.RecordType; |
| 230 var timestamp = event.startTime; |
| 231 var selfTime = event.selfTime || 0; |
| 232 |
| 233 if (!this._hasThreadedCompositing) { |
| 234 if (event.name === eventNames.BeginMainThreadFrame) |
| 235 this._startMainThreadFrame(timestamp); |
| 236 if (!this._lastFrame) |
| 237 return; |
| 238 if (!selfTime) |
| 239 return; |
| 240 |
| 241 var categoryName = WebInspector.TracingTimelineUIUtils.eventStyle(ev
ent).category.name; |
| 242 this._lastFrame._addTimeForCategory(categoryName, selfTime); |
| 243 return; |
| 244 } |
| 245 |
| 246 if (!this._aggregatedMainThreadWork && WebInspector.TimelineFrameModel._
tracingMainFrameMarkers.indexOf(event.name) >= 0) |
| 247 this._aggregatedMainThreadWork = {}; |
| 248 if (!this._aggregatedMainThreadWork) |
| 249 return; |
| 250 |
| 251 if (selfTime) { |
| 252 var categoryName = WebInspector.TracingTimelineUIUtils.eventStyle(ev
ent).category.name; |
| 253 this._aggregatedMainThreadWork[categoryName] = (this._aggregatedMain
ThreadWork[categoryName] || 0) + selfTime; |
| 254 } |
| 255 if (event.name === eventNames.CompositeLayers && event.args["layerTreeId
"] === this._layerTreeId) |
| 256 this.handleCompositeLayers(); |
| 257 }, |
| 258 |
| 259 /** |
| 204 * @param {number} startTime | 260 * @param {number} startTime |
| 205 */ | 261 */ |
| 206 handleBeginFrame: function(startTime) | 262 handleBeginFrame: function(startTime) |
| 207 { | 263 { |
| 208 if (!this._lastFrame) | 264 if (!this._lastFrame) |
| 209 this._startBackgroundFrame(startTime); | 265 this._startBackgroundFrame(startTime); |
| 210 }, | 266 }, |
| 211 | 267 |
| 212 /** | 268 /** |
| 213 * @param {number} startTime | 269 * @param {number} startTime |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 if (!this._hasThreadedCompositing) { | 346 if (!this._hasThreadedCompositing) { |
| 291 if (record.type() === recordTypes.BeginFrame) | 347 if (record.type() === recordTypes.BeginFrame) |
| 292 this._startMainThreadFrame(record.startTime()); | 348 this._startMainThreadFrame(record.startTime()); |
| 293 | 349 |
| 294 if (!this._lastFrame) | 350 if (!this._lastFrame) |
| 295 return; | 351 return; |
| 296 | 352 |
| 297 this._lastFrame._addTimeFromRecord(record); | 353 this._lastFrame._addTimeFromRecord(record); |
| 298 | 354 |
| 299 // Account for "other" time at the same time as the first child. | 355 // Account for "other" time at the same time as the first child. |
| 300 if (programRecord.children()[0] === record) { | 356 if (programRecord.children()[0] === record) |
| 301 this._deriveOtherTime(programRecord, this._lastFrame.timeByCateg
ory); | 357 this._lastFrame._addTimeForCategory("other", this._deriveOtherTi
me(programRecord)); |
| 302 this._lastFrame._updateCpuTime(); | |
| 303 } | |
| 304 return; | 358 return; |
| 305 } | 359 } |
| 306 | 360 |
| 307 if (!this._aggregatedMainThreadWork) | 361 if (!this._aggregatedMainThreadWork) |
| 308 return; | 362 return; |
| 309 | 363 |
| 310 WebInspector.TimelineUIUtils.aggregateTimeForRecord(this._aggregatedMain
ThreadWork, record); | 364 WebInspector.TimelineUIUtils.aggregateTimeForRecord(this._aggregatedMain
ThreadWork, record); |
| 311 if (programRecord.children()[0] === record) | 365 if (programRecord.children()[0] === record) |
| 312 this._deriveOtherTime(programRecord, this._aggregatedMainThreadWork)
; | 366 this._aggregatedMainThreadWork["other"] = (this._aggregatedMainThrea
dWork["other"] || 0) + this._deriveOtherTime(programRecord); |
| 313 | 367 |
| 314 if (record.type() === recordTypes.CompositeLayers) | 368 if (record.type() === recordTypes.CompositeLayers) |
| 315 this.handleCompositeLayers(); | 369 this.handleCompositeLayers(); |
| 316 }, | 370 }, |
| 317 | 371 |
| 318 /** | 372 /** |
| 319 * @param {!WebInspector.TimelineModel.Record} programRecord | 373 * @param {!WebInspector.TimelineModel.Record} programRecord |
| 320 * @param {!Object} timeByCategory | 374 * @return {number} |
| 321 */ | 375 */ |
| 322 _deriveOtherTime: function(programRecord, timeByCategory) | 376 _deriveOtherTime: function(programRecord) |
| 323 { | 377 { |
| 324 var accounted = 0; | 378 var accounted = 0; |
| 325 for (var i = 0; i < programRecord.children().length; ++i) | 379 for (var i = 0; i < programRecord.children().length; ++i) |
| 326 accounted += programRecord.children()[i].endTime() - programRecord.c
hildren()[i].startTime(); | 380 accounted += programRecord.children()[i].endTime() - programRecord.c
hildren()[i].startTime(); |
| 327 var otherTime = programRecord.endTime() - programRecord.startTime() - ac
counted; | 381 return programRecord.endTime() - programRecord.startTime() - accounted; |
| 328 timeByCategory["other"] = (timeByCategory["other"] || 0) + otherTime; | |
| 329 }, | 382 }, |
| 330 | 383 |
| 331 /** | 384 /** |
| 332 * @param {number} startTime | 385 * @param {number} startTime |
| 333 */ | 386 */ |
| 334 _startBackgroundFrame: function(startTime) | 387 _startBackgroundFrame: function(startTime) |
| 335 { | 388 { |
| 336 if (!this._hasThreadedCompositing) { | 389 if (!this._hasThreadedCompositing) { |
| 337 this._lastFrame = null; | 390 this._lastFrame = null; |
| 338 this._hasThreadedCompositing = true; | 391 this._hasThreadedCompositing = true; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 this.layerTree = layerTree; | 504 this.layerTree = layerTree; |
| 452 }, | 505 }, |
| 453 | 506 |
| 454 /** | 507 /** |
| 455 * @param {!WebInspector.TimelineModel.Record} record | 508 * @param {!WebInspector.TimelineModel.Record} record |
| 456 */ | 509 */ |
| 457 _addTimeFromRecord: function(record) | 510 _addTimeFromRecord: function(record) |
| 458 { | 511 { |
| 459 if (!record.endTime()) | 512 if (!record.endTime()) |
| 460 return; | 513 return; |
| 461 WebInspector.TimelineUIUtils.aggregateTimeForRecord(this.timeByCategory,
record); | 514 var timeByCategory = {}; |
| 462 this._updateCpuTime(); | 515 WebInspector.TimelineUIUtils.aggregateTimeForRecord(timeByCategory, reco
rd); |
| 516 this._addTimeForCategories(timeByCategory); |
| 463 }, | 517 }, |
| 464 | 518 |
| 465 /** | 519 /** |
| 466 * @param {!Object} timeByCategory | 520 * @param {!Object} timeByCategory |
| 467 */ | 521 */ |
| 468 _addTimeForCategories: function(timeByCategory) | 522 _addTimeForCategories: function(timeByCategory) |
| 469 { | 523 { |
| 470 WebInspector.TimelineUIUtils.aggregateTimeByCategory(this.timeByCategory
, timeByCategory); | 524 for (var category in timeByCategory) |
| 471 this._updateCpuTime(); | 525 this._addTimeForCategory(category, timeByCategory[category]); |
| 472 }, | 526 }, |
| 473 | 527 |
| 474 _updateCpuTime: function() | 528 /** |
| 529 * @param {string} category |
| 530 * @param {number} time |
| 531 */ |
| 532 _addTimeForCategory: function(category, time) |
| 475 { | 533 { |
| 476 this.cpuTime = 0; | 534 this.timeByCategory[category] = (this.timeByCategory[category] || 0) + t
ime; |
| 477 for (var key in this.timeByCategory) | 535 this.cpuTime += time; |
| 478 this.cpuTime += this.timeByCategory[key]; | 536 }, |
| 479 } | |
| 480 } | 537 } |
| OLD | NEW |