Diff
Modified: trunk/Source/WebInspectorUI/ChangeLog (163140 => 163141)
--- trunk/Source/WebInspectorUI/ChangeLog 2014-01-31 01:34:54 UTC (rev 163140)
+++ trunk/Source/WebInspectorUI/ChangeLog 2014-01-31 01:35:01 UTC (rev 163141)
@@ -1,3 +1,50 @@
+2014-01-30 Timothy Hatcher <[email protected]>
+
+ 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):
+
2014-01-26 Timothy Hatcher <[email protected]>
Prefix existing Web Inspector profiler classes with "Legacy".
Modified: trunk/Source/WebInspectorUI/UserInterface/Main.html (163140 => 163141)
--- trunk/Source/WebInspectorUI/UserInterface/Main.html 2014-01-31 01:34:54 UTC (rev 163140)
+++ trunk/Source/WebInspectorUI/UserInterface/Main.html 2014-01-31 01:35:01 UTC (rev 163141)
@@ -201,6 +201,9 @@
<script src=""
<script src=""
<script src=""
+ <script src=""
+ <script src=""
+ <script src=""
<script src=""
<script src=""
<script src=""
Added: trunk/Source/WebInspectorUI/UserInterface/Profile.js (0 => 163141)
--- trunk/Source/WebInspectorUI/UserInterface/Profile.js (rev 0)
+++ trunk/Source/WebInspectorUI/UserInterface/Profile.js 2014-01-31 01:35:01 UTC (rev 163141)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2014 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.Profile = "" idleTime)
+{
+ WebInspector.Object.call(this);
+
+ topDownRootNodes = topDownRootNodes || [];
+
+ console.assert(topDownRootNodes instanceof Array);
+ console.assert(topDownRootNodes.reduce(function(previousValue, node) { return previousValue && node instanceof WebInspector.ProfileNode; }, true));
+
+ this._topDownRootNodes = topDownRootNodes;
+ this._idleTime = idleTime || 0;
+};
+
+WebInspector.Profile.prototype = {
+ constructor: WebInspector.Profile,
+ __proto__: WebInspector.Object.prototype,
+
+ // Public
+
+ get idleTime()
+ {
+ return this._idleTime;
+ },
+
+ get topDownRootNodes()
+ {
+ return this._topDownRootNodes;
+ },
+
+ get bottomUpRootNodes()
+ {
+ // FIXME: Implement.
+ return [];
+ }
+};
Added: trunk/Source/WebInspectorUI/UserInterface/ProfileNode.js (0 => 163141)
--- trunk/Source/WebInspectorUI/UserInterface/ProfileNode.js (rev 0)
+++ trunk/Source/WebInspectorUI/UserInterface/ProfileNode.js 2014-01-31 01:35:01 UTC (rev 163141)
@@ -0,0 +1,220 @@
+/*
+ * Copyright (C) 2014 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.ProfileNode = function(id, type, functionName, sourceCodeLocation, calls, childNodes)
+{
+ WebInspector.Object.call(this);
+
+ childNodes = childNodes || [];
+
+ console.assert(id);
+ console.assert(calls instanceof Array);
+ console.assert(calls.length >= 1);
+ console.assert(calls.reduce(function(previousValue, call) { return previousValue && call instanceof WebInspector.ProfileNodeCall; }, true));
+ console.assert(childNodes instanceof Array);
+ console.assert(childNodes.reduce(function(previousValue, node) { return previousValue && node instanceof WebInspector.ProfileNode; }, true));
+
+ this._id = id;
+ this._type = type || WebInspector.ProfileNode.Type.Function;
+ this._functionName = functionName || null;
+ this._sourceCodeLocation = sourceCodeLocation || null;
+ this._calls = calls;
+ this._childNodes = childNodes;
+ this._parentNode = null;
+ this._previousSibling = null;
+ this._nextSibling = null;
+
+ for (var i = 0; i < this._childNodes.length; ++i)
+ this._childNodes[i].establishRelationships(this, this._childNodes[i - 1], this._childNodes[i + 1]);
+
+ for (var i = 0; i < this._calls.length; ++i)
+ this._calls[i].establishRelationships(this, this._calls[i - 1], this._calls[i + 1]);
+
+ var info = this.computeCallInfoForTimeRange(0, Infinity);
+ this._startTime = info.startTime;
+ this._endTime = info.endTime;
+ this._selfTime = info.selfTime;
+ this._totalTime = info.totalTime;
+};
+
+WebInspector.ProfileNode.Type = {
+ Function: "profile-node-type-function",
+ Program: "profile-node-type-program"
+};
+
+WebInspector.ProfileNode.TypeIdentifier = "profile-node";
+WebInspector.ProfileNode.TypeCookieKey = "profile-node-type";
+WebInspector.ProfileNode.FunctionNameCookieKey = "profile-node-function-name";
+WebInspector.ProfileNode.SourceCodeURLCookieKey = "profile-node-source-code-url";
+WebInspector.ProfileNode.SourceCodeLocationLineCookieKey = "profile-node-source-code-location-line";
+WebInspector.ProfileNode.SourceCodeLocationColumnCookieKey = "profile-node-source-code-location-column";
+
+WebInspector.ProfileNode.prototype = {
+ constructor: WebInspector.ProfileNode,
+ __proto__: WebInspector.Object.prototype,
+
+ // Public
+
+ get id()
+ {
+ return this._id;
+ },
+
+ get type()
+ {
+ return this._type;
+ },
+
+ get functionName()
+ {
+ return this._functionName;
+ },
+
+ get sourceCodeLocation()
+ {
+ return this._sourceCodeLocation;
+ },
+
+ get startTime()
+ {
+ return this._startTime;
+ },
+
+ get endTime()
+ {
+ return this._endTime;
+ },
+
+ get selfTime()
+ {
+ return this._selfTime;
+ },
+
+ get totalTime()
+ {
+ return this._totalTime;
+ },
+
+ get calls()
+ {
+ return this._calls;
+ },
+
+ get previousSibling()
+ {
+ return this._previousSibling;
+ },
+
+ get nextSibling()
+ {
+ return this._nextSibling;
+ },
+
+ get parentNode()
+ {
+ return this._parentNode;
+ },
+
+ get childNodes()
+ {
+ return this._childNodes;
+ },
+
+ computeCallInfoForTimeRange: function(rangeStartTime, rangeEndTime)
+ {
+ rangeStartTime = !isNaN(rangeStartTime) ? rangeStartTime : 0;
+ rangeEndTime = !isNaN(rangeEndTime) ? rangeEndTime : Infinity;
+
+ var recordCallCount = true;
+ var callCount = 0;
+
+ function totalTimeInRange(previousValue, call)
+ {
+ if (rangeStartTime > call.endTime || rangeEndTime < call.startTime)
+ return previousValue;
+
+ if (recordCallCount)
+ ++callCount;
+
+ return previousValue + Math.min(call.endTime, rangeEndTime) - Math.max(rangeStartTime, call.startTime);
+ }
+
+ var startTime = Math.max(rangeStartTime, this._calls[0].startTime);
+ var endTime = Math.min(this._calls.lastValue.endTime, rangeEndTime);
+ var totalTime = this._calls.reduce(totalTimeInRange, 0);
+
+ recordCallCount = false;
+
+ var childNodesTotalTime = 0;
+ for (var childNode of this._childNodes)
+ childNodesTotalTime += childNode.calls.reduce(totalTimeInRange, 0);
+
+ var selfTime = totalTime - childNodesTotalTime;
+ var averageTime = selfTime / callCount;
+
+ return {startTime: startTime, endTime: endTime, totalTime: totalTime, selfTime: selfTime, callCount: callCount, averageTime: averageTime};
+ },
+
+ traverseNextProfileNode: function(stayWithin)
+ {
+ var profileNode = this._childNodes[0];
+ if (profileNode)
+ return profileNode;
+
+ if (this === stayWithin)
+ return null;
+
+ profileNode = this._nextSibling;
+ if (profileNode)
+ return profileNode;
+
+ profileNode = this;
+ while (profileNode && !profileNode.nextSibling && profileNode.parentNode !== stayWithin)
+ profileNode = profileNode.parentNode;
+
+ if (!profileNode)
+ return null;
+
+ return profileNode.nextSibling;
+ },
+
+ saveIdentityToCookie: function(cookie)
+ {
+ cookie[WebInspector.ProfileNode.TypeCookieKey] = this._type || null;
+ cookie[WebInspector.ProfileNode.FunctionNameCookieKey] = this._functionName || null;
+ cookie[WebInspector.ProfileNode.SourceCodeURLCookieKey] = this._sourceCodeLocation ? this._sourceCodeLocation.sourceCode.url ? this._sourceCodeLocation.sourceCode.url.hash : null : null;
+ cookie[WebInspector.ProfileNode.SourceCodeLocationLineCookieKey] = this._sourceCodeLocation ? this._sourceCodeLocation.lineNumber : null;
+ cookie[WebInspector.ProfileNode.SourceCodeLocationColumnCookieKey] = this._sourceCodeLocation ? this._sourceCodeLocation.columnNumber : null;
+ },
+
+ // Protected
+
+ establishRelationships: function(parentNode, previousSibling, nextSibling)
+ {
+ this._parentNode = parentNode || null;
+ this._previousSibling = previousSibling || null;
+ this._nextSibling = nextSibling || null;
+ }
+};
Added: trunk/Source/WebInspectorUI/UserInterface/ProfileNodeCall.js (0 => 163141)
--- trunk/Source/WebInspectorUI/UserInterface/ProfileNodeCall.js (rev 0)
+++ trunk/Source/WebInspectorUI/UserInterface/ProfileNodeCall.js 2014-01-31 01:35:01 UTC (rev 163141)
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2014 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.ProfileNodeCall = function(startTime, totalTime)
+{
+ WebInspector.Object.call(this);
+
+ console.assert(startTime);
+
+ this._startTime = startTime;
+ this._totalTime = totalTime || 0;
+ this._parentNode = null;
+ this._previousSibling = null;
+ this._nextSibling = null;
+};
+
+WebInspector.ProfileNodeCall.prototype = {
+ constructor: WebInspector.ProfileNodeCall,
+ __proto__: WebInspector.Object.prototype,
+
+ // Public
+
+ get startTime()
+ {
+ return this._startTime;
+ },
+
+ get totalTime()
+ {
+ return this._totalTime;
+ },
+
+ get endTime()
+ {
+ return this._startTime + this._totalTime;
+ },
+
+ // Protected
+
+ establishRelationships: function(parentNode, previousSibling, nextSibling)
+ {
+ this._parentNode = parentNode || null;
+ this._previousSibling = previousSibling || null;
+ this._nextSibling = nextSibling || null;
+ }
+};
Modified: trunk/Source/WebInspectorUI/UserInterface/TimelineManager.js (163140 => 163141)
--- trunk/Source/WebInspectorUI/UserInterface/TimelineManager.js 2014-01-31 01:34:54 UTC (rev 163140)
+++ trunk/Source/WebInspectorUI/UserInterface/TimelineManager.js 2014-01-31 01:35:01 UTC (rev 163141)
@@ -207,12 +207,16 @@
}
}
+ var profile = ""
+ if (recordPayload.data.profile)
+ profile = ""
+
switch (parentRecordPayload && parentRecordPayload.type) {
case TimelineAgent.EventType.TimerFire:
- this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.TimerFired, startTime, endTime, callFrames, sourceCodeLocation, parentRecordPayload.data.timerId));
+ this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.TimerFired, startTime, endTime, callFrames, sourceCodeLocation, parentRecordPayload.data.timerId, profile));
break;
default:
- this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.ScriptEvaluated, startTime, endTime, callFrames, sourceCodeLocation, null));
+ this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.ScriptEvaluated, startTime, endTime, callFrames, sourceCodeLocation, null, profile));
break;
}
@@ -229,6 +233,10 @@
if (!parentRecordPayload)
break;
+ var profile = ""
+ if (recordPayload.data.profile)
+ profile = ""
+
if (!sourceCodeLocation) {
var mainFrame = WebInspector.frameResourceManager.mainFrame;
var scriptResource = mainFrame.url ="" recordPayload.data.scriptName ? mainFrame.mainResource : mainFrame.resourceForURL(recordPayload.data.scriptName, true);
@@ -243,19 +251,19 @@
switch (parentRecordPayload.type) {
case TimelineAgent.EventType.TimerFire:
- this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.TimerFired, startTime, endTime, callFrames, sourceCodeLocation, parentRecordPayload.data.timerId));
+ this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.TimerFired, startTime, endTime, callFrames, sourceCodeLocation, parentRecordPayload.data.timerId, profile));
break;
case TimelineAgent.EventType.EventDispatch:
- this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.EventDispatched, startTime, endTime, callFrames, sourceCodeLocation, parentRecordPayload.data.type));
+ this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.EventDispatched, startTime, endTime, callFrames, sourceCodeLocation, parentRecordPayload.data.type, profile));
break;
case TimelineAgent.EventType.XHRLoad:
- this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.EventDispatched, startTime, endTime, callFrames, sourceCodeLocation, "load"));
+ this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.EventDispatched, startTime, endTime, callFrames, sourceCodeLocation, "load", profile));
break;
case TimelineAgent.EventType.XHRReadyStateChange:
- this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.EventDispatched, startTime, endTime, callFrames, sourceCodeLocation, "readystatechange"));
+ this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.EventDispatched, startTime, endTime, callFrames, sourceCodeLocation, "readystatechange", profile));
break;
case TimelineAgent.EventType.FireAnimationFrame:
- this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.AnimationFrameFired, startTime, endTime, callFrames, sourceCodeLocation, parentRecordPayload.data.id));
+ this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.AnimationFrameFired, startTime, endTime, callFrames, sourceCodeLocation, parentRecordPayload.data.id, profile));
break;
}
@@ -320,6 +328,74 @@
// Private
+ _profileFromPayload: function(payload)
+ {
+ if (!payload)
+ return null;
+
+ console.assert(payload.rootNodes instanceof Array);
+
+ function profileNodeFromPayload(nodePayload)
+ {
+ console.assert("id" in nodePayload);
+ console.assert(nodePayload.calls instanceof Array);
+
+ if (nodePayload.url) {
+ var sourceCode = WebInspector.frameResourceManager.resourceForURL(nodePayload.url);
+ if (!sourceCode)
+ sourceCode = WebInspector.debuggerManager.scriptsForURL(nodePayload.url)[0];
+
+ // The lineNumber is 1-based, but we expect 0-based.
+ var lineNumber = nodePayload.lineNumber - 1;
+
+ var sourceCodeLocation = sourceCode ? sourceCode.createSourceCodeLocation(lineNumber, nodePayload.columnNumber) : null;
+ }
+
+ var isProgramCode = nodePayload.functionName === "(program)";
+ var isAnonymousFunction = nodePayload.functionName === "(anonymous function)";
+
+ var type = isProgramCode ? WebInspector.ProfileNode.Type.Program : WebInspector.ProfileNode.Type.Function;
+ var functionName = !isProgramCode && !isAnonymousFunction && nodePayload.functionName !== "(unknown)" ? nodePayload.functionName : null;
+ var calls = nodePayload.calls.map(profileNodeCallFromPayload);
+
+ return new WebInspector.ProfileNode(nodePayload.id, type, functionName, sourceCodeLocation, calls, nodePayload.children);
+ }
+
+ function profileNodeCallFromPayload(nodeCallPayload)
+ {
+ console.assert("startTime" in nodeCallPayload);
+ console.assert("totalTime" in nodeCallPayload);
+
+ return new WebInspector.ProfileNodeCall(nodeCallPayload.startTime, nodeCallPayload.totalTime);
+ }
+
+ var rootNodes = payload.rootNodes;
+
+ // Iterate over the node tree using a stack. Doing this recursively can easily cause a stack overflow.
+ // We traverse the profile in post-order and convert the payloads in place until we get back to the root.
+ var stack = [{parent: {children: rootNodes}, index: 0, root: true}];
+ while (stack.length) {
+ var entry = stack.lastValue;
+
+ if (entry.index < entry.parent.children.length) {
+ var childNodePayload = entry.parent.children[entry.index];
+ if (childNodePayload.children && childNodePayload.children.length)
+ stack.push({parent: childNodePayload, index: 0});
+
+ ++entry.index;
+ } else {
+ if (!entry.root)
+ entry.parent.children = entry.parent.children.map(profileNodeFromPayload);
+ else
+ rootNodes = rootNodes.map(profileNodeFromPayload);
+
+ stack.pop();
+ }
+ }
+
+ return new WebInspector.Profile(rootNodes, payload.idleTime);
+ },
+
_callFramesFromPayload: function(payload)
{
if (!payload)