Commit 7d60ac92 authored by yurys@chromium.org's avatar yurys@chromium.org

Don't create TimelineModel.RecordImpl in TimelinePresentationModel.js

TimelinePresentationModel.Record now has three implementations: one for root record, one for coealesced record and one for representing actual TimelineModel.Record. This allows it to work fine with Timeline based on trace events.

BUG=361045
R=caseq@chromium.org

Review URL: https://codereview.chromium.org/337023004

git-svn-id: svn://svn.chromium.org/blink/trunk@176205 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent e09741d1
......@@ -207,7 +207,7 @@ InspectorTest.dumpTimelineRecord = function(record, detailsCallback, level, filt
// Dump just the record name, indenting output on separate lines for subrecords
InspectorTest.dumpPresentationRecord = function(presentationRecord, detailsCallback, level, filterTypes)
{
var record = presentationRecord.record();
var record = !presentationRecord.presentationParent() ? null : presentationRecord.record();
if (typeof level !== "number")
level = 0;
var prefix = "";
......@@ -218,13 +218,14 @@ InspectorTest.dumpPresentationRecord = function(presentationRecord, detailsCallb
prefix = prefix + "> ";
if (presentationRecord.coalesced()) {
suffix = " x " + presentationRecord.presentationChildren().length;
} else if (record.type() === WebInspector.TimelineModel.RecordType.TimeStamp
|| record.type() === WebInspector.TimelineModel.RecordType.ConsoleTime) {
} else if (record && (record.type() === WebInspector.TimelineModel.RecordType.TimeStamp
|| record.type() === WebInspector.TimelineModel.RecordType.ConsoleTime)) {
suffix = " : " + record.data().message;
}
if (detailsCallback)
suffix += " " + detailsCallback(record);
InspectorTest.addResult(prefix + InspectorTest._timelineAgentTypeToString(record.type()) + suffix);
suffix += " " + detailsCallback(presentationRecord);
var typeString = record ? InspectorTest._timelineAgentTypeToString(record.type()) : "Root";
InspectorTest.addResult(prefix + typeString + suffix);
var numChildren = presentationRecord.presentationChildren() ? presentationRecord.presentationChildren().length : 0;
for (var i = 0; i < numChildren; ++i) {
......
......@@ -7,11 +7,11 @@
function initialize_TimelineCoalescing()
{
InspectorTest.dumpStats = function(record)
InspectorTest.dumpStats = function(presentationRecord)
{
if (record.type() === "Root")
if (!presentationRecord.presentationParent())
return "";
var aggregatedStats = record.aggregatedStats();
var aggregatedStats = presentationRecord.presentationAggregatedStats();
var timeByCategory = "";
for (category in aggregatedStats) {
......@@ -19,8 +19,8 @@ InspectorTest.dumpStats = function(record)
timeByCategory += ", ";
timeByCategory += category + ": " + aggregatedStats[category].toFixed(5);
}
var duration = (record.endTime() - record.startTime()).toFixed(5);
var durationTillLastChild = (record.endTime() - record.startTime()).toFixed(5);
var duration = (presentationRecord.endTime() - presentationRecord.startTime()).toFixed(5);
var durationTillLastChild = (presentationRecord.endTime() - presentationRecord.startTime()).toFixed(5);
return "duration: " + duration + ":" + durationTillLastChild + (timeByCategory ? " (" + timeByCategory + ")" : "");
}
......
......@@ -32,7 +32,7 @@
* @constructor
* @implements {WebInspector.FlameChartDataProvider}
* @implements {WebInspector.TimelineFlameChart.SelectionProvider}
* @param {!WebInspector.TimelineModel} model
* @param {!WebInspector.TimelineModelImpl} model
* @param {!WebInspector.TimelineFrameModelBase} frameModel
*/
WebInspector.TimelineFlameChartDataProvider = function(model, frameModel)
......@@ -816,7 +816,7 @@ WebInspector.TimelineFlameChart = function(delegate, model, tracingModel, frameM
this._model = model;
this._dataProvider = tracingModel
? new WebInspector.TracingBasedTimelineFlameChartDataProvider(tracingModel, frameModel, model.target())
: new WebInspector.TimelineFlameChartDataProvider(model, frameModel);
: new WebInspector.TimelineFlameChartDataProvider(/** @type {!WebInspector.TimelineModelImpl} */(model), frameModel);
this._mainView = new WebInspector.FlameChart(this._dataProvider, this, true);
this._mainView.show(this.element);
this._model.addEventListener(WebInspector.TimelineModel.Events.RecordingStarted, this._onRecordingStarted, this);
......
......@@ -6,7 +6,7 @@
WebInspector.TimelineJSProfileProcessor = { };
/**
* @param {!WebInspector.TimelineModel} timelineModel
* @param {!WebInspector.TimelineModelImpl} timelineModel
* @param {!ProfilerAgent.CPUProfile} jsProfile
*/
WebInspector.TimelineJSProfileProcessor.mergeJSProfileIntoTimeline = function(timelineModel, jsProfile)
......
......@@ -164,7 +164,6 @@ WebInspector.TimelineModelImpl.prototype = {
* @param {!TimelineAgent.TimelineEvent} payload
* @param {?WebInspector.TimelineModel.Record} parentRecord
* @return {!WebInspector.TimelineModel.Record}
* @this {!WebInspector.TimelineModel}
*/
_innerAddRecord: function(payload, parentRecord)
{
......@@ -292,7 +291,7 @@ WebInspector.TimelineModelImpl.InterRecordBindings.prototype = {
/**
* @constructor
* @implements {WebInspector.TimelineModel.Record}
* @param {!WebInspector.TimelineModel} model
* @param {!WebInspector.TimelineModelImpl} model
* @param {!TimelineAgent.TimelineEvent} timelineEvent
* @param {?WebInspector.TimelineModel.Record} parentRecord
*/
......
......@@ -83,9 +83,7 @@ WebInspector.TimelinePresentationModel.prototype = {
reset: function()
{
this._recordToPresentationRecord.clear();
var rootPayload = { type: WebInspector.TimelineModel.RecordType.Root };
var rootRecord = new WebInspector.TimelineModel.RecordImpl(this._model, /** @type {!TimelineAgent.TimelineEvent} */ (rootPayload), null);
this._rootRecord = new WebInspector.TimelinePresentationModel.Record(rootRecord, null);
this._rootRecord = new WebInspector.TimelinePresentationModel.RootRecord();
/** @type {!Object.<string, !WebInspector.TimelinePresentationModel.Record>} */
this._coalescingBuckets = {};
},
......@@ -120,7 +118,7 @@ WebInspector.TimelinePresentationModel.prototype = {
if (coalescedRecord)
parentRecord = coalescedRecord;
var formattedRecord = new WebInspector.TimelinePresentationModel.Record(record, parentRecord);
var formattedRecord = new WebInspector.TimelinePresentationModel.ActualRecord(record, parentRecord);
this._recordToPresentationRecord.put(record, formattedRecord);
formattedRecord._collapsed = parentRecord === this._rootRecord;
......@@ -130,7 +128,7 @@ WebInspector.TimelinePresentationModel.prototype = {
for (var i = 0; record.children() && i < record.children().length; ++i)
this._innerAddRecord(formattedRecord, record.children()[i]);
if (parentRecord._coalesced)
if (parentRecord.coalesced())
this._updateCoalescingParent(formattedRecord);
},
......@@ -145,7 +143,7 @@ WebInspector.TimelinePresentationModel.prototype = {
const coalescingThresholdMillis = 5;
var lastRecord = bucket ? this._coalescingBuckets[bucket] : newParent._presentationChildren.peekLast();
if (lastRecord && lastRecord._coalesced)
if (lastRecord && lastRecord.coalesced())
lastRecord = lastRecord._presentationChildren.peekLast();
var startTime = record.startTime();
var endTime = record.endTime();
......@@ -159,7 +157,7 @@ WebInspector.TimelinePresentationModel.prototype = {
return null;
if (endTime + coalescingThresholdMillis < lastRecord.record().startTime())
return null;
if (lastRecord.presentationParent()._coalesced)
if (lastRecord.presentationParent().coalesced())
return lastRecord.presentationParent();
return this._replaceWithCoalescedRecord(lastRecord);
},
......@@ -171,21 +169,9 @@ WebInspector.TimelinePresentationModel.prototype = {
_replaceWithCoalescedRecord: function(presentationRecord)
{
var record = presentationRecord.record();
var rawRecord = {
type: record.type(),
startTime: record.startTime(),
data: { }
};
if (record.thread())
rawRecord.thread = "aggregated";
if (record.type() === WebInspector.TimelineModel.RecordType.TimeStamp)
rawRecord.data["message"] = record.data().message;
var modelRecord = new WebInspector.TimelineModel.RecordImpl(this._model, /** @type {!TimelineAgent.TimelineEvent} */ (rawRecord), null);
var coalescedRecord = new WebInspector.TimelinePresentationModel.Record(modelRecord, null);
var parent = presentationRecord._presentationParent;
var coalescedRecord = new WebInspector.TimelinePresentationModel.CoalescedRecord(record);
coalescedRecord._coalesced = true;
coalescedRecord._collapsed = true;
coalescedRecord._presentationChildren.push(presentationRecord);
presentationRecord._presentationParent = coalescedRecord;
......@@ -194,7 +180,7 @@ WebInspector.TimelinePresentationModel.prototype = {
coalescedRecord._presentationParent = parent;
parent._presentationChildren[parent._presentationChildren.indexOf(presentationRecord)] = coalescedRecord;
WebInspector.TimelineUIUtils.aggregateTimeByCategory(modelRecord.aggregatedStats(), record.aggregatedStats());
WebInspector.TimelineUIUtils.aggregateTimeByCategory(coalescedRecord.presentationAggregatedStats(), presentationRecord.presentationAggregatedStats());
return coalescedRecord;
},
......@@ -204,11 +190,10 @@ WebInspector.TimelinePresentationModel.prototype = {
*/
_updateCoalescingParent: function(presentationRecord)
{
var record = presentationRecord.record();
var parentRecord = presentationRecord._presentationParent.record();
WebInspector.TimelineUIUtils.aggregateTimeByCategory(parentRecord.aggregatedStats(), record.aggregatedStats());
if (parentRecord.endTime() < record.endTime())
parentRecord.setEndTime(record.endTime());
var parentRecord = presentationRecord._presentationParent;
WebInspector.TimelineUIUtils.aggregateTimeByCategory(parentRecord.presentationAggregatedStats(), presentationRecord.presentationAggregatedStats());
if (parentRecord.endTime() < presentationRecord.endTime())
parentRecord._endTime = presentationRecord.endTime();
},
/**
......@@ -257,9 +242,8 @@ WebInspector.TimelinePresentationModel.prototype = {
if (records && entry.index < records.length) {
var record = records[entry.index];
++entry.index;
var rawRecord = record.record();
if (rawRecord.startTime() < this._windowEndTime && rawRecord.endTime() > this._windowStartTime) {
if (this._model.isVisible(rawRecord)) {
if (record.startTime() < this._windowEndTime && record.endTime() > this._windowStartTime) {
if (this._model.isVisible(record.record())) {
record._presentationParent._expandable = true;
if (this._textFilter)
revealRecordsInStack();
......@@ -294,12 +278,10 @@ WebInspector.TimelinePresentationModel.prototype = {
/**
* @constructor
* @param {!WebInspector.TimelineModel.Record} record
* @param {?WebInspector.TimelinePresentationModel.Record} parentRecord
*/
WebInspector.TimelinePresentationModel.Record = function(record, parentRecord)
WebInspector.TimelinePresentationModel.Record = function(parentRecord)
{
this._record = record;
/**
* @type {!Array.<!WebInspector.TimelinePresentationModel.Record>}
*/
......@@ -309,20 +291,47 @@ WebInspector.TimelinePresentationModel.Record = function(record, parentRecord)
this._presentationParent = parentRecord;
parentRecord._presentationChildren.push(this);
}
if (this.hasWarnings()) {
for (var parent = this._presentationParent; parent && !parent._childHasWarnings; parent = parent._presentationParent)
parent._childHasWarnings = true;
}
}
WebInspector.TimelinePresentationModel.Record.prototype = {
/**
* @return {number}
*/
startTime: function()
{
throw new Error("Not implemented.");
},
/**
* @return {number}
*/
endTime: function()
{
throw new Error("Not implemented.");
},
/**
* @return {number}
*/
selfTime: function()
{
throw new Error("Not implemented.");
},
/**
* @return {!WebInspector.TimelineModel.Record}
*/
record: function()
{
return this._record;
throw new Error("Not implemented.");
},
/**
* @return {!Object.<string, number>}
*/
presentationAggregatedStats: function()
{
throw new Error("Not implemented.");
},
/**
......@@ -338,7 +347,7 @@ WebInspector.TimelinePresentationModel.Record.prototype = {
*/
coalesced: function()
{
return this._coalesced;
return false;
},
/**
......@@ -387,7 +396,7 @@ WebInspector.TimelinePresentationModel.Record.prototype = {
*/
hasWarnings: function()
{
return !!this._record.warnings();
return false;
},
/**
......@@ -430,3 +439,175 @@ WebInspector.TimelinePresentationModel.Record.prototype = {
this._graphRow = graphRow;
}
}
/**
* @constructor
* @extends {WebInspector.TimelinePresentationModel.Record}
* @param {!WebInspector.TimelineModel.Record} record
* @param {?WebInspector.TimelinePresentationModel.Record} parentRecord
*/
WebInspector.TimelinePresentationModel.ActualRecord = function(record, parentRecord)
{
WebInspector.TimelinePresentationModel.Record.call(this, parentRecord);
this._record = record;
if (this.hasWarnings()) {
for (var parent = this._presentationParent; parent && !parent._childHasWarnings; parent = parent._presentationParent)
parent._childHasWarnings = true;
}
}
WebInspector.TimelinePresentationModel.ActualRecord.prototype = {
/**
* @return {number}
*/
startTime: function()
{
return this._record.startTime();
},
/**
* @return {number}
*/
endTime: function()
{
return this._record.endTime();
},
/**
* @return {number}
*/
selfTime: function()
{
return this._record.selfTime();
},
/**
* @return {!WebInspector.TimelineModel.Record}
*/
record: function()
{
return this._record;
},
/**
* @return {!Object.<string, number>}
*/
presentationAggregatedStats: function()
{
return this._record.aggregatedStats();
},
/**
* @return {boolean}
*/
hasWarnings: function()
{
return !!this._record.warnings();
},
__proto__: WebInspector.TimelinePresentationModel.Record.prototype
}
/**
* @constructor
* @extends {WebInspector.TimelinePresentationModel.Record}
* @param {!WebInspector.TimelineModel.Record} record
*/
WebInspector.TimelinePresentationModel.CoalescedRecord = function(record)
{
WebInspector.TimelinePresentationModel.Record.call(this, null);
this._startTime = record.startTime();
this._endTime = record.endTime();
this._aggregatedStats = {};
}
WebInspector.TimelinePresentationModel.CoalescedRecord.prototype = {
/**
* @return {number}
*/
startTime: function()
{
return this._startTime;
},
/**
* @return {number}
*/
endTime: function()
{
return this._endTime;
},
/**
* @return {number}
*/
selfTime: function()
{
return 0;
},
/**
* @return {!WebInspector.TimelineModel.Record}
*/
record: function()
{
return this._presentationChildren[0].record();
},
/**
* @return {!Object.<string, number>}
*/
presentationAggregatedStats: function()
{
return this._aggregatedStats;
},
/**
* @return {boolean}
*/
coalesced: function()
{
return true;
},
/**
* @return {boolean}
*/
hasWarnings: function()
{
return false;
},
__proto__: WebInspector.TimelinePresentationModel.Record.prototype
}
/**
* @constructor
* @extends {WebInspector.TimelinePresentationModel.Record}
*/
WebInspector.TimelinePresentationModel.RootRecord = function()
{
WebInspector.TimelinePresentationModel.Record.call(this, null);
this._aggregatedStats = {};
}
WebInspector.TimelinePresentationModel.RootRecord.prototype = {
/**
* @return {!Object.<string, number>}
*/
presentationAggregatedStats: function()
{
return this._aggregatedStats;
},
/**
* @return {boolean}
*/
hasWarnings: function()
{
return false;
},
__proto__: WebInspector.TimelinePresentationModel.Record.prototype
}
......@@ -129,8 +129,8 @@ WebInspector.TimelineView.prototype = {
for (var i = 0; i < eventDividerRecords.length; ++i) {
var record = eventDividerRecords[i];
var positions = this._calculator.computeBarGraphWindowPosition(record);
var dividerPosition = Math.round(positions.left);
var position = this._calculator.computePosition(record.startTime());
var dividerPosition = Math.round(position);
if (dividerPosition < 0 || dividerPosition >= clientWidth || dividers[dividerPosition])
continue;
var divider = WebInspector.TimelineUIUtils.createEventDivider(record.type(), WebInspector.TimelineUIUtils.recordTitle(record, this._model));
......@@ -531,8 +531,8 @@ WebInspector.TimelineView.prototype = {
this._automaticallySizeWindow = false;
this._clearSelection();
// If we're at the top, always use real timeline start as a left window bound so that expansion arrow padding logic works.
var windowStartTime = startIndex ? recordsInWindow[startIndex].record().startTime() : this._model.minimumRecordTime();
var windowEndTime = recordsInWindow[Math.max(0, lastVisibleLine - 1)].record().endTime();
var windowStartTime = startIndex ? recordsInWindow[startIndex].startTime() : this._model.minimumRecordTime();
var windowEndTime = recordsInWindow[Math.max(0, lastVisibleLine - 1)].endTime();
this._delegate.requestWindowTimes(windowStartTime, windowEndTime);
recordsInWindow = this._presentationModel.filteredRecords();
endIndex = Math.min(recordsInWindow.length, lastVisibleLine);
......@@ -566,7 +566,7 @@ WebInspector.TimelineView.prototype = {
var lastChildIndex = i + record.visibleChildrenCount();
if (lastChildIndex >= startIndex && lastChildIndex < endIndex) {
var expandElement = new WebInspector.TimelineExpandableElement(this._expandElements);
var positions = this._calculator.computeBarGraphWindowPosition(record.record());
var positions = this._calculator.computeBarGraphWindowPosition(record);
expandElement._update(record, i, positions.left - this._expandOffset, positions.width);
}
} else {
......@@ -824,7 +824,10 @@ WebInspector.TimelineView.prototype = {
{
if (!rowElement || !rowElement.row)
return false;
var record = rowElement.row._record.record();
var presentationRecord = rowElement.row._record;
if (presentationRecord.collapsed())
return false;
var record = presentationRecord.record();
if (this._highlightedQuadRecord === record)
return true;
this._highlightedQuadRecord = record;
......@@ -920,7 +923,7 @@ WebInspector.TimelineCalculator.prototype = {
},
/**
* @param {!WebInspector.TimelineModel.Record} record
* @param {!WebInspector.TimelinePresentationModel.Record} record
* @return {!{start: number, end: number, cpuWidth: number}}
*/
computeBarGraphPercentages: function(record)
......@@ -932,7 +935,7 @@ WebInspector.TimelineCalculator.prototype = {
},
/**
* @param {!WebInspector.TimelineModel.Record} record
* @param {!WebInspector.TimelinePresentationModel.Record} record
* @return {!{left: number, width: number, cpuWidth: number}}
*/
computeBarGraphWindowPosition: function(record)
......@@ -1193,7 +1196,7 @@ WebInspector.TimelineRecordGraphRow.prototype = {
if (record.thread())
this.element.classList.add("background");
var barPosition = calculator.computeBarGraphWindowPosition(record);
var barPosition = calculator.computeBarGraphWindowPosition(presentationRecord);
this._barElement.style.left = barPosition.left + "px";
this._barElement.style.width = barPosition.width + "px";
this._barCpuElement.style.left = barPosition.left + "px";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment