OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 18 matching lines...) Expand all Loading... | |
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 = this._lastFrameForRecord(record); |
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.CommitF rame) { |
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 /** |
100 * @param {Object} record | 110 * @param {Object} record |
101 * @param {number} programTimeCarryover | |
102 */ | 111 */ |
103 _flushFrame: function(record, programTimeCarryover) | 112 _lastFrameForRecord: function(record) |
104 { | 113 { |
105 this._lastFrame.endTime = WebInspector.TimelineModel.startTimeInSeconds( record); | 114 return record.thread ? this._lastBackgroundFrame : this._lastMainThreadF rame; |
pfeldman
2013/11/06 17:21:05
inline
| |
106 this._lastFrame.duration = this._lastFrame.endTime - this._lastFrame.sta rtTime; | |
107 this._lastFrame.timeByCategory["other"] -= programTimeCarryover; | |
108 // 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. | |
110 this._lastFrame.cpuTime += this._lastFrame.timeByCategory["other"]; | |
111 this._overviewPane.addFrame(this._lastFrame); | |
112 this._presentationModel.addFrame(this._lastFrame); | |
113 this._lastFrame = this._createFrame(record, programTimeCarryover); | |
114 }, | 115 }, |
115 | 116 |
116 /** | 117 /** |
118 * @param {WebInspector.TimelineFrame} frame | |
119 * @param {Object} record | |
120 * @param {number} programTimeCarryover | |
121 */ | |
122 _flushFrame: function(frame, record, programTimeCarryover) | |
123 { | |
124 frame.endTime = WebInspector.TimelineModel.startTimeInSeconds(record); | |
125 frame.duration = frame.endTime - frame.startTime; | |
126 frame.timeByCategory["other"] -= programTimeCarryover; | |
127 // Alternatively, we could compute CPU time as sum of all Program events . | |
128 // This way it's a bit more flexible, as it works in case there's no pro gram events. | |
129 frame.cpuTime += frame.timeByCategory["other"]; | |
130 this._overviewPane.addFrame(frame); | |
131 this._presentationModel.addFrame(frame); | |
132 }, | |
133 | |
134 /** | |
117 * @param {Object} record | 135 * @param {Object} record |
118 * @param {number} programTimeCarryover | 136 * @param {number} programTimeCarryover |
119 */ | 137 */ |
120 _createFrame: function(record, programTimeCarryover) | 138 _createFrame: function(record, programTimeCarryover) |
121 { | 139 { |
122 var frame = new WebInspector.TimelineFrame(); | 140 var frame = new WebInspector.TimelineFrame(); |
123 frame.startTime = WebInspector.TimelineModel.startTimeInSeconds(record); | 141 frame.startTime = WebInspector.TimelineModel.startTimeInSeconds(record); |
124 frame.startTimeOffset = this._model.recordOffsetInSeconds(record); | 142 frame.startTimeOffset = this._model.recordOffsetInSeconds(record); |
125 frame.timeByCategory["other"] = programTimeCarryover; | 143 frame.timeByCategory["other"] = programTimeCarryover; |
144 frame.isBackground = !!record.thread; | |
145 frame.id = record.data && record.data["id"]; | |
126 return frame; | 146 return frame; |
127 }, | 147 }, |
128 | 148 |
129 dispose: function() | 149 dispose: function() |
130 { | 150 { |
131 this._model.removeEventListener(WebInspector.TimelineModel.Events.Record Added, this._onRecordAdded, this); | 151 this._model.removeEventListener(WebInspector.TimelineModel.Events.Record Added, this._onRecordAdded, this); |
132 this._model.removeEventListener(WebInspector.TimelineModel.Events.Record sCleared, this._onRecordsCleared, this); | 152 this._model.removeEventListener(WebInspector.TimelineModel.Events.Record sCleared, this._onRecordsCleared, this); |
133 } | 153 } |
134 } | 154 } |
135 | 155 |
(...skipping 27 matching lines...) Expand all Loading... | |
163 } | 183 } |
164 | 184 |
165 /** | 185 /** |
166 * @constructor | 186 * @constructor |
167 */ | 187 */ |
168 WebInspector.TimelineFrame = function() | 188 WebInspector.TimelineFrame = function() |
169 { | 189 { |
170 this.timeByCategory = {}; | 190 this.timeByCategory = {}; |
171 this.cpuTime = 0; | 191 this.cpuTime = 0; |
172 } | 192 } |
OLD | NEW |