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

Side by Side Diff: Source/devtools/front_end/timeline/TimelinePresentationModel.js

Issue 337023004: Don't create TimelineModel.RecordImpl in TimelinePresentationModel.js (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Addressed comments Created 6 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 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * Copyright (C) 2012 Intel Inc. All rights reserved. 3 * Copyright (C) 2012 Intel Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 * @return {!WebInspector.TimelinePresentationModel.Record} 76 * @return {!WebInspector.TimelinePresentationModel.Record}
77 */ 77 */
78 rootRecord: function() 78 rootRecord: function()
79 { 79 {
80 return this._rootRecord; 80 return this._rootRecord;
81 }, 81 },
82 82
83 reset: function() 83 reset: function()
84 { 84 {
85 this._recordToPresentationRecord.clear(); 85 this._recordToPresentationRecord.clear();
86 var rootPayload = { type: WebInspector.TimelineModel.RecordType.Root }; 86 this._rootRecord = new WebInspector.TimelinePresentationModel.RootRecord ();
87 var rootRecord = new WebInspector.TimelineModel.RecordImpl(this._model, /** @type {!TimelineAgent.TimelineEvent} */ (rootPayload), null);
88 this._rootRecord = new WebInspector.TimelinePresentationModel.Record(roo tRecord, null);
89 /** @type {!Object.<string, !WebInspector.TimelinePresentationModel.Reco rd>} */ 87 /** @type {!Object.<string, !WebInspector.TimelinePresentationModel.Reco rd>} */
90 this._coalescingBuckets = {}; 88 this._coalescingBuckets = {};
91 }, 89 },
92 90
93 /** 91 /**
94 * @param {!WebInspector.TimelineModel.Record} record 92 * @param {!WebInspector.TimelineModel.Record} record
95 */ 93 */
96 addRecord: function(record) 94 addRecord: function(record)
97 { 95 {
98 var records; 96 var records;
(...skipping 14 matching lines...) Expand all
113 { 111 {
114 var coalescingBucket; 112 var coalescingBucket;
115 113
116 // On main thread, only coalesce if the last event is of same type. 114 // On main thread, only coalesce if the last event is of same type.
117 if (parentRecord === this._rootRecord) 115 if (parentRecord === this._rootRecord)
118 coalescingBucket = record.thread() ? record.type() : "mainThread"; 116 coalescingBucket = record.thread() ? record.type() : "mainThread";
119 var coalescedRecord = this._findCoalescedParent(record, parentRecord, co alescingBucket); 117 var coalescedRecord = this._findCoalescedParent(record, parentRecord, co alescingBucket);
120 if (coalescedRecord) 118 if (coalescedRecord)
121 parentRecord = coalescedRecord; 119 parentRecord = coalescedRecord;
122 120
123 var formattedRecord = new WebInspector.TimelinePresentationModel.Record( record, parentRecord); 121 var formattedRecord = new WebInspector.TimelinePresentationModel.ActualR ecord(record, parentRecord);
124 this._recordToPresentationRecord.put(record, formattedRecord); 122 this._recordToPresentationRecord.put(record, formattedRecord);
125 123
126 formattedRecord._collapsed = parentRecord === this._rootRecord; 124 formattedRecord._collapsed = parentRecord === this._rootRecord;
127 if (coalescingBucket) 125 if (coalescingBucket)
128 this._coalescingBuckets[coalescingBucket] = formattedRecord; 126 this._coalescingBuckets[coalescingBucket] = formattedRecord;
129 127
130 for (var i = 0; record.children() && i < record.children().length; ++i) 128 for (var i = 0; record.children() && i < record.children().length; ++i)
131 this._innerAddRecord(formattedRecord, record.children()[i]); 129 this._innerAddRecord(formattedRecord, record.children()[i]);
132 130
133 if (parentRecord._coalesced) 131 if (parentRecord.coalesced())
134 this._updateCoalescingParent(formattedRecord); 132 this._updateCoalescingParent(formattedRecord);
135 }, 133 },
136 134
137 /** 135 /**
138 * @param {!WebInspector.TimelineModel.Record} record 136 * @param {!WebInspector.TimelineModel.Record} record
139 * @param {!WebInspector.TimelinePresentationModel.Record} newParent 137 * @param {!WebInspector.TimelinePresentationModel.Record} newParent
140 * @param {string=} bucket 138 * @param {string=} bucket
141 * @return {?WebInspector.TimelinePresentationModel.Record} 139 * @return {?WebInspector.TimelinePresentationModel.Record}
142 */ 140 */
143 _findCoalescedParent: function(record, newParent, bucket) 141 _findCoalescedParent: function(record, newParent, bucket)
144 { 142 {
145 const coalescingThresholdMillis = 5; 143 const coalescingThresholdMillis = 5;
146 144
147 var lastRecord = bucket ? this._coalescingBuckets[bucket] : newParent._p resentationChildren.peekLast(); 145 var lastRecord = bucket ? this._coalescingBuckets[bucket] : newParent._p resentationChildren.peekLast();
148 if (lastRecord && lastRecord._coalesced) 146 if (lastRecord && lastRecord.coalesced())
149 lastRecord = lastRecord._presentationChildren.peekLast(); 147 lastRecord = lastRecord._presentationChildren.peekLast();
150 var startTime = record.startTime(); 148 var startTime = record.startTime();
151 var endTime = record.endTime(); 149 var endTime = record.endTime();
152 if (!lastRecord) 150 if (!lastRecord)
153 return null; 151 return null;
154 if (lastRecord.record().type() !== record.type()) 152 if (lastRecord.record().type() !== record.type())
155 return null; 153 return null;
156 if (!WebInspector.TimelinePresentationModel._coalescingRecords[record.ty pe()]) 154 if (!WebInspector.TimelinePresentationModel._coalescingRecords[record.ty pe()])
157 return null; 155 return null;
158 if (lastRecord.record().endTime() + coalescingThresholdMillis < startTim e) 156 if (lastRecord.record().endTime() + coalescingThresholdMillis < startTim e)
159 return null; 157 return null;
160 if (endTime + coalescingThresholdMillis < lastRecord.record().startTime( )) 158 if (endTime + coalescingThresholdMillis < lastRecord.record().startTime( ))
161 return null; 159 return null;
162 if (lastRecord.presentationParent()._coalesced) 160 if (lastRecord.presentationParent().coalesced())
163 return lastRecord.presentationParent(); 161 return lastRecord.presentationParent();
164 return this._replaceWithCoalescedRecord(lastRecord); 162 return this._replaceWithCoalescedRecord(lastRecord);
165 }, 163 },
166 164
167 /** 165 /**
168 * @param {!WebInspector.TimelinePresentationModel.Record} presentationRecor d 166 * @param {!WebInspector.TimelinePresentationModel.Record} presentationRecor d
169 * @return {!WebInspector.TimelinePresentationModel.Record} 167 * @return {!WebInspector.TimelinePresentationModel.Record}
170 */ 168 */
171 _replaceWithCoalescedRecord: function(presentationRecord) 169 _replaceWithCoalescedRecord: function(presentationRecord)
172 { 170 {
173 var record = presentationRecord.record(); 171 var record = presentationRecord.record();
174 var rawRecord = { 172 var parent = presentationRecord._presentationParent;
175 type: record.type(), 173 var coalescedRecord = new WebInspector.TimelinePresentationModel.Coalesc edRecord(record);
176 startTime: record.startTime(),
177 data: { }
178 };
179 if (record.thread())
180 rawRecord.thread = "aggregated";
181 if (record.type() === WebInspector.TimelineModel.RecordType.TimeStamp)
182 rawRecord.data["message"] = record.data().message;
183 174
184 var modelRecord = new WebInspector.TimelineModel.RecordImpl(this._model, /** @type {!TimelineAgent.TimelineEvent} */ (rawRecord), null);
185 var coalescedRecord = new WebInspector.TimelinePresentationModel.Record( modelRecord, null);
186 var parent = presentationRecord._presentationParent;
187
188 coalescedRecord._coalesced = true;
189 coalescedRecord._collapsed = true; 175 coalescedRecord._collapsed = true;
190 coalescedRecord._presentationChildren.push(presentationRecord); 176 coalescedRecord._presentationChildren.push(presentationRecord);
191 presentationRecord._presentationParent = coalescedRecord; 177 presentationRecord._presentationParent = coalescedRecord;
192 if (presentationRecord.hasWarnings() || presentationRecord.childHasWarni ngs()) 178 if (presentationRecord.hasWarnings() || presentationRecord.childHasWarni ngs())
193 coalescedRecord._childHasWarnings = true; 179 coalescedRecord._childHasWarnings = true;
194 180
195 coalescedRecord._presentationParent = parent; 181 coalescedRecord._presentationParent = parent;
196 parent._presentationChildren[parent._presentationChildren.indexOf(presen tationRecord)] = coalescedRecord; 182 parent._presentationChildren[parent._presentationChildren.indexOf(presen tationRecord)] = coalescedRecord;
197 WebInspector.TimelineUIUtils.aggregateTimeByCategory(modelRecord.aggrega tedStats(), record.aggregatedStats()); 183 WebInspector.TimelineUIUtils.aggregateTimeByCategory(coalescedRecord.pre sentationAggregatedStats(), presentationRecord.presentationAggregatedStats());
198 184
199 return coalescedRecord; 185 return coalescedRecord;
200 }, 186 },
201 187
202 /** 188 /**
203 * @param {!WebInspector.TimelinePresentationModel.Record} presentationRecor d 189 * @param {!WebInspector.TimelinePresentationModel.Record} presentationRecor d
204 */ 190 */
205 _updateCoalescingParent: function(presentationRecord) 191 _updateCoalescingParent: function(presentationRecord)
206 { 192 {
207 var record = presentationRecord.record(); 193 var parentRecord = presentationRecord._presentationParent;
208 var parentRecord = presentationRecord._presentationParent.record(); 194 WebInspector.TimelineUIUtils.aggregateTimeByCategory(parentRecord.presen tationAggregatedStats(), presentationRecord.presentationAggregatedStats());
209 WebInspector.TimelineUIUtils.aggregateTimeByCategory(parentRecord.aggreg atedStats(), record.aggregatedStats()); 195 if (parentRecord.endTime() < presentationRecord.endTime())
210 if (parentRecord.endTime() < record.endTime()) 196 parentRecord._endTime = presentationRecord.endTime();
211 parentRecord.setEndTime(record.endTime());
212 }, 197 },
213 198
214 /** 199 /**
215 * @param {?RegExp} textFilter 200 * @param {?RegExp} textFilter
216 */ 201 */
217 setTextFilter: function(textFilter) 202 setTextFilter: function(textFilter)
218 { 203 {
219 this._textFilter = textFilter; 204 this._textFilter = textFilter;
220 }, 205 },
221 206
(...skipping 28 matching lines...) Expand all
250 revealedDepth = depth; 235 revealedDepth = depth;
251 } 236 }
252 } 237 }
253 238
254 while (stack.length) { 239 while (stack.length) {
255 var entry = stack[stack.length - 1]; 240 var entry = stack[stack.length - 1];
256 var records = entry.children; 241 var records = entry.children;
257 if (records && entry.index < records.length) { 242 if (records && entry.index < records.length) {
258 var record = records[entry.index]; 243 var record = records[entry.index];
259 ++entry.index; 244 ++entry.index;
260 var rawRecord = record.record(); 245 if (record.startTime() < this._windowEndTime && record.endTime() > this._windowStartTime) {
261 if (rawRecord.startTime() < this._windowEndTime && rawRecord.end Time() > this._windowStartTime) { 246 if (this._model.isVisible(record.record())) {
262 if (this._model.isVisible(rawRecord)) {
263 record._presentationParent._expandable = true; 247 record._presentationParent._expandable = true;
264 if (this._textFilter) 248 if (this._textFilter)
265 revealRecordsInStack(); 249 revealRecordsInStack();
266 if (!entry.parentIsCollapsed) { 250 if (!entry.parentIsCollapsed) {
267 recordsInWindow.push(record); 251 recordsInWindow.push(record);
268 revealedDepth = stack.length; 252 revealedDepth = stack.length;
269 entry.parentRecord._collapsed = false; 253 entry.parentRecord._collapsed = false;
270 } 254 }
271 } 255 }
272 } 256 }
(...skipping 14 matching lines...) Expand all
287 271
288 this._filteredRecords = recordsInWindow; 272 this._filteredRecords = recordsInWindow;
289 return recordsInWindow; 273 return recordsInWindow;
290 }, 274 },
291 275
292 __proto__: WebInspector.Object.prototype 276 __proto__: WebInspector.Object.prototype
293 } 277 }
294 278
295 /** 279 /**
296 * @constructor 280 * @constructor
297 * @param {!WebInspector.TimelineModel.Record} record
298 * @param {?WebInspector.TimelinePresentationModel.Record} parentRecord 281 * @param {?WebInspector.TimelinePresentationModel.Record} parentRecord
299 */ 282 */
300 WebInspector.TimelinePresentationModel.Record = function(record, parentRecord) 283 WebInspector.TimelinePresentationModel.Record = function(parentRecord)
301 { 284 {
302 this._record = record;
303 /** 285 /**
304 * @type {!Array.<!WebInspector.TimelinePresentationModel.Record>} 286 * @type {!Array.<!WebInspector.TimelinePresentationModel.Record>}
305 */ 287 */
306 this._presentationChildren = []; 288 this._presentationChildren = [];
307 289
308 if (parentRecord) { 290 if (parentRecord) {
309 this._presentationParent = parentRecord; 291 this._presentationParent = parentRecord;
310 parentRecord._presentationChildren.push(this); 292 parentRecord._presentationChildren.push(this);
311 } 293 }
312
313 if (this.hasWarnings()) {
314 for (var parent = this._presentationParent; parent && !parent._childHasW arnings; parent = parent._presentationParent)
315 parent._childHasWarnings = true;
316 }
317 } 294 }
318 295
319 WebInspector.TimelinePresentationModel.Record.prototype = { 296 WebInspector.TimelinePresentationModel.Record.prototype = {
320 /** 297 /**
298 * @return {number}
299 */
300 startTime: function()
301 {
302 throw new Error("Not implemented.");
303 },
304
305 /**
306 * @return {number}
307 */
308 endTime: function()
309 {
310 throw new Error("Not implemented.");
311 },
312
313 /**
314 * @return {number}
315 */
316 selfTime: function()
317 {
318 throw new Error("Not implemented.");
319 },
320
321 /**
321 * @return {!WebInspector.TimelineModel.Record} 322 * @return {!WebInspector.TimelineModel.Record}
322 */ 323 */
323 record: function() 324 record: function()
324 { 325 {
325 return this._record; 326 throw new Error("Not implemented.");
326 }, 327 },
327 328
328 /** 329 /**
330 * @return {!Object.<string, number>}
331 */
332 presentationAggregatedStats: function()
333 {
334 throw new Error("Not implemented.");
335 },
336
337 /**
329 * @return {!Array.<!WebInspector.TimelinePresentationModel.Record>} 338 * @return {!Array.<!WebInspector.TimelinePresentationModel.Record>}
330 */ 339 */
331 presentationChildren: function() 340 presentationChildren: function()
332 { 341 {
333 return this._presentationChildren; 342 return this._presentationChildren;
334 }, 343 },
335 344
336 /** 345 /**
337 * @return {boolean} 346 * @return {boolean}
338 */ 347 */
339 coalesced: function() 348 coalesced: function()
340 { 349 {
341 return this._coalesced; 350 return false;
342 }, 351 },
343 352
344 /** 353 /**
345 * @return {boolean} 354 * @return {boolean}
346 */ 355 */
347 collapsed: function() 356 collapsed: function()
348 { 357 {
349 return this._collapsed; 358 return this._collapsed;
350 }, 359 },
351 360
(...skipping 28 matching lines...) Expand all
380 expandable: function() 389 expandable: function()
381 { 390 {
382 return !!this._expandable; 391 return !!this._expandable;
383 }, 392 },
384 393
385 /** 394 /**
386 * @return {boolean} 395 * @return {boolean}
387 */ 396 */
388 hasWarnings: function() 397 hasWarnings: function()
389 { 398 {
390 return !!this._record.warnings(); 399 return false;
391 }, 400 },
392 401
393 /** 402 /**
394 * @return {boolean} 403 * @return {boolean}
395 */ 404 */
396 childHasWarnings: function() 405 childHasWarnings: function()
397 { 406 {
398 return this._childHasWarnings; 407 return this._childHasWarnings;
399 }, 408 },
400 409
(...skipping 22 matching lines...) Expand all
423 }, 432 },
424 433
425 /** 434 /**
426 * @param {!WebInspector.TimelineRecordGraphRow} graphRow 435 * @param {!WebInspector.TimelineRecordGraphRow} graphRow
427 */ 436 */
428 setGraphRow: function(graphRow) 437 setGraphRow: function(graphRow)
429 { 438 {
430 this._graphRow = graphRow; 439 this._graphRow = graphRow;
431 } 440 }
432 } 441 }
442
443 /**
444 * @constructor
445 * @extends {WebInspector.TimelinePresentationModel.Record}
446 * @param {!WebInspector.TimelineModel.Record} record
447 * @param {?WebInspector.TimelinePresentationModel.Record} parentRecord
448 */
449 WebInspector.TimelinePresentationModel.ActualRecord = function(record, parentRec ord)
450 {
451 WebInspector.TimelinePresentationModel.Record.call(this, parentRecord);
452 this._record = record;
453
454 if (this.hasWarnings()) {
455 for (var parent = this._presentationParent; parent && !parent._childHasW arnings; parent = parent._presentationParent)
456 parent._childHasWarnings = true;
457 }
458 }
459
460 WebInspector.TimelinePresentationModel.ActualRecord.prototype = {
461 /**
462 * @return {number}
463 */
464 startTime: function()
465 {
466 return this._record.startTime();
467 },
468
469 /**
470 * @return {number}
471 */
472 endTime: function()
473 {
474 return this._record.endTime();
475 },
476
477 /**
478 * @return {number}
479 */
480 selfTime: function()
481 {
482 return this._record.selfTime();
483 },
484
485 /**
486 * @return {!WebInspector.TimelineModel.Record}
487 */
488 record: function()
489 {
490 return this._record;
491 },
492
493 /**
494 * @return {!Object.<string, number>}
495 */
496 presentationAggregatedStats: function()
497 {
498 return this._record.aggregatedStats();
499 },
500
501 /**
502 * @return {boolean}
503 */
504 hasWarnings: function()
505 {
506 return !!this._record.warnings();
507 },
508
509 __proto__: WebInspector.TimelinePresentationModel.Record.prototype
510 }
511
512 /**
513 * @constructor
514 * @extends {WebInspector.TimelinePresentationModel.Record}
515 * @param {!WebInspector.TimelineModel.Record} record
516 */
517 WebInspector.TimelinePresentationModel.CoalescedRecord = function(record)
518 {
519 WebInspector.TimelinePresentationModel.Record.call(this, null);
520 this._startTime = record.startTime();
521 this._endTime = record.endTime();
522 this._aggregatedStats = {};
523 }
524
525 WebInspector.TimelinePresentationModel.CoalescedRecord.prototype = {
526 /**
527 * @return {number}
528 */
529 startTime: function()
530 {
531 return this._startTime;
532 },
533
534 /**
535 * @return {number}
536 */
537 endTime: function()
538 {
539 return this._endTime;
540 },
541
542 /**
543 * @return {number}
544 */
545 selfTime: function()
546 {
547 return 0;
548 },
549
550 /**
551 * @return {!WebInspector.TimelineModel.Record}
552 */
553 record: function()
554 {
555 return this._presentationChildren[0].record();
556 },
557
558 /**
559 * @return {!Object.<string, number>}
560 */
561 presentationAggregatedStats: function()
562 {
563 return this._aggregatedStats;
564 },
565
566 /**
567 * @return {boolean}
568 */
569 coalesced: function()
570 {
571 return true;
572 },
573
574 /**
575 * @return {boolean}
576 */
577 hasWarnings: function()
578 {
579 return false;
580 },
581
582 __proto__: WebInspector.TimelinePresentationModel.Record.prototype
583 }
584
585 /**
586 * @constructor
587 * @extends {WebInspector.TimelinePresentationModel.Record}
588 */
589 WebInspector.TimelinePresentationModel.RootRecord = function()
590 {
591 WebInspector.TimelinePresentationModel.Record.call(this, null);
592 this._aggregatedStats = {};
593 }
594
595 WebInspector.TimelinePresentationModel.RootRecord.prototype = {
596 /**
597 * @return {!Object.<string, number>}
598 */
599 presentationAggregatedStats: function()
600 {
601 return this._aggregatedStats;
602 },
603
604 /**
605 * @return {boolean}
606 */
607 hasWarnings: function()
608 {
609 return false;
610 },
611
612 __proto__: WebInspector.TimelinePresentationModel.Record.prototype
613 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/timeline/TimelineModelImpl.js ('k') | Source/devtools/front_end/timeline/TimelineView.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698