Changeset 163141 in webkit


Ignore:
Timestamp:
Jan 30, 2014 5:35:01 PM (10 years ago)
Author:
timothy@apple.com
Message:

Add the model objects for the new Web Inspector profile data.

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

Reviewed by Joseph Pecoraro.

  • UserInterface/Main.html:
  • UserInterface/Profile.js: Added.

(WebInspector.Profile):
(WebInspector.Profile.prototype.get idleTime):
(WebInspector.Profile.prototype.get topDownRootNodes):
(WebInspector.Profile.prototype.get bottomUpRootNodes):

  • UserInterface/ProfileNode.js: Added.

(WebInspector.ProfileNode):
(WebInspector.ProfileNode.prototype.get id):
(WebInspector.ProfileNode.prototype.get type):
(WebInspector.ProfileNode.prototype.get functionName):
(WebInspector.ProfileNode.prototype.get sourceCodeLocation):
(WebInspector.ProfileNode.prototype.get startTime):
(WebInspector.ProfileNode.prototype.get endTime):
(WebInspector.ProfileNode.prototype.get selfTime):
(WebInspector.ProfileNode.prototype.get totalTime):
(WebInspector.ProfileNode.prototype.get calls):
(WebInspector.ProfileNode.prototype.get previousSibling):
(WebInspector.ProfileNode.prototype.get nextSibling):
(WebInspector.ProfileNode.prototype.get parentNode):
(WebInspector.ProfileNode.prototype.get childNodes):
(WebInspector.ProfileNode.prototype.totalTimeInRange):
(WebInspector.ProfileNode.prototype.computeCallInfoForTimeRange):
(WebInspector.ProfileNode.prototype.traverseNextProfileNode):
(WebInspector.ProfileNode.prototype.saveIdentityToCookie):
(WebInspector.ProfileNode.prototype.establishRelationships):

  • UserInterface/ProfileNodeCall.js: Added.

(WebInspector.ProfileNodeCall):
(WebInspector.ProfileNodeCall.prototype.get startTime):
(WebInspector.ProfileNodeCall.prototype.get totalTime):
(WebInspector.ProfileNodeCall.prototype.get endTime):
(WebInspector.ProfileNodeCall.prototype.establishRelationships):

  • UserInterface/TimelineManager.js:

(WebInspector.TimelineManager.prototype.eventRecorded.processRecord):
(WebInspector.TimelineManager.prototype.eventRecorded):
(WebInspector.TimelineManager.prototype._profileFromPayload.profileNodeFromPayload):
(WebInspector.TimelineManager.prototype._profileFromPayload.profileNodeCallFromPayload):
(WebInspector.TimelineManager.prototype._profileFromPayload):

