TimelineFrameController.js [plain text]
WebInspector.TimelineFrameController = function(model, overviewPane, presentationModel)
{
this._lastFrame = null;
this._model = model;
this._overviewPane = overviewPane;
this._presentationModel = presentationModel;
this._model.addEventListener(WebInspector.TimelineModel.Events.RecordAdded, this._onRecordAdded, this);
this._model.addEventListener(WebInspector.TimelineModel.Events.RecordsCleared, this._onRecordsCleared, this);
var records = model.records;
for (var i = 0; i < records.length; ++i)
this._addRecord(records[i]);
}
WebInspector.TimelineFrameController.prototype = {
_onRecordAdded: function(event)
{
this._addRecord(event.data);
},
_onRecordsCleared: function()
{
this._lastFrame = null;
},
_addRecord: function(record)
{
if (record.type === WebInspector.TimelineModel.RecordType.BeginFrame)
this._flushFrame(record);
else if (this._lastFrame) {
WebInspector.TimelineModel.aggregateTimeForRecord(this._lastFrame.timeByCategory, record);
this._lastFrame.cpuTime += WebInspector.TimelineModel.durationInSeconds(record);
} else {
this._overviewPane.addFrame(this._createSyntheticFrame(record));
}
},
_flushFrame: function(record)
{
var frameBeginTime = WebInspector.TimelineModel.startTimeInSeconds(record);
if (this._lastFrame) {
this._lastFrame.endTime = frameBeginTime;
this._lastFrame.duration = this._lastFrame.endTime - this._lastFrame.startTime;
this._overviewPane.addFrame(this._lastFrame);
this._presentationModel.addFrame(this._lastFrame);
}
this._lastFrame = new WebInspector.TimelineFrame();
this._lastFrame.startTime = frameBeginTime;
this._lastFrame.startTimeOffset = this._model.recordOffsetInSeconds(record);
},
_createSyntheticFrame: function(record)
{
var frame = new WebInspector.TimelineFrame();
frame.startTime = WebInspector.TimelineModel.startTimeInSeconds(record);
frame.startTimeOffset = this._model.recordOffsetInSeconds(record);
frame.endTime = WebInspector.TimelineModel.endTimeInSeconds(record);
frame.duration = WebInspector.TimelineModel.durationInSeconds(record);
frame.cpuTime = frame.duration;
return frame;
},
dispose: function()
{
this._model.removeEventListener(WebInspector.TimelineModel.Events.RecordAdded, this._onRecordAdded, this);
this._model.removeEventListener(WebInspector.TimelineModel.Events.RecordsCleared, this._onRecordsCleared, this);
}
}
WebInspector.TimelineFrame = function()
{
this.timeByCategory = {};
this.cpuTime = 0;
}