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

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: 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 record = presentationRecord;
caseq 2014/06/16 12:26:33 nit: remove this and inline presentationRecord in
yurys 2014/06/16 12:32:37 Done.
208 var parentRecord = presentationRecord._presentationParent.record(); 194 var parentRecord = presentationRecord._presentationParent;
209 WebInspector.TimelineUIUtils.aggregateTimeByCategory(parentRecord.aggreg atedStats(), record.aggregatedStats()); 195 WebInspector.TimelineUIUtils.aggregateTimeByCategory(parentRecord.presen tationAggregatedStats(), record.presentationAggregatedStats());
210 if (parentRecord.endTime() < record.endTime()) 196 if (parentRecord.endTime() < record.endTime())
211 parentRecord.setEndTime(record.endTime()); 197 parentRecord._endTime = record.endTime();
212 }, 198 },
213 199
214 /** 200 /**
215 * @param {?RegExp} textFilter 201 * @param {?RegExp} textFilter
216 */ 202 */
217 setTextFilter: function(textFilter) 203 setTextFilter: function(textFilter)
218 { 204 {
219 this._textFilter = textFilter; 205 this._textFilter = textFilter;
220 }, 206 },
221 207
(...skipping 28 matching lines...) Expand all
250 revealedDepth = depth; 236 revealedDepth = depth;
251 } 237 }
252 } 238 }
253 239
254 while (stack.length) { 240 while (stack.length) {
255 var entry = stack[stack.length - 1]; 241 var entry = stack[stack.length - 1];
256 var records = entry.children; 242 var records = entry.children;
257 if (records && entry.index < records.length) { 243 if (records && entry.index < records.length) {
258 var record = records[entry.index]; 244 var record = records[entry.index];
259 ++entry.index; 245 ++entry.index;
260 var rawRecord = record.record(); 246 if (record.startTime() < this._windowEndTime && record.endTime() > this._windowStartTime) {
261 if (rawRecord.startTime() < this._windowEndTime && rawRecord.end Time() > this._windowStartTime) { 247 if (this._model.isVisible(record.record())) {
262 if (this._model.isVisible(rawRecord)) {
263 record._presentationParent._expandable = true; 248 record._presentationParent._expandable = true;
264 if (this._textFilter) 249 if (this._textFilter)
265 revealRecordsInStack(); 250 revealRecordsInStack();
266 if (!entry.parentIsCollapsed) { 251 if (!entry.parentIsCollapsed) {
267 recordsInWindow.push(record); 252 recordsInWindow.push(record);
268 revealedDepth = stack.length; 253 revealedDepth = stack.length;
269 entry.parentRecord._collapsed = false; 254 entry.parentRecord._collapsed = false;
270 } 255 }
271 } 256 }
272 } 257 }
(...skipping 14 matching lines...) Expand all
287 272
288 this._filteredRecords = recordsInWindow; 273 this._filteredRecords = recordsInWindow;
289 return recordsInWindow; 274 return recordsInWindow;
290 }, 275 },
291 276
292 __proto__: WebInspector.Object.prototype 277 __proto__: WebInspector.Object.prototype
293 } 278 }
294 279
295 /** 280 /**
296 * @constructor 281 * @constructor
297 * @param {!WebInspector.TimelineModel.Record} record
298 * @param {?WebInspector.TimelinePresentationModel.Record} parentRecord 282 * @param {?WebInspector.TimelinePresentationModel.Record} parentRecord
299 */ 283 */
300 WebInspector.TimelinePresentationModel.Record = function(record, parentRecord) 284 WebInspector.TimelinePresentationModel.Record = function(parentRecord)
301 { 285 {
302 this._record = record;
303 /** 286 /**
304 * @type {!Array.<!WebInspector.TimelinePresentationModel.Record>} 287 * @type {!Array.<!WebInspector.TimelinePresentationModel.Record>}
305 */ 288 */
306 this._presentationChildren = []; 289 this._presentationChildren = [];
307 290
308 if (parentRecord) { 291 if (parentRecord) {
309 this._presentationParent = parentRecord; 292 this._presentationParent = parentRecord;
310 parentRecord._presentationChildren.push(this); 293 parentRecord._presentationChildren.push(this);
311 } 294 }
312
313 if (this.hasWarnings()) {
314 for (var parent = this._presentationParent; parent && !parent._childHasW arnings; parent = parent._presentationParent)
315 parent._childHasWarnings = true;
316 }
317 } 295 }
318 296
319 WebInspector.TimelinePresentationModel.Record.prototype = { 297 WebInspector.TimelinePresentationModel.Record.prototype = {
320 /** 298 /**
299 * @return {number}
300 */
301 startTime: function()
302 {
303 throw new Error("Not implemented.");
304 },
305
306 /**
307 * @return {number}
308 */
309 endTime: function()
310 {
311 throw new Error("Not implemented.");
312 },
313
314 /**
315 * @return {number}
316 */
317 selfTime: function()
318 {
319 throw new Error("Not implemented.");
320 },
321
322 /**
321 * @return {!WebInspector.TimelineModel.Record} 323 * @return {!WebInspector.TimelineModel.Record}
322 */ 324 */
323 record: function() 325 record: function()
324 { 326 {
325 return this._record; 327 throw new Error("Not implemented.");
326 }, 328 },
327 329
328 /** 330 /**
331 * @return {!Object.<string, number>}
332 */
333 presentationAggregatedStats: function()
334 {
335 throw new Error("Not implemented.");
336 },
337
338 /**
329 * @return {!Array.<!WebInspector.TimelinePresentationModel.Record>} 339 * @return {!Array.<!WebInspector.TimelinePresentationModel.Record>}
330 */ 340 */
331 presentationChildren: function() 341 presentationChildren: function()
332 { 342 {
333 return this._presentationChildren; 343 return this._presentationChildren;
334 }, 344 },
335 345
336 /** 346 /**
337 * @return {boolean} 347 * @return {boolean}
338 */ 348 */
339 coalesced: function() 349 coalesced: function()
340 { 350 {
341 return this._coalesced; 351 return false;
342 }, 352 },
343 353
344 /** 354 /**
345 * @return {boolean} 355 * @return {boolean}
346 */ 356 */
347 collapsed: function() 357 collapsed: function()
348 { 358 {
349 return this._collapsed; 359 return this._collapsed;
350 }, 360 },
351 361
(...skipping 28 matching lines...) Expand all
380 expandable: function() 390 expandable: function()
381 { 391 {
382 return !!this._expandable; 392 return !!this._expandable;
383 }, 393 },
384 394
385 /** 395 /**
386 * @return {boolean} 396 * @return {boolean}
387 */ 397 */
388 hasWarnings: function() 398 hasWarnings: function()
389 { 399 {
390 return !!this._record.warnings(); 400 return false;
391 }, 401 },
392 402
393 /** 403 /**
394 * @return {boolean} 404 * @return {boolean}
395 */ 405 */
396 childHasWarnings: function() 406 childHasWarnings: function()
397 { 407 {
398 return this._childHasWarnings; 408 return this._childHasWarnings;
399 }, 409 },
400 410
(...skipping 20 matching lines...) Expand all
421 { 431 {
422 return this._graphRow; 432 return this._graphRow;
423 }, 433 },
424 434
425 /** 435 /**
426 * @param {!WebInspector.TimelineRecordGraphRow} graphRow 436 * @param {!WebInspector.TimelineRecordGraphRow} graphRow
427 */ 437 */
428 setGraphRow: function(graphRow) 438 setGraphRow: function(graphRow)
429 { 439 {
430 this._graphRow = graphRow; 440 this._graphRow = graphRow;
441 },
442
443 /**
444 * @return {string}
445 */
446 toString: function()
447 {
448 return "Record";
449 },
450
451 /**
452 * @param {string} prefix
453 * @return {string}
454 */
455 dump: function(prefix)
caseq 2014/06/16 12:26:33 How is this used?
yurys 2014/06/16 12:32:37 I used it for debugging. Removed.
456 {
457 prefix = prefix || " ";
458 var result = prefix + this.toString();
459 result += "\n";
460 prefix += " ";
461 for (var i = 0; i < this.presentationChildren().length; i++) {
462 result += this.presentationChildren()[i].dump(prefix);
463 }
464 return result;
431 } 465 }
432 } 466 }
467
468 /**
469 * @constructor
470 * @extends {WebInspector.TimelinePresentationModel.Record}
471 * @param {!WebInspector.TimelineModel.Record} record
472 * @param {?WebInspector.TimelinePresentationModel.Record} parentRecord
473 */
474 WebInspector.TimelinePresentationModel.ActualRecord = function(record, parentRec ord)
475 {
476 WebInspector.TimelinePresentationModel.Record.call(this, parentRecord);
477 this._record = record;
478
479 if (this.hasWarnings()) {
480 for (var parent = this._presentationParent; parent && !parent._childHasW arnings; parent = parent._presentationParent)
481 parent._childHasWarnings = true;
482 }
483 }
484
485 WebInspector.TimelinePresentationModel.ActualRecord.prototype = {
486 /**
487 * @return {number}
488 */
489 startTime: function()
490 {
491 return this._record.startTime();
492 },
493
494 /**
495 * @return {number}
496 */
497 endTime: function()
498 {
499 return this._record.endTime();
500 },
501
502 /**
503 * @return {number}
504 */
505 selfTime: function()
506 {
507 return this._record.selfTime();
508 },
509
510 /**
511 * @return {!WebInspector.TimelineModel.Record}
512 */
513 record: function()
514 {
515 return this._record;
516 },
517
518 /**
519 * @return {!Object.<string, number>}
520 */
521 presentationAggregatedStats: function()
522 {
523 return this._record.aggregatedStats();
524 },
525
526 /**
527 * @return {boolean}
528 */
529 hasWarnings: function()
530 {
531 return !!this._record.warnings();
532 },
533
534 /**
535 * @return {string}
536 */
537 toString: function()
caseq 2014/06/16 12:26:33 is thus used?
yurys 2014/06/16 12:32:37 Not anymore. Removed.
538 {
539 return "ActualRecord: " + this._record.type();
540 },
541
542 __proto__: WebInspector.TimelinePresentationModel.Record.prototype
543 }
544
545 /**
546 * @constructor
547 * @extends {WebInspector.TimelinePresentationModel.Record}
548 * @param {!WebInspector.TimelineModel.Record} record
549 */
550 WebInspector.TimelinePresentationModel.CoalescedRecord = function(record)
551 {
552 WebInspector.TimelinePresentationModel.Record.call(this, null);
553 this._startTime = record.startTime();
554 this._endTime = record.endTime();
555 this._aggregatedStats = {};
556 }
557
558 WebInspector.TimelinePresentationModel.CoalescedRecord.prototype = {
559 /**
560 * @return {number}
561 */
562 startTime: function()
563 {
564 return this._startTime;
565 },
566
567 /**
568 * @return {number}
569 */
570 endTime: function()
571 {
572 return this._endTime;
573 },
574
575 /**
576 * @return {number}
577 */
578 selfTime: function()
579 {
580 return 0;
581 },
582
583 /**
584 * @return {!WebInspector.TimelineModel.Record}
585 */
586 record: function()
587 {
588 return this._presentationChildren[0].record();
589 },
590
591 /**
592 * @return {!Object.<string, number>}
593 */
594 presentationAggregatedStats: function()
595 {
596 return this._aggregatedStats;
597 },
598
599 /**
600 * @return {boolean}
601 */
602 coalesced: function()
603 {
604 return true;
605 },
606
607 /**
608 * @return {boolean}
609 */
610 hasWarnings: function()
611 {
612 return false;
613 },
614
615 /**
616 * @return {string}
617 */
618 toString: function()
619 {
620 return "CoalescedRecord";
621 },
622
623 __proto__: WebInspector.TimelinePresentationModel.Record.prototype
624 }
625
626 /**
627 * @constructor
628 * @extends {WebInspector.TimelinePresentationModel.Record}
629 */
630 WebInspector.TimelinePresentationModel.RootRecord = function()
631 {
632 WebInspector.TimelinePresentationModel.Record.call(this, null);
633 this._aggregatedStats = {};
634 }
635
636 WebInspector.TimelinePresentationModel.RootRecord.prototype = {
637 /**
638 * @return {!Object.<string, number>}
639 */
640 presentationAggregatedStats: function()
641 {
642 return this._aggregatedStats;
643 },
644
645 /**
646 * @return {boolean}
647 */
648 hasWarnings: function()
649 {
650 return false;
651 },
652
653 /**
654 * @return {string}
655 */
656 toString: function()
657 {
658 return "RootRecord";
659 },
660
661 __proto__: WebInspector.TimelinePresentationModel.Record.prototype
662 }
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