Location:
trunk/Source/WebInspectorUI
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebInspectorUI/ChangeLog

    r163138 r163141  
     12014-01-30  Timothy Hatcher  <timothy@apple.com>
     2
     3        Add the model objects for the new Web Inspector profile data.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=127899
     6
     7        Reviewed by Joseph Pecoraro.
     8
     9        * UserInterface/Main.html:
     10        * UserInterface/Profile.js: Added.
     11        (WebInspector.Profile):
     12        (WebInspector.Profile.prototype.get idleTime):
     13        (WebInspector.Profile.prototype.get topDownRootNodes):
     14        (WebInspector.Profile.prototype.get bottomUpRootNodes):
     15        * UserInterface/ProfileNode.js: Added.
     16        (WebInspector.ProfileNode):
     17        (WebInspector.ProfileNode.prototype.get id):
     18        (WebInspector.ProfileNode.prototype.get type):
     19        (WebInspector.ProfileNode.prototype.get functionName):
     20        (WebInspector.ProfileNode.prototype.get sourceCodeLocation):
     21        (WebInspector.ProfileNode.prototype.get startTime):
     22        (WebInspector.ProfileNode.prototype.get endTime):
     23        (WebInspector.ProfileNode.prototype.get selfTime):
     24        (WebInspector.ProfileNode.prototype.get totalTime):
     25        (WebInspector.ProfileNode.prototype.get calls):
     26        (WebInspector.ProfileNode.prototype.get previousSibling):
     27        (WebInspector.ProfileNode.prototype.get nextSibling):
     28        (WebInspector.ProfileNode.prototype.get parentNode):
     29        (WebInspector.ProfileNode.prototype.get childNodes):
     30        (WebInspector.ProfileNode.prototype.totalTimeInRange):
     31        (WebInspector.ProfileNode.prototype.computeCallInfoForTimeRange):
     32        (WebInspector.ProfileNode.prototype.traverseNextProfileNode):
     33        (WebInspector.ProfileNode.prototype.saveIdentityToCookie):
     34        (WebInspector.ProfileNode.prototype.establishRelationships):
     35        * UserInterface/ProfileNodeCall.js: Added.
     36        (WebInspector.ProfileNodeCall):
     37        (WebInspector.ProfileNodeCall.prototype.get startTime):
     38        (WebInspector.ProfileNodeCall.prototype.get totalTime):
     39        (WebInspector.ProfileNodeCall.prototype.get endTime):
     40        (WebInspector.ProfileNodeCall.prototype.establishRelationships):
     41        * UserInterface/TimelineManager.js:
     42        (WebInspector.TimelineManager.prototype.eventRecorded.processRecord):
     43        (WebInspector.TimelineManager.prototype.eventRecorded):
     44        (WebInspector.TimelineManager.prototype._profileFromPayload.profileNodeFromPayload):
     45        (WebInspector.TimelineManager.prototype._profileFromPayload.profileNodeCallFromPayload):
     46        (WebInspector.TimelineManager.prototype._profileFromPayload):
     47
    1482014-01-26  Timothy Hatcher  <timothy@apple.com>
    249
  • trunk/Source/WebInspectorUI/UserInterface/Main.html

    r163138 r163141  
    202202    <script src="TimelineMarker.js"></script>
    203203    <script src="ResourceTimelineRecord.js"></script>
     204    <script src="Profile.js"></script>
     205    <script src="ProfileNode.js"></script>
     206    <script src="ProfileNodeCall.js"></script>
    204207    <script src="FrameResourceManager.js"></script>
    205208    <script src="IssueManager.js"></script>
  • trunk/Source/WebInspectorUI/UserInterface/TimelineManager.js

    r162420 r163141  
    208208                }
    209209
     210                var profile = null;
     211                if (recordPayload.data.profile)
     212                    profile = this._profileFromPayload(recordPayload.data.profile);
     213
    210214                switch (parentRecordPayload && parentRecordPayload.type) {
    211215                case TimelineAgent.EventType.TimerFire:
    212                     this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.TimerFired, startTime, endTime, callFrames, sourceCodeLocation, parentRecordPayload.data.timerId));
     216                    this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.TimerFired, startTime, endTime, callFrames, sourceCodeLocation, parentRecordPayload.data.timerId, profile));
    213217                    break;
    214218                default:
    215                     this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.ScriptEvaluated, startTime, endTime, callFrames, sourceCodeLocation, null));
     219                    this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.ScriptEvaluated, startTime, endTime, callFrames, sourceCodeLocation, null, profile));
    216220                    break;
    217221                }
     
    229233                if (!parentRecordPayload)
    230234                    break;
     235
     236                var profile = null;
     237                if (recordPayload.data.profile)
     238                    profile = this._profileFromPayload(recordPayload.data.profile);
    231239
    232240                if (!sourceCodeLocation) {
     
    244252                switch (parentRecordPayload.type) {
    245253                case TimelineAgent.EventType.TimerFire:
    246                     this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.TimerFired, startTime, endTime, callFrames, sourceCodeLocation, parentRecordPayload.data.timerId));
     254                    this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.TimerFired, startTime, endTime, callFrames, sourceCodeLocation, parentRecordPayload.data.timerId, profile));
    247255                    break;
    248256                case TimelineAgent.EventType.EventDispatch:
    249                     this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.EventDispatched, startTime, endTime, callFrames, sourceCodeLocation, parentRecordPayload.data.type));
     257                    this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.EventDispatched, startTime, endTime, callFrames, sourceCodeLocation, parentRecordPayload.data.type, profile));
    250258                    break;
    251259                case TimelineAgent.EventType.XHRLoad:
    252                     this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.EventDispatched, startTime, endTime, callFrames, sourceCodeLocation, "load"));
     260                    this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.EventDispatched, startTime, endTime, callFrames, sourceCodeLocation, "load", profile));
    253261                    break;
    254262                case TimelineAgent.EventType.XHRReadyStateChange:
    255                     this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.EventDispatched, startTime, endTime, callFrames, sourceCodeLocation, "readystatechange"));
     263                    this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.EventDispatched, startTime, endTime, callFrames, sourceCodeLocation, "readystatechange", profile));
    256264                    break;
    257265                case TimelineAgent.EventType.FireAnimationFrame:
    258                     this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.AnimationFrameFired, startTime, endTime, callFrames, sourceCodeLocation, parentRecordPayload.data.id));
     266                    this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.AnimationFrameFired, startTime, endTime, callFrames, sourceCodeLocation, parentRecordPayload.data.id, profile));
    259267                    break;
    260268                }
     
    321329    // Private
    322330
     331    _profileFromPayload: function(payload)
     332    {
     333        if (!payload)
     334            return null;
     335
     336        console.assert(payload.rootNodes instanceof Array);
     337
     338        function profileNodeFromPayload(nodePayload)
     339        {
     340            console.assert("id" in nodePayload);
     341            console.assert(nodePayload.calls instanceof Array);
     342
     343            if (nodePayload.url) {
     344                var sourceCode = WebInspector.frameResourceManager.resourceForURL(nodePayload.url);
     345                if (!sourceCode)
     346                    sourceCode = WebInspector.debuggerManager.scriptsForURL(nodePayload.url)[0];
     347
     348                // The lineNumber is 1-based, but we expect 0-based.
     349                var lineNumber = nodePayload.lineNumber - 1;
     350
     351                var sourceCodeLocation = sourceCode ? sourceCode.createSourceCodeLocation(lineNumber, nodePayload.columnNumber) : null;
     352            }
     353
     354            var isProgramCode = nodePayload.functionName === "(program)";
     355            var isAnonymousFunction = nodePayload.functionName === "(anonymous function)";
     356
     357            var type = isProgramCode ? WebInspector.ProfileNode.Type.Program : WebInspector.ProfileNode.Type.Function;
     358            var functionName = !isProgramCode && !isAnonymousFunction && nodePayload.functionName !== "(unknown)" ? nodePayload.functionName : null;
     359            var calls = nodePayload.calls.map(profileNodeCallFromPayload);
     360
     361            return new WebInspector.ProfileNode(nodePayload.id, type, functionName, sourceCodeLocation, calls, nodePayload.children);
     362        }
     363
     364        function profileNodeCallFromPayload(nodeCallPayload)
     365        {
     366            console.assert("startTime" in nodeCallPayload);
     367            console.assert("totalTime" in nodeCallPayload);
     368
     369            return new WebInspector.ProfileNodeCall(nodeCallPayload.startTime, nodeCallPayload.totalTime);
     370        }
     371
     372        var rootNodes = payload.rootNodes;
     373
     374        // Iterate over the node tree using a stack. Doing this recursively can easily cause a stack overflow.
     375        // We traverse the profile in post-order and convert the payloads in place until we get back to the root.
     376        var stack = [{parent: {children: rootNodes}, index: 0, root: true}];
     377        while (stack.length) {
     378            var entry = stack.lastValue;
     379
     380            if (entry.index < entry.parent.children.length) {
     381                var childNodePayload = entry.parent.children[entry.index];
     382                if (childNodePayload.children && childNodePayload.children.length)
     383                    stack.push({parent: childNodePayload, index: 0});
     384
     385                ++entry.index;
     386            } else {
     387                if (!entry.root)
     388                    entry.parent.children = entry.parent.children.map(profileNodeFromPayload);
     389                else
     390                    rootNodes = rootNodes.map(profileNodeFromPayload);
     391
     392                stack.pop();
     393            }
     394        }
     395
     396        return new WebInspector.Profile(rootNodes, payload.idleTime);
     397    },
     398
    323399    _callFramesFromPayload: function(payload)
    324400    {
Note: See TracChangeset for help on using the changeset viewer.