[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-10851-g50815da

mnaganov at chromium.org mnaganov at chromium.org
Wed Dec 22 17:45:13 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit af7ad7a66b7f85abbfc85e6ec871ac3b23b7ec89
Author: mnaganov at chromium.org <mnaganov at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Mon Nov 29 23:37:08 2010 +0000

    2010-11-29  Mikhail Naganov  <mnaganov at chromium.org>
    
            Reviewed by Pavel Feldman.
    
            WebInspector: Request JSON-serialized heap snapshot from JS engine.
            This simplifies heap snapshots interaction and API. Instead of
            having objects representing snapshot entities, the whole snapshot
            is transferred to WebInspector and parsed there.
    
            https://bugs.webkit.org/show_bug.cgi?id=49974
    
            * bindings/js/ScriptHeapSnapshot.h:
            (WebCore::ScriptHeapSnapshot::OutputStream::~OutputStream):
            (WebCore::ScriptHeapSnapshot::~ScriptHeapSnapshot):
            (WebCore::ScriptHeapSnapshot::writeJSON):
            (WebCore::ScriptHeapSnapshot::ScriptHeapSnapshot):
            * bindings/v8/ScriptHeapSnapshot.cpp:
            (WebCore::ScriptHeapSnapshot::writeJSON):
            * bindings/v8/ScriptHeapSnapshot.h:
            (WebCore::ScriptHeapSnapshot::OutputStream::~OutputStream):
            * inspector/Inspector.idl:
            * inspector/InspectorProfilerAgent.cpp:
            (WebCore::InspectorProfilerAgent::getProfile):
            * inspector/front-end/HeapSnapshotView.js:
            (WebInspector.HeapSnapshotEdgesIterator):
            (WebInspector.HeapSnapshotEdgesIterator.prototype.get done):
            (WebInspector.HeapSnapshotEdgesIterator.prototype.get isElement):
            (WebInspector.HeapSnapshotEdgesIterator.prototype.get isHidden):
            (WebInspector.HeapSnapshotEdgesIterator.prototype.get name):
            (WebInspector.HeapSnapshotEdgesIterator.prototype.next):
            (WebInspector.HeapSnapshotEdgesIterator.prototype.get node):
            (WebInspector.HeapSnapshotEdgesIterator.prototype.get nodeIndex):
            (WebInspector.HeapSnapshotEdgesIterator.prototype._getNameOrIndex):
            (WebInspector.HeapSnapshotEdgesIterator.prototype._getType):
            (WebInspector.HeapSnapshotNodeWrapper):
            (WebInspector.HeapSnapshotNodeWrapper.prototype.get edges):
            (WebInspector.HeapSnapshotNodeWrapper.prototype.get edgesCount):
            (WebInspector.HeapSnapshotNodeWrapper.prototype.get instancesCount):
            (WebInspector.HeapSnapshotNodeWrapper.prototype.get isHidden):
            (WebInspector.HeapSnapshotNodeWrapper.prototype.get name):
            (WebInspector.HeapSnapshotNodeWrapper.prototype.get selfSize):
            (WebInspector.HeapSnapshotNodeWrapper.prototype._getName):
            (WebInspector.HeapSnapshotNodeWrapper.prototype._getEdges):
            (WebInspector.HeapSnapshotNodeWrapper.prototype._getType):
            (WebInspector.HeapSnapshot):
            (WebInspector.HeapSnapshot.prototype._init):
            (WebInspector.HeapSnapshot.prototype.get rootEdges):
            (WebInspector.HeapSnapshotView.prototype.snapshotLoaded):
            (WebInspector.HeapSnapshotView.prototype._loadProfile.processLoadedSnapshot):
            (WebInspector.HeapSnapshotView.prototype._loadProfile):
            (WebInspector.HeapSnapshotView.prototype._convertSnapshot):
            (WebInspector.HeapSnapshotView.prototype._prepareProfile.mergeRetainers):
            (WebInspector.HeapSnapshotView.prototype._prepareProfile):
            (WebInspector.HeapSnapshotView.prototype._sortData):
            * inspector/front-end/ProfilesPanel.js:
            (WebInspector.ProfilesPanel):
            (WebInspector.ProfilesPanel.prototype.addHeapSnapshotChunk):
            (WebInspector.ProfilesPanel.prototype.finishHeapSnapshot):
            * inspector/front-end/inspector.js:
            (WebInspector.addHeapSnapshotChunk):
            (WebInspector.finishHeapSnapshot):
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@72843 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 40456bf..1b4c2f8 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,65 @@
+2010-11-29  Mikhail Naganov  <mnaganov at chromium.org>
+
+        Reviewed by Pavel Feldman.
+
+        WebInspector: Request JSON-serialized heap snapshot from JS engine.
+        This simplifies heap snapshots interaction and API. Instead of
+        having objects representing snapshot entities, the whole snapshot
+        is transferred to WebInspector and parsed there.
+
+        https://bugs.webkit.org/show_bug.cgi?id=49974
+
+        * bindings/js/ScriptHeapSnapshot.h:
+        (WebCore::ScriptHeapSnapshot::OutputStream::~OutputStream):
+        (WebCore::ScriptHeapSnapshot::~ScriptHeapSnapshot):
+        (WebCore::ScriptHeapSnapshot::writeJSON):
+        (WebCore::ScriptHeapSnapshot::ScriptHeapSnapshot):
+        * bindings/v8/ScriptHeapSnapshot.cpp:
+        (WebCore::ScriptHeapSnapshot::writeJSON):
+        * bindings/v8/ScriptHeapSnapshot.h:
+        (WebCore::ScriptHeapSnapshot::OutputStream::~OutputStream):
+        * inspector/Inspector.idl:
+        * inspector/InspectorProfilerAgent.cpp:
+        (WebCore::InspectorProfilerAgent::getProfile):
+        * inspector/front-end/HeapSnapshotView.js:
+        (WebInspector.HeapSnapshotEdgesIterator):
+        (WebInspector.HeapSnapshotEdgesIterator.prototype.get done):
+        (WebInspector.HeapSnapshotEdgesIterator.prototype.get isElement):
+        (WebInspector.HeapSnapshotEdgesIterator.prototype.get isHidden):
+        (WebInspector.HeapSnapshotEdgesIterator.prototype.get name):
+        (WebInspector.HeapSnapshotEdgesIterator.prototype.next):
+        (WebInspector.HeapSnapshotEdgesIterator.prototype.get node):
+        (WebInspector.HeapSnapshotEdgesIterator.prototype.get nodeIndex):
+        (WebInspector.HeapSnapshotEdgesIterator.prototype._getNameOrIndex):
+        (WebInspector.HeapSnapshotEdgesIterator.prototype._getType):
+        (WebInspector.HeapSnapshotNodeWrapper):
+        (WebInspector.HeapSnapshotNodeWrapper.prototype.get edges):
+        (WebInspector.HeapSnapshotNodeWrapper.prototype.get edgesCount):
+        (WebInspector.HeapSnapshotNodeWrapper.prototype.get instancesCount):
+        (WebInspector.HeapSnapshotNodeWrapper.prototype.get isHidden):
+        (WebInspector.HeapSnapshotNodeWrapper.prototype.get name):
+        (WebInspector.HeapSnapshotNodeWrapper.prototype.get selfSize):
+        (WebInspector.HeapSnapshotNodeWrapper.prototype._getName):
+        (WebInspector.HeapSnapshotNodeWrapper.prototype._getEdges):
+        (WebInspector.HeapSnapshotNodeWrapper.prototype._getType):
+        (WebInspector.HeapSnapshot):
+        (WebInspector.HeapSnapshot.prototype._init):
+        (WebInspector.HeapSnapshot.prototype.get rootEdges):
+        (WebInspector.HeapSnapshotView.prototype.snapshotLoaded):
+        (WebInspector.HeapSnapshotView.prototype._loadProfile.processLoadedSnapshot):
+        (WebInspector.HeapSnapshotView.prototype._loadProfile):
+        (WebInspector.HeapSnapshotView.prototype._convertSnapshot):
+        (WebInspector.HeapSnapshotView.prototype._prepareProfile.mergeRetainers):
+        (WebInspector.HeapSnapshotView.prototype._prepareProfile):
+        (WebInspector.HeapSnapshotView.prototype._sortData):
+        * inspector/front-end/ProfilesPanel.js:
+        (WebInspector.ProfilesPanel):
+        (WebInspector.ProfilesPanel.prototype.addHeapSnapshotChunk):
+        (WebInspector.ProfilesPanel.prototype.finishHeapSnapshot):
+        * inspector/front-end/inspector.js:
+        (WebInspector.addHeapSnapshotChunk):
+        (WebInspector.finishHeapSnapshot):
+
 2010-11-29  Simon Fraser  <simon.fraser at apple.com>
 
         Reviewed by Dave Hyatt.
diff --git a/WebCore/bindings/js/ScriptHeapSnapshot.h b/WebCore/bindings/js/ScriptHeapSnapshot.h
index a9432ad..4c3d915 100644
--- a/WebCore/bindings/js/ScriptHeapSnapshot.h
+++ b/WebCore/bindings/js/ScriptHeapSnapshot.h
@@ -38,17 +38,22 @@ namespace WebCore {
 
 class ScriptHeapSnapshot : public RefCounted<ScriptHeapSnapshot> {
 public:
-    virtual ~ScriptHeapSnapshot() {}
+    class OutputStream {
+    public:
+        virtual ~OutputStream() { }
+        virtual void Write(const String& chunk) = 0;
+        virtual void Close() = 0;
+    };
+
+    virtual ~ScriptHeapSnapshot() { }
 
     String title() const { return ""; }
     unsigned int uid() const { return 0; }
 
-#if ENABLE(INSPECTOR)
-    PassRefPtr<InspectorObject> buildInspectorObjectForHead() const { return InspectorObject::create(); }
-#endif
+    void writeJSON(OutputStream*) { }
 
 private:
-    ScriptHeapSnapshot() {}
+    ScriptHeapSnapshot() { }
 };
 
 } // namespace WebCore
diff --git a/WebCore/bindings/v8/ScriptHeapSnapshot.cpp b/WebCore/bindings/v8/ScriptHeapSnapshot.cpp
index 885d039..c35d508 100644
--- a/WebCore/bindings/v8/ScriptHeapSnapshot.cpp
+++ b/WebCore/bindings/v8/ScriptHeapSnapshot.cpp
@@ -33,6 +33,7 @@
 
 #include "InspectorValues.h"
 #include "V8Binding.h"
+#include <v8.h>
 #include <v8-profiler.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefPtr.h>
@@ -50,50 +51,29 @@ unsigned int ScriptHeapSnapshot::uid() const
     return m_snapshot->GetUid();
 }
 
