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

Side by Side Diff: Source/devtools/front_end/TimelineFrameModel.js

Issue 183893010: DevTools: extract TimelineModel.Record from TimelinePresentationModel.Record. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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 /* 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 20 matching lines...) Expand all
31 /** 31 /**
32 * @constructor 32 * @constructor
33 * @extends {WebInspector.Object} 33 * @extends {WebInspector.Object}
34 * @param {!WebInspector.TimelineModel} model 34 * @param {!WebInspector.TimelineModel} model
35 */ 35 */
36 WebInspector.TimelineFrameModel = function(model) 36 WebInspector.TimelineFrameModel = function(model)
37 { 37 {
38 this._model = model; 38 this._model = model;
39 39
40 this.reset(); 40 this.reset();
41 var records = model.records; 41 var records = model.records();
42 for (var i = 0; i < records.length; ++i) 42 for (var i = 0; i < records.length; ++i)
43 this.addRecord(records[i]); 43 this.addRecord(records[i]);
44 } 44 }
45 45
46 WebInspector.TimelineFrameModel.Events = { 46 WebInspector.TimelineFrameModel.Events = {
47 FrameAdded: "FrameAdded" 47 FrameAdded: "FrameAdded"
48 } 48 }
49 49
50 WebInspector.TimelineFrameModel.prototype = { 50 WebInspector.TimelineFrameModel.prototype = {
51 /** 51 /**
(...skipping 30 matching lines...) Expand all
82 this._frames = []; 82 this._frames = [];
83 this._lastFrame = null; 83 this._lastFrame = null;
84 this._hasThreadedCompositing = false; 84 this._hasThreadedCompositing = false;
85 this._mainFrameCommitted = false; 85 this._mainFrameCommitted = false;
86 this._mainFrameRequested = false; 86 this._mainFrameRequested = false;
87 this._aggregatedMainThreadWork = null; 87 this._aggregatedMainThreadWork = null;
88 this._mergingBuffer = new WebInspector.TimelineMergingRecordBuffer(); 88 this._mergingBuffer = new WebInspector.TimelineMergingRecordBuffer();
89 }, 89 },
90 90
91 /** 91 /**
92 * @param {!TimelineAgent.TimelineEvent} record 92 * @param {!WebInspector.TimelineModel.Record} record
93 */ 93 */
94 addRecord: function(record) 94 addRecord: function(record)
95 { 95 {
96 var recordTypes = WebInspector.TimelineModel.RecordType; 96 var recordTypes = WebInspector.TimelineModel.RecordType;
97 var programRecord = record.type === recordTypes.Program ? record : null; 97 var programRecord = record.type === recordTypes.Program ? record : null;
98 98
99 // Start collecting main frame 99 // Start collecting main frame
100 if (programRecord) { 100 if (programRecord) {
101 if (!this._aggregatedMainThreadWork && this._findRecordRecursively([ recordTypes.ScheduleStyleRecalculation, recordTypes.InvalidateLayout, recordType s.BeginFrame], programRecord)) 101 if (!this._aggregatedMainThreadWork && this._findRecordRecursively([ recordTypes.ScheduleStyleRecalculation, recordTypes.InvalidateLayout, recordType s.BeginFrame], programRecord))
102 this._aggregatedMainThreadWork = {}; 102 this._aggregatedMainThreadWork = {};
103 } 103 }
104 104
105 var records = this._mergingBuffer.process(record.thread, programRecord ? record.children || [] : [record]); 105 var records = this._mergingBuffer.process(record.thread, programRecord ? record.children || [] : [record]);
106 for (var i = 0; i < records.length; ++i) { 106 for (var i = 0; i < records.length; ++i) {
107 if (records[i].thread) 107 if (records[i].thread)
108 this._addBackgroundRecord(records[i]); 108 this._addBackgroundRecord(records[i]);
109 else 109 else
110 this._addMainThreadRecord(programRecord, records[i]); 110 this._addMainThreadRecord(programRecord, records[i]);
111 } 111 }
112 }, 112 },
113 113
114 /** 114 /**
115 * @param {!TimelineAgent.TimelineEvent} record 115 * @param {!WebInspector.TimelineModel.Record} record
116 */ 116 */
117 _addBackgroundRecord: function(record) 117 _addBackgroundRecord: function(record)
118 { 118 {
119 var recordTypes = WebInspector.TimelineModel.RecordType; 119 var recordTypes = WebInspector.TimelineModel.RecordType;
120 if (!this._lastFrame) { 120 if (!this._lastFrame) {
121 if (record.type === recordTypes.BeginFrame || record.type === record Types.DrawFrame) 121 if (record.type === recordTypes.BeginFrame || record.type === record Types.DrawFrame)
122 this._startBackgroundFrame(record); 122 this._startBackgroundFrame(record);
123 return; 123 return;
124 } 124 }
125 125
126 if (record.type === recordTypes.DrawFrame) { 126 if (record.type === recordTypes.DrawFrame) {
127 // - if it wasn't drawn, it didn't happen! 127 // - if it wasn't drawn, it didn't happen!
128 // - only show frames that either did not wait for the main thread f rame or had one committed. 128 // - only show frames that either did not wait for the main thread f rame or had one committed.
129 if (this._mainFrameCommitted || !this._mainFrameRequested) 129 if (this._mainFrameCommitted || !this._mainFrameRequested)
130 this._startBackgroundFrame(record); 130 this._startBackgroundFrame(record);
131 this._mainFrameCommitted = false; 131 this._mainFrameCommitted = false;
132 } else if (record.type === recordTypes.RequestMainThreadFrame) { 132 } else if (record.type === recordTypes.RequestMainThreadFrame) {
133 this._mainFrameRequested = true; 133 this._mainFrameRequested = true;
134 } else if (record.type === recordTypes.ActivateLayerTree) { 134 } else if (record.type === recordTypes.ActivateLayerTree) {
135 this._mainFrameRequested = false; 135 this._mainFrameRequested = false;
136 this._mainFrameCommitted = true; 136 this._mainFrameCommitted = true;
137 this._lastFrame._addTimeForCategories(this._aggregatedMainThreadWork ToAttachToBackgroundFrame); 137 this._lastFrame._addTimeForCategories(this._aggregatedMainThreadWork ToAttachToBackgroundFrame);
138 this._aggregatedMainThreadWorkToAttachToBackgroundFrame = {}; 138 this._aggregatedMainThreadWorkToAttachToBackgroundFrame = {};
139 } 139 }
140 this._lastFrame._addTimeFromRecord(record); 140 this._lastFrame._addTimeFromRecord(record);
141 }, 141 },
142 142
143 /** 143 /**
144 * @param {?TimelineAgent.TimelineEvent} programRecord 144 * @param {?WebInspector.TimelineModel.Record} programRecord
145 * @param {!TimelineAgent.TimelineEvent} record 145 * @param {!WebInspector.TimelineModel.Record} record
146 */ 146 */
147 _addMainThreadRecord: function(programRecord, record) 147 _addMainThreadRecord: function(programRecord, record)
148 { 148 {
149 var recordTypes = WebInspector.TimelineModel.RecordType; 149 var recordTypes = WebInspector.TimelineModel.RecordType;
150 if (!this._hasThreadedCompositing) { 150 if (!this._hasThreadedCompositing) {
151 if (record.type === recordTypes.BeginFrame) 151 if (record.type === recordTypes.BeginFrame)
152 this._startMainThreadFrame(record); 152 this._startMainThreadFrame(record);
153 153
154 if (!this._lastFrame) 154 if (!this._lastFrame)
155 return; 155 return;
(...skipping 15 matching lines...) Expand all
171 if (programRecord.children[0] === record) 171 if (programRecord.children[0] === record)
172 this._deriveOtherTime(programRecord, this._aggregatedMainThreadWork) ; 172 this._deriveOtherTime(programRecord, this._aggregatedMainThreadWork) ;
173 173
174 if (record.type === recordTypes.CompositeLayers) { 174 if (record.type === recordTypes.CompositeLayers) {
175 this._aggregatedMainThreadWorkToAttachToBackgroundFrame = this._aggr egatedMainThreadWork; 175 this._aggregatedMainThreadWorkToAttachToBackgroundFrame = this._aggr egatedMainThreadWork;
176 this._aggregatedMainThreadWork = null; 176 this._aggregatedMainThreadWork = null;
177 } 177 }
178 }, 178 },
179 179
180 /** 180 /**
181 * @param {!TimelineAgent.TimelineEvent} programRecord 181 * @param {!WebInspector.TimelineModel.Record} programRecord
182 * @param {!Object} timeByCategory 182 * @param {!Object} timeByCategory
183 */ 183 */
184 _deriveOtherTime: function(programRecord, timeByCategory) 184 _deriveOtherTime: function(programRecord, timeByCategory)
185 { 185 {
186 var accounted = 0; 186 var accounted = 0;
187 for (var i = 0; i < programRecord.children.length; ++i) 187 for (var i = 0; i < programRecord.children.length; ++i)
188 accounted += programRecord.children[i].endTime - programRecord.child ren[i].startTime; 188 accounted += programRecord.children[i].endTime - programRecord.child ren[i].startTime;
189 var otherTime = programRecord.endTime - programRecord.startTime - accoun ted; 189 var otherTime = programRecord.endTime - programRecord.startTime - accoun ted;
190 timeByCategory["other"] = (timeByCategory["other"] || 0) + otherTime; 190 timeByCategory["other"] = (timeByCategory["other"] || 0) + otherTime;
191 }, 191 },
192 192
193 /** 193 /**
194 * @param {!TimelineAgent.TimelineEvent} record 194 * @param {!WebInspector.TimelineModel.Record} record
195 */ 195 */
196 _startBackgroundFrame: function(record) 196 _startBackgroundFrame: function(record)
197 { 197 {
198 if (!this._hasThreadedCompositing) { 198 if (!this._hasThreadedCompositing) {
199 this._lastFrame = null; 199 this._lastFrame = null;
200 this._hasThreadedCompositing = true; 200 this._hasThreadedCompositing = true;
201 } 201 }
202 if (this._lastFrame) 202 if (this._lastFrame)
203 this._flushFrame(this._lastFrame, record); 203 this._flushFrame(this._lastFrame, record);
204 204
205 this._lastFrame = new WebInspector.TimelineFrame(this, record); 205 this._lastFrame = new WebInspector.TimelineFrame(this, record);
206 }, 206 },
207 207
208 /** 208 /**
209 * @param {!TimelineAgent.TimelineEvent} record 209 * @param {!WebInspector.TimelineModel.Record} record
210 */ 210 */
211 _startMainThreadFrame: function(record) 211 _startMainThreadFrame: function(record)
212 { 212 {
213 if (this._lastFrame) 213 if (this._lastFrame)
214 this._flushFrame(this._lastFrame, record); 214 this._flushFrame(this._lastFrame, record);
215 this._lastFrame = new WebInspector.TimelineFrame(this, record); 215 this._lastFrame = new WebInspector.TimelineFrame(this, record);
216 }, 216 },
217 217
218 /** 218 /**
219 * @param {!WebInspector.TimelineFrame} frame 219 * @param {!WebInspector.TimelineFrame} frame
220 * @param {!Object} record 220 * @param {!Object} record
221 */ 221 */
222 _flushFrame: function(frame, record) 222 _flushFrame: function(frame, record)
223 { 223 {
224 frame._setEndTime(record.startTime); 224 frame._setEndTime(record.startTime);
225 this._frames.push(frame); 225 this._frames.push(frame);
226 this.dispatchEventToListeners(WebInspector.TimelineFrameModel.Events.Fra meAdded, frame); 226 this.dispatchEventToListeners(WebInspector.TimelineFrameModel.Events.Fra meAdded, frame);
227 }, 227 },
228 228
229 /** 229 /**
230 * @param {!Array.<string>} types 230 * @param {!Array.<string>} types
231 * @param {!TimelineAgent.TimelineEvent} record 231 * @param {!WebInspector.TimelineModel.Record} record
232 * @return {?TimelineAgent.TimelineEvent} record 232 * @return {?WebInspector.TimelineModel.Record} record
233 */ 233 */
234 _findRecordRecursively: function(types, record) 234 _findRecordRecursively: function(types, record)
235 { 235 {
236 if (types.indexOf(record.type) >= 0) 236 if (types.indexOf(record.type) >= 0)
237 return record; 237 return record;
238 if (!record.children) 238 if (!record.children)
239 return null; 239 return null;
240 for (var i = 0; i < record.children.length; ++i) { 240 for (var i = 0; i < record.children.length; ++i) {
241 var result = this._findRecordRecursively(types, record.children[i]); 241 var result = this._findRecordRecursively(types, record.children[i]);
242 if (result) 242 if (result)
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 /** 296 /**
297 * @param {number} endTime 297 * @param {number} endTime
298 */ 298 */
299 _setEndTime: function(endTime) 299 _setEndTime: function(endTime)
300 { 300 {
301 this.endTime = endTime; 301 this.endTime = endTime;
302 this.duration = this.endTime - this.startTime; 302 this.duration = this.endTime - this.startTime;
303 }, 303 },
304 304
305 /** 305 /**
306 * @param {!TimelineAgent.TimelineEvent} record 306 * @param {!WebInspector.TimelineModel.Record} record
307 */ 307 */
308 _addTimeFromRecord: function(record) 308 _addTimeFromRecord: function(record)
309 { 309 {
310 if (!record.endTime) 310 if (!record.endTime)
311 return; 311 return;
312 WebInspector.TimelineUIUtils.aggregateTimeForRecord(this.timeByCategory, record); 312 WebInspector.TimelineUIUtils.aggregateTimeForRecord(this.timeByCategory, record);
313 this._updateCpuTime(); 313 this._updateCpuTime();
314 }, 314 },
315 315
316 /** 316 /**
317 * @param {!Object} timeByCategory 317 * @param {!Object} timeByCategory
318 */ 318 */
319 _addTimeForCategories: function(timeByCategory) 319 _addTimeForCategories: function(timeByCategory)
320 { 320 {
321 WebInspector.TimelineUIUtils.aggregateTimeByCategory(this.timeByCategory , timeByCategory); 321 WebInspector.TimelineUIUtils.aggregateTimeByCategory(this.timeByCategory , timeByCategory);
322 this._updateCpuTime(); 322 this._updateCpuTime();
323 }, 323 },
324 324
325 _updateCpuTime: function() 325 _updateCpuTime: function()
326 { 326 {
327 this.cpuTime = 0; 327 this.cpuTime = 0;
328 for (var key in this.timeByCategory) 328 for (var key in this.timeByCategory)
329 this.cpuTime += this.timeByCategory[key]; 329 this.cpuTime += this.timeByCategory[key];
330 } 330 }
331 } 331 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698