Commit d002bcf3 authored by timothy@apple.com's avatar timothy@apple.com
Browse files

Track callFrames and sourceCodeLocation per TimelineRecord.

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

Reviewed by Joseph Pecoraro.

* UserInterface/LayoutTimelineRecord.js:
(WebInspector.LayoutTimelineRecord): Pass callFrames and sourceCodeLocation to superclass.
* UserInterface/ScriptTimelineRecord.js:
(WebInspector.ScriptTimelineRecord): Pass callFrames and sourceCodeLocation to superclass.
* UserInterface/TimelineManager.js:
(WebInspector.TimelineManager.prototype.eventRecorded.processRecord): Add "Payload" suffix to better track what is a protocol object.
Pass the callFrames and sourceCodeLocation to all the new TimelineRecords.
(WebInspector.TimelineManager.prototype.eventRecorded): Add "Payload" suffix.
* UserInterface/TimelineRecord.js:
(WebInspector.TimelineRecord):
(WebInspector.TimelineRecord.prototype.get callFrames): Added.
(WebInspector.TimelineRecord.prototype.get initiatorCallFrame): Added.
(WebInspector.TimelineRecord.prototype.get sourceCodeLocation): Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@162399 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent fd0f9339
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
2013-10-25  Timothy Hatcher  <timothy@apple.com>

        Track callFrames and sourceCodeLocation per TimelineRecord.

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

        Reviewed by Joseph Pecoraro.

        * UserInterface/LayoutTimelineRecord.js:
        (WebInspector.LayoutTimelineRecord): Pass callFrames and sourceCodeLocation to superclass.
        * UserInterface/ScriptTimelineRecord.js:
        (WebInspector.ScriptTimelineRecord): Pass callFrames and sourceCodeLocation to superclass.
        * UserInterface/TimelineManager.js:
        (WebInspector.TimelineManager.prototype.eventRecorded.processRecord): Add "Payload" suffix to better track what is a protocol object.
        Pass the callFrames and sourceCodeLocation to all the new TimelineRecords.
        (WebInspector.TimelineManager.prototype.eventRecorded): Add "Payload" suffix.
        * UserInterface/TimelineRecord.js:
        (WebInspector.TimelineRecord):
        (WebInspector.TimelineRecord.prototype.get callFrames): Added.
        (WebInspector.TimelineRecord.prototype.get initiatorCallFrame): Added.
        (WebInspector.TimelineRecord.prototype.get sourceCodeLocation): Added.

2013-10-25  Timothy Hatcher  <timothy@apple.com>

        Change how the load and content ready event timestamps are tracked.
+2 −23
Original line number Diff line number Diff line
@@ -23,9 +23,9 @@
 * THE POSSIBILITY OF SUCH DAMAGE.
 */