-static PassRefPtr<InspectorObject> buildInspectorObjectFor(const v8::HeapGraphNode* root)
-{
-    v8::HandleScope scope;
-    RefPtr<InspectorObject> result = InspectorObject::create();
-    RefPtr<InspectorObject> lowLevels = InspectorObject::create();
-    RefPtr<InspectorObject> entries = InspectorObject::create();
-    RefPtr<InspectorObject> children = InspectorObject::create();
-    for (int i = 0, count = root->GetChildrenCount(); i < count; ++i) {
-        const v8::HeapGraphNode* node = root->GetChild(i)->GetToNode();
-        if (node->GetType() == v8::HeapGraphNode::kInternal) {
-            RefPtr<InspectorObject> lowLevel = InspectorObject::create();
-            lowLevel->setNumber("count", node->GetInstancesCount());
-            lowLevel->setNumber("size", node->GetSelfSize());
-            lowLevel->setString("type", toWebCoreString(node->GetName()));
-            lowLevels->setObject(toWebCoreString(node->GetName()), lowLevel);
-        } else if (node->GetInstancesCount()) {
-            RefPtr<InspectorObject> entry = InspectorObject::create();
-            entry->setString("constructorName", toWebCoreString(node->GetName()));
-            entry->setNumber("count", node->GetInstancesCount());
-            entry->setNumber("size", node->GetSelfSize());
-            entries->setObject(toWebCoreString(node->GetName()), entry);
-        } else {
-            RefPtr<InspectorObject> entry = InspectorObject::create();
-            entry->setString("constructorName", toWebCoreString(node->GetName()));
-            for (int j = 0, count = node->GetChildrenCount(); j < count; ++j) {
-                const v8::HeapGraphEdge* v8Edge = node->GetChild(j);
-                const v8::HeapGraphNode* v8Child = v8Edge->GetToNode();
-                RefPtr<InspectorObject> child = InspectorObject::create();
-                child->setString("constructorName", toWebCoreString(v8Child->GetName()));
-                child->setNumber("count", v8Edge->GetName()->ToInteger()->Value());
-                entry->setObject(String::number(reinterpret_cast<unsigned long long>(v8Child)), child);
-            }
-            children->setObject(String::number(reinterpret_cast<unsigned long long>(node)), entry);
-        }
+namespace {
+
+class OutputStreamAdapter : public v8::OutputStream {
+public:
+    OutputStreamAdapter(ScriptHeapSnapshot::OutputStream* output)
+        : m_output(output) { }
+    void EndOfStream() { m_output->Close(); }
+    int GetChunkSize() { return 10240; }
+    WriteResult WriteAsciiChunk(char* data, int size)
+    {
+        m_output->Write(String(data, size));
+        return kContinue;
     }
-    result->setObject("lowlevels", lowLevels);
-    result->setObject("entries", entries);
-    result->setObject("children", children);
-    return result.release();
-}
+private:
+    ScriptHeapSnapshot::OutputStream* m_output;
+};
+
+} // namespace
 
-PassRefPtr<InspectorObject> ScriptHeapSnapshot::buildInspectorObjectForHead() const
+void ScriptHeapSnapshot::writeJSON(ScriptHeapSnapshot::OutputStream* stream)
 {
-    return buildInspectorObjectFor(m_snapshot->GetRoot());
+    OutputStreamAdapter outputStream(stream);
+    m_snapshot->Serialize(&outputStream, v8::HeapSnapshot::kJSON);
 }
 
 } // namespace WebCore
