Commit 27e3e53b authored by caseq@chromium.org's avatar caseq@chromium.org

DevTools: remove most convenience wrappers from WI.TimelineModel.Record

These were mostly for the convenience of layout tests, rarely used in the
prod code. Let's keep TimelineModel.Record() a thin wrapper that just adds
hierarchy to trace events and keep timeline-specific logic away from it,
since it has to work for bare trace events most of the time.

BUG=

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

git-svn-id: svn://svn.chromium.org/blink/trunk@202020 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent f1367b31
......@@ -283,18 +283,24 @@ InspectorTest.dumpTimelineRecords = function(timelineRecords)
InspectorTest.printTimelineRecordProperties = function(record)
{
InspectorTest.addResult(record.type() + " Properties:");
var object = {};
var names = ["data", "endTime", "frameId", "stackTrace", "startTime", "thread", "type"];
for (var i = 0; i < names.length; i++) {
var name = names[i];
var value = record[name].call(record);
if (value)
object[name] = value;
var traceEvent = record.traceEvent();
var data = traceEvent.args["beginData"] || traceEvent.args["data"];
var frameId = data && data["frame"];
var object = {
data: traceEvent.args["data"] || traceEvent.args,
endTime: record.endTime(),
frameId: frameId,
stackTrace: traceEvent.stackTrace,
startTime: record.startTime(),
thread: record.thread(),
type: record.type()
};
for (var field in object) {
if (object[field] === null || object[field] === undefined)
delete object[field];
}
if (record.children().length)
object["children"] = [];
if (!record.data())
object["data"] = record.traceEvent().args;
InspectorTest.addObject(object, InspectorTest.timelinePropertyFormatters);
};
......
......@@ -12,13 +12,14 @@ InspectorTest.dumpStats = function(presentationRecord)
if (!presentationRecord.presentationParent())
return "";
var model = InspectorTest.timelineModel();
var aggregatedStats = {};
if (presentationRecord.coalesced()) {
var presentationChildren = presentationRecord.presentationChildren();
for (var i = 0; i < presentationChildren.length; ++i)
WebInspector.TimelineUIUtils.aggregateTimeForRecord(aggregatedStats, presentationChildren[i].record());
WebInspector.TimelineUIUtils.aggregateTimeForRecord(aggregatedStats, model, presentationChildren[i].record());
} else {
WebInspector.TimelineUIUtils.aggregateTimeForRecord(aggregatedStats, presentationRecord.record());
WebInspector.TimelineUIUtils.aggregateTimeForRecord(aggregatedStats, model, presentationRecord.record());
}
var timeByCategory = "";
......
......@@ -64,7 +64,7 @@ function test()
prefix.push(" ");
}
var mark = record.expandable() ? (record.collapsed() ? "+" : "-") : " ";
InspectorTest.addResult(prefix.join("") + mark + record.record().data().message);
InspectorTest.addResult(prefix.join("") + mark + record.record().traceEvent().args["data"].message);
}
function dumpRecords()
......@@ -87,7 +87,7 @@ function test()
var collapseList = {"bar04":true, "foo13": true};
for (var i = 0; i < records.length; ++i) {
var record = records[i];
if (collapseList[record.record().data().message])
if (collapseList[record.record().traceEvent().args["data"].message])
record.setCollapsed(true);
}
model.invalidateFilteredRecords();
......
......@@ -31,8 +31,8 @@ function test()
function onTimelineRecorded()
{
var layoutRecord = InspectorTest.findFirstTimelineRecord("Layout");
InspectorTest.addResult("layout invalidated: " + layoutRecord.callSiteStackTrace()[0].functionName);
InspectorTest.addResult("layout forced: " + layoutRecord.stackTrace()[0].functionName);
InspectorTest.addResult("layout invalidated: " + layoutRecord.traceEvent().initiator.args["data"]["stackTrace"][0].functionName);
InspectorTest.addResult("layout forced: " + layoutRecord.traceEvent().args["beginData"]["stackTrace"][0].functionName);
InspectorTest.completeTest();
}
}
......
......@@ -39,7 +39,8 @@ function test()
InspectorTest.addResult("Script evaluated.");
var record = InspectorTest.findFirstTimelineRecord("ResourceReceivedData");
if (record) {
if (record.data() && typeof record.data().encodedDataLength === "number")
var data = record.traceEvent().args["data"];
if (data && typeof data.encodedDataLength === "number")
InspectorTest.addResult("Resource received data has length, test passed.");
}
InspectorTest.completeTest();
......
......@@ -59,28 +59,31 @@ function test()
function printSend(record)
{
printRecord(record);
requestId = record.data().requestId;
if (record.data().url === undefined)
var data = record.traceEvent().args["data"];
requestId = data.requestId;
if (data.url === undefined)
InspectorTest.addResult("* No 'url' property in record");
else if (record.data().url.indexOf(scriptUrl) === -1)
else if (data.url.indexOf(scriptUrl) === -1)
InspectorTest.addResult("* Didn't find URL: " + scriptUrl);
}
function printReceive(record)
{
printRecord(record);
if (requestId !== record.data().requestId)
var data = record.traceEvent().args["data"];
if (requestId !== data.requestId)
InspectorTest.addResult("Didn't find matching requestId: " + requestId);
if (record.data().statusCode !== 0)
InspectorTest.addResult("Response received status: " + record.data().statusCode);
if (data.statusCode !== 0)
InspectorTest.addResult("Response received status: " + data.statusCode);
}
function printFinish(record)
{
printRecord(record);
if (requestId !== record.data().requestId)
var data = record.traceEvent().args["data"];
if (requestId !== data.requestId)
InspectorTest.addResult("Didn't find matching requestId: " + requestId);
if (record.data().didFail)
if (data.didFail)
InspectorTest.addResult("Request failed.");
}
}
......
......@@ -40,9 +40,9 @@ function test()
{
var paintRecord = InspectorTest.findFirstTimelineRecord(WebInspector.TimelineModel.RecordType.Paint);
InspectorTest.assertTrue(paintRecord, "Paint record with subframe paint not found");
var topQuad = paintRecord.data().clip;
var topQuad = paintRecord.traceEvent().args["data"].clip;
var subframePaint = paintRecord.children()[0];
var subframeQuad = subframePaint.data().clip;
var subframeQuad = subframePaint.traceEvent().args["data"].clip;
InspectorTest.assertEquals(8, topQuad.length);
InspectorTest.assertEquals(8, subframeQuad.length);
InspectorTest.assertGreaterOrEqual(subframeQuad[0], topQuad[0]);
......
......@@ -15,6 +15,7 @@ ParseHTML Properties:
}
}
endTime : <number>
frameId : <string>
stackTrace : <object>
startTime : <number>
thread : <string>
......@@ -34,6 +35,7 @@ ParseHTML Properties:
}
}
endTime : <number>
frameId : <string>
stackTrace : <object>
startTime : <number>
thread : <string>
......
......@@ -34,7 +34,7 @@ function test()
function formatter(record)
{
if (record.type() === "TimerFire") {
var fnCallSite = record.children()[0].data();
var fnCallSite = record.children()[0].traceEvent().args["data"];
InspectorTest.addResult(record.type() + " " + fnCallSite.scriptName + ":" + fnCallSite.scriptLine);
}
}
......
......@@ -47,6 +47,9 @@ WebInspector.TimelineModel = function(tracingModel, recordFilter)
WebInspector.targetManager.observeTargets(this);
}
/**
* @enum {string}
*/
WebInspector.TimelineModel.RecordType = {
Task: "Task",
Program: "Program",
......@@ -254,14 +257,11 @@ WebInspector.TimelineModel.VirtualThread.prototype = {
/**
* @constructor
* @param {!WebInspector.TimelineModel} model
* @param {!WebInspector.TracingModel.Event} traceEvent
*/
WebInspector.TimelineModel.Record = function(model, traceEvent)
WebInspector.TimelineModel.Record = function(traceEvent)
{
this._model = model;
this._event = traceEvent;
traceEvent._timelineRecord = this;
this._children = [];
}
......@@ -277,24 +277,6 @@ WebInspector.TimelineModel.Record._compareStartTime = function(a, b)
}
WebInspector.TimelineModel.Record.prototype = {
/**
* @return {?Array.<!ConsoleAgent.CallFrame>}
*/
callSiteStackTrace: function()
{
var initiator = this._event.initiator;
return initiator ? initiator.stackTrace : null;
},
/**
* @return {?WebInspector.TimelineModel.Record}
*/
initiator: function()
{
var initiator = this._event.initiator;
return initiator ? initiator._timelineRecord : null;
},
/**
* @return {?WebInspector.Target}
*/
......@@ -305,14 +287,6 @@ WebInspector.TimelineModel.Record.prototype = {
return threadName === WebInspector.TimelineModel.RendererMainThreadName ? WebInspector.targetManager.targets()[0] || null : null;
},
/**
* @return {number}
*/
selfTime: function()
{
return this._event.selfTime;
},
/**
* @return {!Array.<!WebInspector.TimelineModel.Record>}
*/
......@@ -329,72 +303,32 @@ WebInspector.TimelineModel.Record.prototype = {
return this._event.startTime;
},
/**
* @return {string}
*/
thread: function()
{
if (this._event.thread.name() === WebInspector.TimelineModel.RendererMainThreadName)
return WebInspector.TimelineModel.MainThreadName;
return this._event.thread.name();
},
/**
* @return {number}
*/
endTime: function()
{
return this._endTime || this._event.endTime || this._event.startTime;
return this._event.endTime || this._event.startTime;
},
/**
* @param {number} endTime
*/
setEndTime: function(endTime)
{
this._endTime = endTime;
},
/**
* @return {!Object}
* @return {string}
*/
data: function()
thread: function()
{
return this._event.args["data"];
if (this._event.thread.name() === WebInspector.TimelineModel.RendererMainThreadName)
return WebInspector.TimelineModel.MainThreadName;
return this._event.thread.name();
},
/**
* @return {string}
* @return {!WebInspector.TimelineModel.RecordType}
*/
type: function()
{
if (this._event.hasCategory(WebInspector.TracingModel.ConsoleEventCategory))
return WebInspector.TimelineModel.RecordType.ConsoleTime;
return this._event.name;
},
/**
* @return {string}
*/
frameId: function()
{
switch (this._event.name) {
case WebInspector.TimelineModel.RecordType.UpdateLayoutTree:
case WebInspector.TimelineModel.RecordType.RecalculateStyles:
case WebInspector.TimelineModel.RecordType.Layout:
return this._event.args["beginData"]["frame"];
default:
var data = this._event.args["data"];
return (data && data["frame"]) || "";
}
},
/**
* @return {?Array.<!ConsoleAgent.CallFrame>}
*/
stackTrace: function()
{
return this._event.stackTrace;
return /** @type !WebInspector.TimelineModel.RecordType */ (this._event.name);
},
/**
......@@ -419,16 +353,6 @@ WebInspector.TimelineModel.Record.prototype = {
this._event.previewElement = /** @type {?Element} */ (value);
},
/**
* @return {?Array.<string>}
*/
warnings: function()
{
if (this._event.warning)
return [this._event.warning];
return null;
},
/**
* @return {!WebInspector.TracingModel.Event}
*/
......@@ -445,14 +369,6 @@ WebInspector.TimelineModel.Record.prototype = {
this._children.push(child);
child.parent = this;
},
/**
* @return {!WebInspector.TimelineModel}
*/
timelineModel: function()
{
return this._model;
}
}
/** @typedef {!{page: !Array<!WebInspector.TracingModel.Event>, workers: !Array<!WebInspector.TracingModel.Event>}} */
......@@ -937,7 +853,7 @@ WebInspector.TimelineModel.prototype = {
var drawFrameEvent = this._inspectedTargetEvents[i];
var firstPaintEvent = new WebInspector.TracingModel.Event(drawFrameEvent.categoriesString, recordTypes.MarkFirstPaint, WebInspector.TracingModel.Phase.Instant, drawFrameEvent.startTime, drawFrameEvent.thread);
this._mainThreadEvents.splice(insertionIndexForObjectInListSortedByFunction(firstPaintEvent, this._mainThreadEvents, WebInspector.TracingModel.Event.compareStartTime), 0, firstPaintEvent);
var firstPaintRecord = new WebInspector.TimelineModel.Record(this, firstPaintEvent);
var firstPaintRecord = new WebInspector.TimelineModel.Record(firstPaintEvent);
this._eventDividerRecords.splice(insertionIndexForObjectInListSortedByFunction(firstPaintRecord, this._eventDividerRecords, WebInspector.TimelineModel.Record._compareStartTime), 0, firstPaintRecord);
},
......@@ -975,7 +891,7 @@ WebInspector.TimelineModel.prototype = {
var recordTypes = WebInspector.TimelineModel.RecordType;
for (var i = 0; i < events.length; ++i) {
if (events[i].name === recordTypes.GPUTask)
this._gpuTasks.push(new WebInspector.TimelineModel.Record(this, events[i]));
this._gpuTasks.push(new WebInspector.TimelineModel.Record(events[i]));
}
},
......@@ -998,7 +914,7 @@ WebInspector.TimelineModel.prototype = {
// Maintain the back-end logic of old timeline, skip console.time() / console.timeEnd() that are not properly nested.
if (WebInspector.TracingModel.isAsyncBeginPhase(event.phase) && parentRecord && event.endTime > parentRecord._event.endTime)
continue;
var record = new WebInspector.TimelineModel.Record(this, event);
var record = new WebInspector.TimelineModel.Record(event);
if (WebInspector.TimelineUIUtils.isMarkerEvent(event))
this._eventDividerRecords.push(record);
if (!this._recordFilter.accept(record) && !WebInspector.TracingModel.isTopLevelEvent(event))
......
......@@ -877,10 +877,11 @@ WebInspector.TimelinePanel.prototype = {
{
var markers = new Map();
var recordTypes = WebInspector.TimelineModel.RecordType;
var zeroTime = this._model.minimumRecordTime();
for (var record of this._model.eventDividerRecords()) {
if (record.type() === recordTypes.TimeStamp || record.type() === recordTypes.ConsoleTime)
continue;
markers.set(record.startTime(), WebInspector.TimelineUIUtils.createDividerForRecord(record, 0));
markers.set(record.startTime(), WebInspector.TimelineUIUtils.createDividerForRecord(record, zeroTime, 0));
}
this._overviewPane.setMarkers(markers);
},
......@@ -1930,4 +1931,4 @@ WebInspector.TimelinePanel.RecordActionDelegate.prototype = {
console.assert(panel && panel instanceof WebInspector.TimelinePanel);
panel._toggleTimelineButtonClicked();
}
}
\ No newline at end of file
}
......@@ -477,7 +477,7 @@ WebInspector.TimelinePresentationModel.ActualRecord.prototype = {
*/
selfTime: function()
{
return this._record.selfTime();
return this._record.traceEvent().selfTime;
},
/**
......@@ -495,7 +495,7 @@ WebInspector.TimelinePresentationModel.ActualRecord.prototype = {
*/
hasWarnings: function()
{
return !!this._record.warnings();
return !!this._record.traceEvent().warning;
},
__proto__: WebInspector.TimelinePresentationModel.Record.prototype
......
......@@ -1134,13 +1134,12 @@ WebInspector.TimelineUIUtils.InvalidationsGroupElement.prototype = {
/**
* @param {!Object} total
* @param {!WebInspector.TimelineModel} model
* @param {!WebInspector.TimelineModel.Record} record
*/
WebInspector.TimelineUIUtils.aggregateTimeForRecord = function(total, record)
WebInspector.TimelineUIUtils.aggregateTimeForRecord = function(total, model, record)
{
var traceEvent = record.traceEvent();
var model = record.timelineModel();
WebInspector.TimelineUIUtils._aggregatedStatsForTraceEvent(total, model, traceEvent);
WebInspector.TimelineUIUtils._aggregatedStatsForTraceEvent(total, model, record.traceEvent());
}
/**
......@@ -1243,7 +1242,7 @@ WebInspector.TimelineUIUtils.buildPicturePreviewContent = function(event, target
}
/**
* @param {string} recordType
* @param {!WebInspector.TimelineModel.RecordType} recordType
* @param {?string} title
* @param {number} position
* @return {!Element}
......@@ -1273,12 +1272,13 @@ WebInspector.TimelineUIUtils.createEventDivider = function(recordType, title, po
/**
* @param {!WebInspector.TimelineModel.Record} record
* @param {number} zeroTime
* @param {number} position
* @return {!Element}
*/
WebInspector.TimelineUIUtils.createDividerForRecord = function(record, position)
WebInspector.TimelineUIUtils.createDividerForRecord = function(record, zeroTime, position)
{
var startTime = Number.millisToString(record.startTime() - record.timelineModel().minimumRecordTime());
var startTime = Number.millisToString(record.startTime() - zeroTime);
var title = WebInspector.UIString("%s at %s", WebInspector.TimelineUIUtils.eventTitle(record.traceEvent()), startTime);
return WebInspector.TimelineUIUtils.createEventDivider(record.type(), title, position);
}
......
......@@ -139,7 +139,7 @@ WebInspector.TimelineView.prototype = {
var dividerPosition = Math.round(position);
if (dividerPosition < 0 || dividerPosition >= clientWidth || dividers.has(dividerPosition))
continue;
dividers.set(dividerPosition, WebInspector.TimelineUIUtils.createDividerForRecord(record, dividerPosition));
dividers.set(dividerPosition, WebInspector.TimelineUIUtils.createDividerForRecord(record, this._calculator.zeroTime(), dividerPosition));
}
this._timelineGrid.addEventDividers(dividers.valuesArray());
},
......@@ -333,7 +333,7 @@ WebInspector.TimelineView.prototype = {
var aggregatedStats = {};
var presentationChildren = presentationRecord.presentationChildren();
for (var i = 0; i < presentationChildren.length; ++i)
WebInspector.TimelineUIUtils.aggregateTimeForRecord(aggregatedStats, presentationChildren[i].record());
WebInspector.TimelineUIUtils.aggregateTimeForRecord(aggregatedStats, this._model, presentationChildren[i].record());
var idle = presentationRecord.endTime() - presentationRecord.startTime();
for (var category in aggregatedStats)
idle -= aggregatedStats[category];
......@@ -658,13 +658,15 @@ WebInspector.TimelineView.prototype = {
if (task.startTime() > endTime)
break;
var data = task.traceEvent().args["data"];
var foreign = data && data["foreign"];
var left = Math.max(0, this._calculator.computePosition(task.startTime()) + barOffset - widthAdjustment);
var right = Math.min(width, this._calculator.computePosition(task.endTime() || 0) + barOffset + widthAdjustment);
if (lastElement) {
var gap = Math.floor(left) - Math.ceil(lastRight);
if (gap < minGap) {
if (!task.data["foreign"])
if (!foreign)
lastElement.classList.remove(foreignStyle);
lastRight = right;
lastElement._tasksInfo.lastTaskIndex = taskIndex;
......@@ -677,7 +679,7 @@ WebInspector.TimelineView.prototype = {
element = container.createChild("div", "timeline-graph-bar");
element.style.left = left + "px";
element._tasksInfo = {name: name, tasks: tasks, firstTaskIndex: taskIndex, lastTaskIndex: taskIndex};
if (task.data["foreign"])
if (foreign)
element.classList.add(foreignStyle);
lastLeft = left;
lastRight = right;
......
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