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

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

Issue 61923003: Timeline: show impl-side frames on the Timeline overview (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebased, addressed review comments, added a test Created 7 years 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) 2012 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
11 * copyright notice, this list of conditions and the following disclaimer 11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the 12 * in the documentation and/or other materials provided with the
(...skipping 16 matching lines...) Expand all
29 */ 29 */
30 30
31 /** 31 /**
32 * @constructor 32 * @constructor
33 * @param {WebInspector.TimelineModel} model 33 * @param {WebInspector.TimelineModel} model
34 * @param {WebInspector.TimelineOverviewPane} overviewPane 34 * @param {WebInspector.TimelineOverviewPane} overviewPane
35 * @param {WebInspector.TimelinePresentationModel} presentationModel 35 * @param {WebInspector.TimelinePresentationModel} presentationModel
36 */ 36 */
37 WebInspector.TimelineFrameController = function(model, overviewPane, presentatio nModel) 37 WebInspector.TimelineFrameController = function(model, overviewPane, presentatio nModel)
38 { 38 {
39 this._lastFrame = null; 39 this._lastMainThreadFrame = null;
40 this._lastBackgroundFrame = null;
40 this._model = model; 41 this._model = model;
41 this._overviewPane = overviewPane; 42 this._overviewPane = overviewPane;
42 this._presentationModel = presentationModel; 43 this._presentationModel = presentationModel;
43 this._model.addEventListener(WebInspector.TimelineModel.Events.RecordAdded, this._onRecordAdded, this); 44 this._model.addEventListener(WebInspector.TimelineModel.Events.RecordAdded, this._onRecordAdded, this);
44 this._model.addEventListener(WebInspector.TimelineModel.Events.RecordsCleare d, this._onRecordsCleared, this); 45 this._model.addEventListener(WebInspector.TimelineModel.Events.RecordsCleare d, this._onRecordsCleared, this);
45 46
46 var records = model.records; 47 var records = model.records;
47 for (var i = 0; i < records.length; ++i) 48 for (var i = 0; i < records.length; ++i)
48 this._addRecord(records[i]); 49 this._addRecord(records[i]);
49 } 50 }
50 51
51 WebInspector.TimelineFrameController.prototype = { 52 WebInspector.TimelineFrameController.prototype = {
52 _onRecordAdded: function(event) 53 _onRecordAdded: function(event)
53 { 54 {
54 this._addRecord(event.data); 55 this._addRecord(event.data);
55 }, 56 },
56 57
57 _onRecordsCleared: function() 58 _onRecordsCleared: function()
58 { 59 {
59 this._lastFrame = null; 60 this._lastMainThreadFrame = null;
61 this._lastBackgroundFrame = null;
60 }, 62 },
61 63
62 _addRecord: function(record) 64 _addRecord: function(record)
63 { 65 {
64 if (record.isBackground)
65 return;
66 var records; 66 var records;
67 var programRecord; 67 var programRecord;
68 if (record.type === WebInspector.TimelineModel.RecordType.Program) { 68 if (record.type === WebInspector.TimelineModel.RecordType.Program) {
69 programRecord = record; 69 programRecord = record;
70 if (this._lastFrame) 70 if (this._lastMainThreadFrame)
71 this._lastFrame.timeByCategory["other"] += WebInspector.Timeline Model.durationInSeconds(programRecord); 71 this._lastMainThreadFrame.timeByCategory["other"] += WebInspecto r.TimelineModel.durationInSeconds(programRecord);
72 records = record["children"] || []; 72 records = record["children"] || [];
73 } else 73 } else
74 records = [record]; 74 records = [record];
75 records.forEach(this._innerAddRecord.bind(this, programRecord)); 75 records.forEach(this._innerAddRecord.bind(this, programRecord));
76 }, 76 },
77 77
78 /** 78 /**
79 * @param {Object} programRecord 79 * @param {Object} programRecord
80 * @param {Object} record 80 * @param {Object} record
81 */ 81 */
82 _innerAddRecord: function(programRecord, record) 82 _innerAddRecord: function(programRecord, record)
83 { 83 {
84 var isFrameRecord = record.type === WebInspector.TimelineModel.RecordTyp e.BeginFrame; 84 var isFrameRecord = record.type === WebInspector.TimelineModel.RecordTyp e.BeginFrame;
85 var programTimeCarryover = isFrameRecord && programRecord ? WebInspector .TimelineModel.endTimeInSeconds(programRecord) - WebInspector.TimelineModel.star tTimeInSeconds(record) : 0; 85 var programTimeCarryover = isFrameRecord && programRecord ? WebInspector .TimelineModel.endTimeInSeconds(programRecord) - WebInspector.TimelineModel.star tTimeInSeconds(record) : 0;
86 if (isFrameRecord && this._lastFrame) 86 var lastFrame = record.thread ? this._lastBackgroundFrame : this._lastMa inThreadFrame;
87 this._flushFrame(record, programTimeCarryover); 87 if (isFrameRecord && lastFrame) {
88 else { 88 this._flushFrame(lastFrame, record, programTimeCarryover);
89 if (!this._lastFrame) 89 lastFrame = this._createFrame(record, programTimeCarryover);
90 this._lastFrame = this._createFrame(record, programTimeCarryover ); 90 } else if (record.type === WebInspector.TimelineModel.RecordType.Activat eLayerTree) {
91 if (!record.thread) 91 if (lastFrame)
92 WebInspector.TimelineModel.aggregateTimeForRecord(this._lastFram e.timeByCategory, record); 92 lastFrame.mainThreadFrameId = record.data.id;
93 var duration = WebInspector.TimelineModel.durationInSeconds(record); 93 } else {
94 this._lastFrame.cpuTime += duration; 94 if (!lastFrame)
95 this._lastFrame.timeByCategory["other"] -= duration; 95 lastFrame = this._createFrame(record, programTimeCarryover);
96 if (!record.thread) {
97 WebInspector.TimelineModel.aggregateTimeForRecord(lastFrame.time ByCategory, record);
98 var duration = WebInspector.TimelineModel.durationInSeconds(reco rd);
99 lastFrame.cpuTime += duration;
100 lastFrame.timeByCategory["other"] -= duration;
101 }
96 } 102 }
103 if (record.thread)
104 this._lastBackgroundFrame = lastFrame;
105 else
106 this._lastMainThreadFrame = lastFrame;
97 }, 107 },
98 108
99 /** 109 /**
110 * @param {WebInspector.TimelineFrame} frame
100 * @param {Object} record 111 * @param {Object} record
101 * @param {number} programTimeCarryover 112 * @param {number} programTimeCarryover
102 */ 113 */
103 _flushFrame: function(record, programTimeCarryover) 114 _flushFrame: function(frame, record, programTimeCarryover)
104 { 115 {
105 this._lastFrame.endTime = WebInspector.TimelineModel.startTimeInSeconds( record); 116 frame.endTime = WebInspector.TimelineModel.startTimeInSeconds(record);
106 this._lastFrame.duration = this._lastFrame.endTime - this._lastFrame.sta rtTime; 117 frame.duration = frame.endTime - frame.startTime;
107 this._lastFrame.timeByCategory["other"] -= programTimeCarryover; 118 frame.timeByCategory["other"] -= programTimeCarryover;
108 // Alternatively, we could compute CPU time as sum of all Program events . 119 // Alternatively, we could compute CPU time as sum of all Program events .
109 // This way it's a bit more flexible, as it works in case there's no pro gram events. 120 // This way it's a bit more flexible, as it works in case there's no pro gram events.
110 this._lastFrame.cpuTime += this._lastFrame.timeByCategory["other"]; 121 frame.cpuTime += frame.timeByCategory["other"];
111 this._overviewPane.addFrame(this._lastFrame); 122 this._overviewPane.addFrame(frame);
112 this._presentationModel.addFrame(this._lastFrame); 123 this._presentationModel.addFrame(frame);
113 this._lastFrame = this._createFrame(record, programTimeCarryover);
114 }, 124 },
115 125
116 /** 126 /**
117 * @param {Object} record 127 * @param {Object} record
118 * @param {number} programTimeCarryover 128 * @param {number} programTimeCarryover
119 */ 129 */
120 _createFrame: function(record, programTimeCarryover) 130 _createFrame: function(record, programTimeCarryover)
121 { 131 {
122 var frame = new WebInspector.TimelineFrame(); 132 var frame = new WebInspector.TimelineFrame();
123 frame.startTime = WebInspector.TimelineModel.startTimeInSeconds(record); 133 frame.startTime = WebInspector.TimelineModel.startTimeInSeconds(record);
124 frame.startTimeOffset = this._model.recordOffsetInSeconds(record); 134 frame.startTimeOffset = this._model.recordOffsetInSeconds(record);
125 frame.timeByCategory["other"] = programTimeCarryover; 135 frame.timeByCategory["other"] = programTimeCarryover;
136 frame.isBackground = !!record.thread;
137 frame.id = record.data && record.data["id"];
126 return frame; 138 return frame;
127 }, 139 },
128 140
129 dispose: function() 141 dispose: function()
130 { 142 {
131 this._model.removeEventListener(WebInspector.TimelineModel.Events.Record Added, this._onRecordAdded, this); 143 this._model.removeEventListener(WebInspector.TimelineModel.Events.Record Added, this._onRecordAdded, this);
132 this._model.removeEventListener(WebInspector.TimelineModel.Events.Record sCleared, this._onRecordsCleared, this); 144 this._model.removeEventListener(WebInspector.TimelineModel.Events.Record sCleared, this._onRecordsCleared, this);
133 } 145 }
134 } 146 }
135 147
(...skipping 26 matching lines...) Expand all
162 this.stddev = Math.sqrt(variance); 174 this.stddev = Math.sqrt(variance);
163 } 175 }
164 176
165 /** 177 /**
166 * @constructor 178 * @constructor
167 */ 179 */
168 WebInspector.TimelineFrame = function() 180 WebInspector.TimelineFrame = function()
169 { 181 {
170 this.timeByCategory = {}; 182 this.timeByCategory = {};
171 this.cpuTime = 0; 183 this.cpuTime = 0;
184 /** @type {string} */
185 this.mainThreadFrameId;
172 } 186 }
OLDNEW
« no previous file with comments | « LayoutTests/inspector/timeline/timeline-frame-controller-expected.txt ('k') | Source/devtools/front_end/TimelineModel.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698