diff --git a/WebCore/bindings/v8/ScriptHeapSnapshot.h b/WebCore/bindings/v8/ScriptHeapSnapshot.h
index 794a5a9..d3ae022 100644
--- a/WebCore/bindings/v8/ScriptHeapSnapshot.h
+++ b/WebCore/bindings/v8/ScriptHeapSnapshot.h
@@ -43,6 +43,13 @@ class InspectorObject;
 
 class ScriptHeapSnapshot : public RefCounted<ScriptHeapSnapshot> {
 public:
+    class OutputStream {
+    public:
+        virtual ~OutputStream() { }
+        virtual void Write(const String& chunk) = 0;
+        virtual void Close() = 0;
+    };
+
     static PassRefPtr<ScriptHeapSnapshot> create(const v8::HeapSnapshot* snapshot)
     {
         return adoptRef(new ScriptHeapSnapshot(snapshot));
@@ -51,8 +58,7 @@ public:
 
     String title() const;
     unsigned int uid() const;
-
-    PassRefPtr<InspectorObject> buildInspectorObjectForHead() const;
+    void writeJSON(OutputStream* stream);
 
 private:
     ScriptHeapSnapshot(const v8::HeapSnapshot* snapshot)
diff --git a/WebCore/inspector/Inspector.idl b/WebCore/inspector/Inspector.idl
index e8086a6..6589127 100644
--- a/WebCore/inspector/Inspector.idl
+++ b/WebCore/inspector/Inspector.idl
@@ -58,10 +58,12 @@ module core {
 
 #if defined(ENABLE_JAVASCRIPT_DEBUGGER) && ENABLE_JAVASCRIPT_DEBUGGER
         [notify] void addProfileHeader(out Object header);
+        [notify] void addHeapSnapshotChunk(out unsigned long uid, out String chunk);
         [notify] void attachDebuggerWhenShown();
         [notify] void debuggerWasEnabled();
         [notify] void debuggerWasDisabled();
         [notify] void failedToParseScriptSource(out String url, out String data, out int firstLine, out int errorLine, out String errorMessage);
+        [notify] void finishHeapSnapshot(out unsigned long uid);
         [notify] void parsedScriptSource(out String sourceID, out String url, out String data, out int firstLine, out int scriptWorldType);
         [notify] void pausedScript(out Object details);
         [notify] void profilerWasEnabled();
diff --git a/WebCore/inspector/InspectorProfilerAgent.cpp b/WebCore/inspector/InspectorProfilerAgent.cpp
index 1248677..6d5364f 100644
--- a/WebCore/inspector/InspectorProfilerAgent.cpp
+++ b/WebCore/inspector/InspectorProfilerAgent.cpp
@@ -156,6 +156,21 @@ void InspectorProfilerAgent::getProfileHeaders(RefPtr<InspectorArray>* headers)
         (*headers)->pushObject(createSnapshotHeader(*it->second));
 }
 
+namespace {
+
+class OutputStream : public ScriptHeapSnapshot::OutputStream {
+public:
+    OutputStream(InspectorFrontend* frontend, unsigned long uid)
+        : m_frontend(frontend), m_uid(uid) { }
+    void Write(const String& chunk) { m_frontend->addHeapSnapshotChunk(m_uid, chunk); }
+    void Close() { m_frontend->finishHeapSnapshot(m_uid); }
+private:
+    InspectorFrontend* m_frontend;
+    unsigned long m_uid;
+};
+
+} // namespace
+
 void InspectorProfilerAgent::getProfile(const String& type, unsigned uid, RefPtr<InspectorObject>* profileObject)
 {
     if (type == CPUProfileType) {
@@ -167,8 +182,12 @@ void InspectorProfilerAgent::getProfile(const String& type, unsigned uid, RefPtr
     } else if (type == HeapProfileType) {
         HeapSnapshotsMap::iterator it = m_snapshots.find(uid);
         if (it != m_snapshots.end()) {
-            *profileObject = createSnapshotHeader(*it->second);
-            (*profileObject)->setObject("head", it->second->buildInspectorObjectForHead());
+            RefPtr<ScriptHeapSnapshot> snapshot = it->second;
+            *profileObject = createSnapshotHeader(*snapshot);
+            if (m_frontend) {
+                OutputStream stream(m_frontend, uid);
+                snapshot->writeJSON(&stream);
+            }
         }
     }
 }
diff --git a/WebCore/inspector/front-end/HeapSnapshotView.js b/WebCore/inspector/front-end/HeapSnapshotView.js
index 6bcc0ff..d09f91d 100644
--- a/WebCore/inspector/front-end/HeapSnapshotView.js
+++ b/WebCore/inspector/front-end/HeapSnapshotView.js
@@ -27,6 +27,154 @@
  * (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.HeapSnapshotEdgesIterator = function(snapshot, edges)
+{
+    this._snapshot = snapshot;
+    this._edges = edges;
+    this._edgeIndex = 0;
+}
+
+WebInspector.HeapSnapshotEdgesIterator.prototype = {
+    get done()
+    {
+        return this._edgeIndex >= this._edges.length;
+    },
+
+    get isElement()
+    {
+        return this._getType() === this._snapshot._edgeElementType;
+    },
+
+    get isHidden()
+    {
+        return this._getType() === this._snapshot._edgeHiddenType;
+    },
+
+    get name()
+    {
+        return this.isElement || this.isHidden ? this._getNameOrIndex() : this._snapshot._strings[this._getNameOrIndex()];
+    },
+
+    next: function()
+    {
+        this._edgeIndex += this._snapshot._edgeFieldsCount;
+    },
+
+    get node()
+    {
+        return new WebInspector.HeapSnapshotNodeWrapper(this._snapshot, this.nodeIndex);
+    },
+
+    get nodeIndex()
+    {
+        return this._edges[this._edgeIndex + this._snapshot._edgeToNodeOffset];
+    },
+
+    _getNameOrIndex: function()
+    {
+        return this._edges[this._edgeIndex + this._snapshot._edgeNameOffset];
+    },
+
+    _getType: function()
+    {
+        return this._edges[this._edgeIndex + this._snapshot._edgeTypeOffset];
+    }
+};
+
+WebInspector.HeapSnapshotNodeWrapper = function(snapshot, nodeIndex)
+{
+    this._snapshot = snapshot;
+    this._nodes = snapshot._nodes;
+    this._nodeIndex = nodeIndex;
+}
+
+WebInspector.HeapSnapshotNodeWrapper.prototype = {
+    get edges()
+    {
+        return new WebInspector.HeapSnapshotEdgesIterator(this._snapshot, this._getEdges());
+    },
+
+    get edgesCount()
+    {
+        return this._nodes[this._nodeIndex + this._snapshot._edgesCountOffset];
+    },
+
+    get instancesCount()
+    {
+        return this._nodes[this._nodeIndex + this._snapshot._nodeInstancesCountOffset];
+    },
+
+    get isHidden()
+    {
+        return this._getType() === this._snapshot._nodeHiddenType;
+    },
+
+    get name()
+    {
+        return this._snapshot._strings[this._getName()];
+    },
+
+    get selfSize()
+    {
+        return this._nodes[this._nodeIndex + this._snapshot._nodeSelfSizeOffset]; 
+    },
+
+    _getName: function()
+    {
+        return this._nodes[this._nodeIndex + this._snapshot._nodeNameOffset]; 
+    },
+
+    _getEdges: function()
+    {
+        var firstEdgeIndex = this._nodeIndex + this._snapshot._firstEdgeOffset;
+        return this._nodes.slice(firstEdgeIndex, firstEdgeIndex + this.edgesCount * this._snapshot._edgeFieldsCount);
+    },
+
+    _getType: function()
+    {
+        return this._nodes[this._nodeIndex + this._snapshot._nodeTypeOffset];
+    }
+};
+
+WebInspector.HeapSnapshot = function(profile)
+{
+    this._profile = profile;
+    this._nodes = profile.nodes;
+    this._strings = profile.strings;
+
+    this._init();
+}
+
+WebInspector.HeapSnapshot.prototype = {
+    _init: function()
+    {
+        this._metaNodeIndex = 0;
+        this._rootNodeIndex = 1;
+        var meta = this._nodes[this._metaNodeIndex];
+        this._nodeTypeOffset = meta.fields.indexOf("type");
+        this._nodeNameOffset = meta.fields.indexOf("name");
+        this._nodeIdOffset = meta.fields.indexOf("id");
+        this._nodeInstancesCountOffset = this._nodeIdOffset;
+        this._nodeSelfSizeOffset = meta.fields.indexOf("self_size");
+        this._edgesCountOffset = meta.fields.indexOf("children_count");
+        this._firstEdgeOffset = meta.fields.indexOf("children");
+        this._nodeTypes = meta.types[this._nodeTypeOffset];
+        this._nodeHiddenType = this._nodeTypes.indexOf("hidden");
+        var edgesMeta = meta.types[this._firstEdgeOffset];
+        this._edgeFieldsCount = edgesMeta.fields.length;
+        this._edgeTypeOffset = edgesMeta.fields.indexOf("type");
+        this._edgeNameOffset = edgesMeta.fields.indexOf("name_or_index");
+        this._edgeToNodeOffset = edgesMeta.fields.indexOf("to_node");
+        this._edgeTypes = edgesMeta.types[this._edgeTypeOffset];
+        this._edgeElementType = this._edgeTypes.indexOf("element");
+        this._edgeHiddenType = this._edgeTypes.indexOf("hidden");
+    },
+
+    get rootEdges()
+    {
+        return (new WebInspector.HeapSnapshotNodeWrapper(this, this._rootNodeIndex)).edges;
+    }
+};
 
 WebInspector.HeapSnapshotView = function(parent, profile)
 {
@@ -94,6 +242,7 @@ WebInspector.HeapSnapshotView = function(parent, profile)
     this.percentButton = new WebInspector.StatusBarButton("", "percent-time-status-bar-item status-bar-item");
     this.percentButton.addEventListener("click", this._percentClicked.bind(this), false);
 
+    this._loadedCallbacks = [];
     this._loadProfile(this.profile, profileCallback.bind(this));
 
     function profileCallback(profile)
@@ -290,6 +439,14 @@ WebInspector.HeapSnapshotView.prototype = {
         this._updateSummaryGraph();
     },
 
+    snapshotLoaded: function(uid, loadedSnapshot)
+    {
+        if (!this._loadedCallbacks[uid])
+            return;
+        this._loadedCallbacks[uid](loadedSnapshot);
+        delete this._loadedCallbacks[uid];
+    },
+
     _changeBase: function()
     {
         if (this.baseSnapshot.uid === this._getProfiles()[this.baseSelectElement.selectedIndex].uid)
@@ -332,15 +489,17 @@ WebInspector.HeapSnapshotView.prototype = {
             return;
         }
 
-        InspectorBackend.getProfile(profile.typeId, profile.uid, loadedCallback.bind(this));
+        this._loadedCallbacks[profile.uid] = processLoadedSnapshot.bind(this);
+        InspectorBackend.getProfile(profile.typeId, profile.uid);
 
-        function loadedCallback(loadedSnapshot) {
-            profile.children = loadedSnapshot.head.children;
-            profile.entries = loadedSnapshot.head.entries;
-            profile.lowlevels = loadedSnapshot.head.lowlevels;
+        function processLoadedSnapshot(loadedSnapshot)
+        {
+            var snapshot = this._convertSnapshot(loadedSnapshot);
+            profile.children = snapshot.children;
+            profile.entries = snapshot.entries;
+            profile.lowlevels = snapshot.lowlevels;
             this._prepareProfile(profile);
             profile._loaded = true;
-            this.parent.updateProfile(profile);
             callback(profile);
         }
     },
@@ -384,6 +543,26 @@ WebInspector.HeapSnapshotView.prototype = {
         this.refreshShowAsPercents();
     },
 
+    _convertSnapshot: function(loadedSnapshot)
+    {
+        var snapshot = new WebInspector.HeapSnapshot(loadedSnapshot);
+        var result = {lowlevels: {}, entries: {}, children: {}};
+        for (var rootEdges = snapshot.rootEdges; !rootEdges.done; rootEdges.next()) {
+            var node = rootEdges.node;
+            if (node.isHidden)
+                result.lowlevels[node.name] = {count: node.instancesCount, size: node.selfSize, type: node.name};
+            else if (node.instancesCount)
+                result.entries[node.name] = {constructorName: node.name, count: node.instancesCount, size: node.selfSize};
+            else {
+                var entry = {constructorName: node.name};
+                for (var edges = node.edges; !edges.done; edges.next())
+                    entry[edges.nodeIndex] = {constructorName: edges.node.name, count: edges.name};
+                result.children[rootEdges.nodeIndex] = entry;
+            }
+        }
+        return result;
+    },
+
     _prepareProfile: function(profile)
     {
         for (var profileEntry in profile.entries)
@@ -392,12 +571,12 @@ WebInspector.HeapSnapshotView.prototype = {
 
         for (var addr in profile.children) {
             var retainer = profile.children[addr];
-            var retainerId = retainer.constructorName + ':' + addr;
+            var retainerId = retainer.constructorName + ":" + addr;
             for (var childAddr in retainer) {
-                if (childAddr === 'constructorName') continue;
+                if (childAddr === "constructorName") continue;
                 var item = retainer[childAddr];
-                var itemId = item.constructorName + ':' + childAddr;
-                if ((item.constructorName === 'Object' || item.constructorName === 'Array')) {
+                var itemId = item.constructorName + ":" + childAddr;
+                if ((item.constructorName === "Object" || item.constructorName === "Array")) {
                     if (!(itemId in profile.clusters))
                         profile.clusters[itemId] = { constructorName: itemId, retainers: {} };
                     mergeRetainers(profile.clusters[itemId], item);
@@ -412,7 +591,7 @@ WebInspector.HeapSnapshotView.prototype = {
                entry.retainers[retainer.constructorName] = { constructorName: retainer.constructorName, count: 0, clusters: {} };
             var retainerEntry = entry.retainers[retainer.constructorName];
             retainerEntry.count += item.count;
-            if (retainer.constructorName === 'Object' || retainer.constructorName === 'Array')
+            if (retainer.constructorName === "Object" || retainer.constructorName === "Array")
                 retainerEntry.clusters[retainerId] = true;
         }
     },
@@ -438,7 +617,7 @@ WebInspector.HeapSnapshotView.prototype = {
         var sortAscending = this.dataGrid.sortOrder === "ascending";
         var sortColumnIdentifier = this.dataGrid.sortColumnIdentifier;
         var sortProperty = {
-            cons: ["cons", null],
+            cons: ["constructorName", null],
             count: ["count", null],
             size: ["size", "count"],
             countDelta: this.showCountDeltaAsPercent ? ["countDeltaPercent", null] : ["countDelta", null],
diff --git a/WebCore/inspector/front-end/ProfilesPanel.js b/WebCore/inspector/front-end/ProfilesPanel.js
index 0aa4174..50795e8 100644
--- a/WebCore/inspector/front-end/ProfilesPanel.js
+++ b/WebCore/inspector/front-end/ProfilesPanel.js
@@ -123,6 +123,7 @@ WebInspector.ProfilesPanel = function()
 
     this._profiles = [];
     this._profilerEnabled = Preferences.profilerAlwaysEnabled;
+    this._tempHeapSnapshots = [];
     this._reset();
 }
 
@@ -411,6 +412,25 @@ WebInspector.ProfilesPanel.prototype = {
             }
     },
 
+    addHeapSnapshotChunk: function(uid, chunk)
+    {
+        if (this._tempHeapSnapshots[uid])
+            this._tempHeapSnapshots[uid] += chunk;
+        else
+            this._tempHeapSnapshots[uid] = chunk;
+    },
+
+    finishHeapSnapshot: function(uid)
+    {
+        var profile =
+            this._profilesIdMap[this._makeKey(uid, WebInspector.HeapSnapshotProfileType.TypeId)];
+        if (profile) {
+            var view = profile.__profilesPanelProfileType.viewForProfile(profile);
+            view.snapshotLoaded(uid, JSON.parse(this._tempHeapSnapshots[uid]));
+        }
+        delete this._tempHeapSnapshots[uid];
+    },
+
     showView: function(view)
     {
         this.showProfile(view.profile);
diff --git a/WebCore/inspector/front-end/inspector.js b/WebCore/inspector/front-end/inspector.js
index 78592ff..51145cf 100644
--- a/WebCore/inspector/front-end/inspector.js
+++ b/WebCore/inspector/front-end/inspector.js
@@ -1545,6 +1545,16 @@ WebInspector.setRecordingProfile = function(isProfiling)
     this.panels.profiles.updateProfileTypeButtons();
 }
 
+WebInspector.addHeapSnapshotChunk = function(uid, chunk)
+{
+    this.panels.profiles.addHeapSnapshotChunk(uid, chunk);
+}
+
+WebInspector.finishHeapSnapshot = function(uid)
+{
+    this.panels.profiles.finishHeapSnapshot(uid);
+}
+
 WebInspector.drawLoadingPieChart = function(canvas, percent) {
     var g = canvas.getContext("2d");
     var darkColor = "rgb(122, 168, 218)";

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list