Commit 650bc7c5 authored by timothy@apple.com's avatar timothy@apple.com

Implement TimelineRecording and per-call-site timelines.

Keep track of timeline records per global timeline and per source code location.
This will be used to display them in the UI in later patches.

https://bugs.webkit.org/show_bug.cgi?id=123367

Reviewed by Joseph Pecoraro.

* UserInterface/Main.html:
* UserInterface/SourceCodeTimeline.js: Added.
(WebInspector.SourceCodeTimeline):
(WebInspector.SourceCodeTimeline.prototype.get sourceCode):
(WebInspector.SourceCodeTimeline.prototype.get sourceCodeLocation):
(WebInspector.SourceCodeTimeline.prototype.get recordType):
(WebInspector.SourceCodeTimeline.prototype.get recordEventType):
* UserInterface/Timeline.js: Added.
(WebInspector.Timeline):
(WebInspector.Timeline.prototype.get records):
(WebInspector.Timeline.prototype.addRecord):
* UserInterface/TimelineRecording.js:
(WebInspector.TimelineRecording):
(WebInspector.TimelineRecording.prototype.get timelines): Added.
(WebInspector.TimelineRecording.prototype.sourceCodeTimelinesForSourceCode): Added.
(WebInspector.TimelineRecording.prototype.addEventMarker): Implemented.
(WebInspector.TimelineRecording.prototype.addRecord): Implemented.
(WebInspector.TimelineRecording.prototype._keyForRecord): Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@162401 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent bde56d6d
2013-10-25 Timothy Hatcher <timothy@apple.com>
Implement TimelineRecording and per-call-site timelines.
Keep track of timeline records per global timeline and per source code location.
This will be used to display them in the UI in later patches.
https://bugs.webkit.org/show_bug.cgi?id=123367
Reviewed by Joseph Pecoraro.
* UserInterface/Main.html:
* UserInterface/SourceCodeTimeline.js: Added.
(WebInspector.SourceCodeTimeline):
(WebInspector.SourceCodeTimeline.prototype.get sourceCode):
(WebInspector.SourceCodeTimeline.prototype.get sourceCodeLocation):
(WebInspector.SourceCodeTimeline.prototype.get recordType):
(WebInspector.SourceCodeTimeline.prototype.get recordEventType):
* UserInterface/Timeline.js: Added.
(WebInspector.Timeline):
(WebInspector.Timeline.prototype.get records):
(WebInspector.Timeline.prototype.addRecord):
* UserInterface/TimelineRecording.js:
(WebInspector.TimelineRecording):
(WebInspector.TimelineRecording.prototype.get timelines): Added.
(WebInspector.TimelineRecording.prototype.sourceCodeTimelinesForSourceCode): Added.
(WebInspector.TimelineRecording.prototype.addEventMarker): Implemented.
(WebInspector.TimelineRecording.prototype.addRecord): Implemented.
(WebInspector.TimelineRecording.prototype._keyForRecord): Added.
2013-10-25 Timothy Hatcher <timothy@apple.com>
Add support for multiple Timeline recordings.
......
......@@ -187,6 +187,8 @@
<script src="TimelineObserver.js"></script>
<script src="TimelineManager.js"></script>
<script src="TimelineRecording.js"></script>
<script src="Timeline.js"></script>
<script src="SourceCodeTimeline.js"></script>
<script src="TimelineRecord.js"></script>
<script src="TimelineEventMarker.js"></script>
<script src="ResourceTimelineRecord.js"></script>
......
/*
* Copyright (C) 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
WebInspector.SourceCodeTimeline = function(sourceCode, sourceCodeLocation, recordType, recordEventType)
{
WebInspector.Timeline.call(this);
console.assert(sourceCode);
console.assert(recordType);
this._sourceCode = sourceCode;
this._sourceCodeLocation = sourceCodeLocation || null;
this._recordType = recordType;
this._recordEventType = recordEventType || null;
};
WebInspector.SourceCodeTimeline.prototype = {
constructor: WebInspector.SourceCodeTimeline,
__proto__: WebInspector.Timeline.prototype,
// Public
get sourceCode()
{
return this._sourceCode;
},
get sourceCodeLocation()
{
return this._sourceCodeLocation;
},
get recordType()
{
return this._recordType;
},
get recordEventType()
{
return this._recordEventType;
}
};
/*
* Copyright (C) 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
WebInspector.Timeline = function()
{
WebInspector.Object.call(this);
this._records = [];
};
WebInspector.Timeline.prototype = {
constructor: WebInspector.Timeline,
__proto__: WebInspector.Object.prototype,
// Public
get records()
{
return this._records;
},
addRecord: function(record)
{
this._records.push(record);
}
};
......@@ -26,6 +26,13 @@
WebInspector.TimelineRecording = function()
{
WebInspector.Object.call(this);
this.reset(true);
};
WebInspector.TimelineRecording.Event = {
Reset: "timeline-recording-reset",
SourceCodeTimelineAdded: "timeline-recording-source-code-timeline-added"
};
WebInspector.TimelineRecording.prototype = {
......@@ -34,13 +41,91 @@ WebInspector.TimelineRecording.prototype = {
// Public
get timelines()
{
return this._timelines;
},
reset: function(newObject)
{
this._timelines = new Map;
this._timelines.set(WebInspector.TimelineRecord.Type.Network, new WebInspector.Timeline);
this._timelines.set(WebInspector.TimelineRecord.Type.Script, new WebInspector.Timeline);
this._timelines.set(WebInspector.TimelineRecord.Type.Layout, new WebInspector.Timeline);
this._sourceCodeTimelinesMap = new Map;
this._eventMarkers = [];
if (!newObject)
this.dispatchEventToListeners(WebInspector.TimelineRecording.Event.Reset);
},
sourceCodeTimelinesForSourceCode: function(sourceCode)
{
var timelines = this._sourceCodeTimelinesMap.get(sourceCode);
if (!timelines)
return [];
var result = [];
// FIXME: This could use a for..of loop once they are supported on Maps.
timelines.forEach(function(sourceCodeTimeline) {
result.push(sourceCodeTimeline);
});
return result;
},
addEventMarker: function(eventMarker)
{
// FIXME: Implement.
this._eventMarkers.push(eventMarker);
},
addRecord: function(record)
{
// FIXME: Implement.
// Add the record to the global timeline by type.
this._timelines.get(record.type).addRecord(record);
// Netowrk records don't have source code timelines.
if (record.type === WebInspector.TimelineRecord.Type.Network)
return;
// Add the record to the source code timelines.
var activeMainResource = WebInspector.frameResourceManager.mainFrame.provisionalMainResource || WebInspector.frameResourceManager.mainFrame.mainResource;
var sourceCode = record.sourceCodeLocation ? record.sourceCodeLocation.sourceCode : activeMainResource;
var sourceCodeTimelines = this._sourceCodeTimelinesMap.get(sourceCode);
if (!sourceCodeTimelines) {
sourceCodeTimelines = new Map;
this._sourceCodeTimelinesMap.set(sourceCode, sourceCodeTimelines);
}
var newTimeline = false;
var key = this._keyForRecord(record);
var sourceCodeTimeline = sourceCodeTimelines.get(key);
if (!sourceCodeTimeline) {
sourceCodeTimeline = new WebInspector.SourceCodeTimeline(sourceCode, record.sourceCodeLocation, record.type, record.eventType);
sourceCodeTimelines.set(key, sourceCodeTimeline);
newTimeline = true;
}
sourceCodeTimeline.addRecord(record);
if (newTimeline)
this.dispatchEventToListeners(WebInspector.TimelineRecording.Event.SourceCodeTimelineAdded, {sourceCodeTimeline: sourceCodeTimeline});
},
// Private
_keyForRecord: function(record)
{
var key = record.type;
if (record instanceof WebInspector.ScriptTimelineRecord || record instanceof WebInspector.LayoutTimelineRecord)
key += ":" + record.eventType;
if (record instanceof WebInspector.ScriptTimelineRecord && record.eventType === WebInspector.ScriptTimelineRecord.EventType.EventDispatched)
key += ":" + record.details;
if (record.sourceCodeLocation)
key += ":" + record.sourceCodeLocation.lineNumber + ":" + record.sourceCodeLocation.columnNumber;
return key;
}
};
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