WebInspector.LayoutTimelineRecord = function(eventType, startTime, endTime, callFrames, x, y, width, height, quad)
WebInspector.LayoutTimelineRecord = function(eventType, startTime, endTime, callFrames, sourceCodeLocation, x, y, width, height, quad)
{
    WebInspector.TimelineRecord.call(this, WebInspector.TimelineRecord.Type.Layout, startTime, endTime);
    WebInspector.TimelineRecord.call(this, WebInspector.TimelineRecord.Type.Layout, startTime, endTime, callFrames, sourceCodeLocation);

    console.assert(eventType);

@@ -33,7 +33,6 @@ WebInspector.LayoutTimelineRecord = function(eventType, startTime, endTime, call
        eventType = WebInspector.LayoutTimelineRecord.EventType[eventType];

    this._eventType = eventType;
    this._callFrames = callFrames || [];
    this._x = typeof x === "number" ? x : NaN;
    this._y = typeof y === "number" ? y : NaN;
    this._width = typeof width === "number" ? width : NaN;
@@ -75,26 +74,6 @@ WebInspector.LayoutTimelineRecord.prototype = {
        return this._eventType;
    },

    get callFrames()
    {
        return this._callFrames;
    },

    get initiatorCallFrame()
    {
        if (!this._callFrames || !this._callFrames.length)
            return null;

        // Return the first non-native code call frame as the initiator.
        for (var i = 0; i < this._callFrames.length; ++i) {
            if (this._callFrames[i].nativeCode)
                continue;
            return this._callFrames[i];
        }

        return null;
    },

    get x()
    {
        return this._x;
+2 −52
Original line number Diff line number Diff line
@@ -23,9 +23,9 @@
 * THE POSSIBILITY OF SUCH DAMAGE.
 */

WebInspector.ScriptTimelineRecord = function(eventType, startTime, endTime, details, resource, lineNumber, callFrames)
WebInspector.ScriptTimelineRecord = function(eventType, startTime, endTime, callFrames, sourceCodeLocation, details)
{
    WebInspector.TimelineRecord.call(this, WebInspector.TimelineRecord.Type.Script, startTime, endTime);
    WebInspector.TimelineRecord.call(this, WebInspector.TimelineRecord.Type.Script, startTime, endTime, callFrames, sourceCodeLocation);

    console.assert(eventType);

@@ -34,9 +34,6 @@ WebInspector.ScriptTimelineRecord = function(eventType, startTime, endTime, deta

    this._eventType = eventType;
    this._details = details || "";
    this._resource = resource || null;
    this._lineNumber = lineNumber || NaN;
    this._callFrames = callFrames || null;
};

WebInspector.ScriptTimelineRecord.EventType = {
@@ -79,53 +76,6 @@ WebInspector.ScriptTimelineRecord.prototype = {
    get details()
    {
        return this._details;
    },

    get resource()
    {
        return this._resource;
    },

    get lineNumber()
    {
        return this._lineNumber;
    },

    get callFrames()
    {
        return this._callFrames;
    },

    get sourceCodeLocation()
    {
        if ("_sourceCodeLocation" in this)
            return this._sourceCodeLocation;

        if (!this._resource) {
            this._sourceCodeLocation = null;
            return this._sourceCodeLocation;
        }

        // FIXME: Script Timeline Events with a location should always contain a call stack
        // or a complete (url:line:column) triplet.

        if (this._callFrames) {
            for (var i = 0; i < this._callFrames.length; ++i) {
                var callFrame = this._callFrames[i];
                if (callFrame.nativeCode)
                    continue;

                if (!callFrame.sourceCodeLocation)
                    break;

                this._sourceCodeLocation = callFrame.sourceCodeLocation;
                return this._sourceCodeLocation;
            }
        }

        var lineNumber = isNaN(this._lineNumber) ? 0 : this._lineNumber;
        this._sourceCodeLocation = this._resource.createSourceCodeLocation(lineNumber, 0);
        return this._sourceCodeLocation;
    }
};

+60 −62
Original line number Diff line number Diff line
@@ -91,22 +91,34 @@ WebInspector.TimelineManager.prototype = {
        this.dispatchEventToListeners(WebInspector.TimelineManager.Event.RecordingStopped);
    },

    eventRecorded: function(originalRecord)
    eventRecorded: function(originalRecordPayload)
    {
        // Called from WebInspector.TimelineObserver.

        if (!this._recording)
            return;

        function processRecord(record, parentRecord)
        function processRecord(recordPayload, parentRecordPayload)
        {
            // Convert the timestamps to seconds to match the resource timestamps.
            var startTime = record.startTime / 1000;
            var endTime = record.endTime / 1000;
            var startTime = recordPayload.startTime / 1000;
            var endTime = recordPayload.endTime / 1000;

            var callFrames = this._callFramesFromPayload(record.stackTrace);
            var callFrames = this._callFramesFromPayload(recordPayload.stackTrace);

            switch (record.type) {
            var significantCallFrame = null;
            if (callFrames) {
                for (var i = 0; i < callFrames.length; ++i) {
                    if (callFrames[i].nativeCode)
                        continue;
                    significantCallFrame = callFrames[i];
                    break;
                }
            }

            var sourceCodeLocation = significantCallFrame && significantCallFrame.sourceCodeLocation;

            switch (recordPayload.type) {
            case TimelineAgent.EventType.MarkLoad:
                console.assert(isNaN(endTime));

@@ -146,50 +158,58 @@ WebInspector.TimelineManager.prototype = {

            case TimelineAgent.EventType.ScheduleStyleRecalculation:
                console.assert(isNaN(endTime));

                // Pass the startTime as the endTime since this record type has no duration.
                this._addRecord(new WebInspector.LayoutTimelineRecord(WebInspector.LayoutTimelineRecord.EventType.InvalidateStyles, startTime, startTime, callFrames));
                this._addRecord(new WebInspector.LayoutTimelineRecord(WebInspector.LayoutTimelineRecord.EventType.InvalidateStyles, startTime, startTime, callFrames, sourceCodeLocation));
                break;

            case TimelineAgent.EventType.RecalculateStyles:
                this._addRecord(new WebInspector.LayoutTimelineRecord(WebInspector.LayoutTimelineRecord.EventType.RecalculateStyles, startTime, endTime, callFrames));
                this._addRecord(new WebInspector.LayoutTimelineRecord(WebInspector.LayoutTimelineRecord.EventType.RecalculateStyles, startTime, endTime, callFrames, sourceCodeLocation));
                break;

            case TimelineAgent.EventType.InvalidateLayout:
                console.assert(isNaN(endTime));

                // Pass the startTime as the endTime since this record type has no duration.
                this._addRecord(new WebInspector.LayoutTimelineRecord(WebInspector.LayoutTimelineRecord.EventType.InvalidateLayout, startTime, startTime, callFrames));
                this._addRecord(new WebInspector.LayoutTimelineRecord(WebInspector.LayoutTimelineRecord.EventType.InvalidateLayout, startTime, startTime, callFrames, sourceCodeLocation));
                break;

            case TimelineAgent.EventType.Layout:
                // COMPATIBILITY (iOS 6): Layout records did not contain area properties. This is not exposed via a quad "root".
                var quad = record.data.root ? new WebInspector.Quad(record.data.root) : null;
                var quad = recordPayload.data.root ? new WebInspector.Quad(recordPayload.data.root) : null;
                if (quad)
                    this._addRecord(new WebInspector.LayoutTimelineRecord(WebInspector.LayoutTimelineRecord.EventType.Layout, startTime, endTime, callFrames, quad.points[0].x, quad.points[0].y, quad.width, quad.height, quad));
                    this._addRecord(new WebInspector.LayoutTimelineRecord(WebInspector.LayoutTimelineRecord.EventType.Layout, startTime, endTime, callFrames, sourceCodeLocation, quad.points[0].x, quad.points[0].y, quad.width, quad.height, quad));
                else
                    this._addRecord(new WebInspector.LayoutTimelineRecord(WebInspector.LayoutTimelineRecord.EventType.Layout, startTime, endTime, callFrames));
                    this._addRecord(new WebInspector.LayoutTimelineRecord(WebInspector.LayoutTimelineRecord.EventType.Layout, startTime, endTime, callFrames, sourceCodeLocation));
                break;

            case TimelineAgent.EventType.Paint:
                // COMPATIBILITY (iOS 6): Paint records data contained x, y, width, height properties. This became a quad "clip".
                var quad = record.data.clip ? new WebInspector.Quad(record.data.clip) : null;
                var quad = recordPayload.data.clip ? new WebInspector.Quad(recordPayload.data.clip) : null;
                if (quad)
                    this._addRecord(new WebInspector.LayoutTimelineRecord(WebInspector.LayoutTimelineRecord.EventType.Paint, startTime, endTime, callFrames, null, null, quad.width, quad.height, quad));
                    this._addRecord(new WebInspector.LayoutTimelineRecord(WebInspector.LayoutTimelineRecord.EventType.Paint, startTime, endTime, callFrames, sourceCodeLocation, null, null, quad.width, quad.height, quad));
                else
                    this._addRecord(new WebInspector.LayoutTimelineRecord(WebInspector.LayoutTimelineRecord.EventType.Paint, startTime, endTime, callFrames, record.data.x, record.data.y, record.data.width, record.data.height));
                    this._addRecord(new WebInspector.LayoutTimelineRecord(WebInspector.LayoutTimelineRecord.EventType.Paint, startTime, endTime, callFrames, sourceCodeLocation, recordPayload.data.x, recordPayload.data.y, recordPayload.data.width, recordPayload.data.height));
                break;

            case TimelineAgent.EventType.EvaluateScript:
                var resource = WebInspector.frameResourceManager.resourceForURL(record.data.url);

                if (!sourceCodeLocation) {
                    var mainFrame = WebInspector.frameResourceManager.mainFrame;
                    var scriptResource = mainFrame.url === recordPayload.data.url ? mainFrame.mainResource : mainFrame.resourceForURL(recordPayload.data.url, true);
                    if (scriptResource) {
                        // The lineNumber is 1-based, but we expect 0-based.
                var lineNumber = record.data.lineNumber - 1;
                        var lineNumber = recordPayload.data.lineNumber - 1;

                        sourceCodeLocation = scriptResource.createSourceCodeLocation(lineNumber, 0);
                    }
                }

                switch (parent ? parent.type : null) {
                switch (parentRecordPayload && parentRecordPayload.type) {
                case TimelineAgent.EventType.TimerFire:
                    this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.TimerFired, startTime, endTime, parent.data.timerId, resource, lineNumber, callFrames));
                    this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.TimerFired, startTime, endTime, callFrames, sourceCodeLocation, parentRecordPayload.data.timerId));
                    break;
                default:
                    this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.ScriptEvaluated, startTime, endTime, null, resource, lineNumber, callFrames));
                    this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.ScriptEvaluated, startTime, endTime, callFrames, sourceCodeLocation, null));
                    break;
                }

@@ -204,29 +224,24 @@ WebInspector.TimelineManager.prototype = {
            case TimelineAgent.EventType.FunctionCall:
                // FunctionCall always happens as a child of another record, and since the FunctionCall record
                // has useful info we just make the timeline record here (combining the data from both records).
                if (!parent)
                if (!parentRecordPayload)
                    break;

                var resource = WebInspector.frameResourceManager.resourceForURL(record.data.scriptName);

                // The scriptLine is 1-based, but we expect 0-based.
                var lineNumber = record.data.scriptLine - 1;

                switch (parent.type) {
                switch (parentRecordPayload.type) {
                case TimelineAgent.EventType.TimerFire:
                    this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.TimerFired, startTime, endTime, parent.data.timerId, resource, lineNumber, callFrames));
                    this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.TimerFired, startTime, endTime, callFrames, sourceCodeLocation, parentRecordPayload.data.timerId));
                    break;
                case TimelineAgent.EventType.EventDispatch:
                    this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.EventDispatched, startTime, endTime, parent.data.type, resource, lineNumber, callFrames));
                    this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.EventDispatched, startTime, endTime, callFrames, sourceCodeLocation, parentRecordPayload.data.type));
                    break;
                case TimelineAgent.EventType.XHRLoad:
                    this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.EventDispatched, startTime, endTime, "load", resource, lineNumber, callFrames));
                    this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.EventDispatched, startTime, endTime, callFrames, sourceCodeLocation, "load"));
                    break;
                case TimelineAgent.EventType.XHRReadyStateChange:
                    this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.EventDispatched, startTime, endTime, "readystatechange", resource, lineNumber, callFrames));
                    this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.EventDispatched, startTime, endTime, callFrames, sourceCodeLocation, "readystatechange"));
                    break;
                case TimelineAgent.EventType.FireAnimationFrame:
                    this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.AnimationFrameFired, startTime, endTime, parent.data.id, resource, lineNumber, callFrames));
                    this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.AnimationFrameFired, startTime, endTime, callFrames, sourceCodeLocation, parentRecordPayload.data.id));
                    break;
                }

@@ -234,47 +249,30 @@ WebInspector.TimelineManager.prototype = {

            case TimelineAgent.EventType.TimerInstall:
            case TimelineAgent.EventType.TimerRemove:
                // COMPATIBILITY (iOS 6): TimerInstall and TimerRemove did not have a stack trace.
                var callFrame = null;
                if (callFrames) {
                    for (var i = 0; i < callFrames.length; ++i) {
                        if (callFrames[i].nativeCode)
                            continue;
                        callFrame = callFrames[i];
                        break;
                    }
                }

                var sourceCodeLocation = callFrame && callFrame.sourceCodeLocation;
                var resource = sourceCodeLocation ? sourceCodeLocation.sourceCode : null;
                var lineNumber = sourceCodeLocation ? sourceCodeLocation.lineNumber : null;

                if (record.type === TimelineAgent.EventType.TimerInstall)
                    this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.TimerInstalled, startTime, endTime, record.data.timerId, resource, lineNumber, callFrames));
                if (recordPayload.type === TimelineAgent.EventType.TimerInstall)
                    this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.TimerInstalled, startTime, endTime, callFrames, sourceCodeLocation, recordPayload.data.timerId));
                else
                    this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.TimerRemoved, startTime, endTime, record.data.timerId, resource, lineNumber, callFrames));
                    this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.TimerRemoved, startTime, endTime, callFrames, sourceCodeLocation, recordPayload.data.timerId));

                break;
            }

            return null;
        }

        // Iterate over the records tree using a stack. Doing this recursively has
        // been known to cause a call stack overflow. https://webkit.org/b/79106
        var stack = [{array: [originalRecord], parent: null, index: 0}];
        var stack = [{array: [originalRecordPayload], parent: null, index: 0}];
        while (stack.length) {
            var entry = stack.lastValue;
            var records = entry.array;
            var parent = entry.parent;
            var recordPayloads = entry.array;
            var parentRecordPayload = entry.parent;

            if (entry.index < records.length) {
                var record = records[entry.index];
            if (entry.index < recordPayloads.length) {
                var recordPayload = recordPayloads[entry.index];

                processRecord.call(this, record, parent);
                processRecord.call(this, recordPayload, parentRecordPayload);

                if (record.children)
                    stack.push({array: record.children, parent: record, index: 0});
                if (recordPayload.children)
                    stack.push({array: recordPayload.children, parent: recordPayload, index: 0});
                ++entry.index;
            } else
                stack.pop();
+28 −1
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@
 * THE POSSIBILITY OF SUCH DAMAGE.
 */

WebInspector.TimelineRecord = function(type, startTime, endTime)
WebInspector.TimelineRecord = function(type, startTime, endTime, callFrames, sourceCodeLocation)
{
    WebInspector.Object.call(this);

@@ -35,6 +35,8 @@ WebInspector.TimelineRecord = function(type, startTime, endTime)
    this._type = type;
    this._startTime = startTime || NaN;
    this._endTime = endTime || NaN;
    this._callFrames = callFrames || null;
    this._sourceCodeLocation = sourceCodeLocation || null;
};

WebInspector.TimelineRecord.Event = {
@@ -83,6 +85,31 @@ WebInspector.TimelineRecord.prototype = {
    {
        // Implemented by subclasses if needed.
        return this.duration;
    },

    get callFrames()
    {
        return this._callFrames;
    },

    get initiatorCallFrame()
    {
        if (!this._callFrames || !this._callFrames.length)
            return null;

        // Return the first non-native code call frame as the initiator.
        for (var i = 0; i < this._callFrames.length; ++i) {
            if (this._callFrames[i].nativeCode)
                continue;
            return this._callFrames[i];
        }

        return null;
    },

    get sourceCodeLocation()
    {
        return this._sourceCodeLocation;
    }
};