Commit 8d2d9a40 authored by mnaganov@chromium.org's avatar mnaganov@chromium.org
Browse files

2011-01-25 Mikhail Naganov <mnaganov@chromium.org>

        Reviewed by Pavel Feldman.

        Web Inspector: [Chromium] Prepare for landing of detailed heap snapshots.

        - Introduce Preferences.detailedHeapProfiles flag for controlling
          querying of detailed heap snapshots.
        - Add boilerplate code for the new view.
        - Factor out common code.

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

        * WebCore.gypi:
        * WebCore.vcproj/WebCore.vcproj:
        * bindings/js/ScriptProfiler.h:
        (WebCore::ScriptProfiler::HeapSnapshotControl::~HeapSnapshotControl):
        (WebCore::ScriptProfiler::takeHeapSnapshot):
        * bindings/v8/ScriptProfiler.cpp:
        (WebCore::ScriptProfiler::takeHeapSnapshot):
        * bindings/v8/ScriptProfiler.h:
        (WebCore::ScriptProfiler::HeapSnapshotControl::~HeapSnapshotControl):
        * inspector/Inspector.idl:
        * inspector/InspectorProfilerAgent.cpp:
        (WebCore::InspectorProfilerAgent::takeHeapSnapshot):
        * inspector/InspectorProfilerAgent.h:
        * inspector/front-end/DetailedHeapshotView.js: Added.
        (WebInspector.DetailedHeapshotView):
        (WebInspector.DetailedHeapshotView.prototype.get statusBarItems):
        (WebInspector.DetailedHeapshotView.prototype.get profile):
        (WebInspector.DetailedHeapshotView.prototype.set profile):
        (WebInspector.DetailedHeapshotView.prototype.show):
        (WebInspector.DetailedHeapshotView.prototype.hide):
        (WebInspector.DetailedHeapshotProfileType):
        (WebInspector.DetailedHeapshotProfileType.prototype.get buttonTooltip):
        (WebInspector.DetailedHeapshotProfileType.prototype.get buttonStyle):
        (WebInspector.DetailedHeapshotProfileType.prototype.buttonClicked):
        (WebInspector.DetailedHeapshotProfileType.prototype.get welcomeMessage):
        (WebInspector.DetailedHeapshotProfileType.prototype.createSidebarTreeElementForProfile):
        (WebInspector.DetailedHeapshotProfileType.prototype.createView):
        * inspector/front-end/HeapSnapshot.js: Added.
        (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):
        * inspector/front-end/HeapSnapshotView.js:
        (WebInspector.HeapSnapshotProfileType.prototype.buttonClicked):
        * inspector/front-end/ProfilesPanel.js:
        (WebInspector.ProfilesPanel.prototype._setRecordingProfile):
        (WebInspector.ProfilesPanel.prototype._reportHeapSnapshotProgress):
        (WebInspector.ProfilerDispatcher.prototype.setRecordingProfile):
        (WebInspector.ProfilerDispatcher.prototype.reportHeapSnapshotProgress):
        * inspector/front-end/Settings.js:
        * inspector/front-end/WebKit.qrc:
        * inspector/front-end/inspector.html:
        * inspector/front-end/inspector.js:
        (WebInspector._createPanels):
        * src/js/DevTools.js:
        ():

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@76597 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f6822424
2011-01-25 Mikhail Naganov <mnaganov@chromium.org>
Reviewed by Pavel Feldman.
Web Inspector: [Chromium] Prepare for landing of detailed heap snapshots.
- Introduce Preferences.detailedHeapProfiles flag for controlling
querying of detailed heap snapshots.
- Add boilerplate code for the new view.
- Factor out common code.
https://bugs.webkit.org/show_bug.cgi?id=52624
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* bindings/js/ScriptProfiler.h:
(WebCore::ScriptProfiler::HeapSnapshotControl::~HeapSnapshotControl):
(WebCore::ScriptProfiler::takeHeapSnapshot):
* bindings/v8/ScriptProfiler.cpp:
(WebCore::ScriptProfiler::takeHeapSnapshot):
* bindings/v8/ScriptProfiler.h:
(WebCore::ScriptProfiler::HeapSnapshotControl::~HeapSnapshotControl):
* inspector/Inspector.idl:
* inspector/InspectorProfilerAgent.cpp:
(WebCore::InspectorProfilerAgent::takeHeapSnapshot):
* inspector/InspectorProfilerAgent.h:
* inspector/front-end/DetailedHeapshotView.js: Added.
(WebInspector.DetailedHeapshotView):
(WebInspector.DetailedHeapshotView.prototype.get statusBarItems):
(WebInspector.DetailedHeapshotView.prototype.get profile):
(WebInspector.DetailedHeapshotView.prototype.set profile):
(WebInspector.DetailedHeapshotView.prototype.show):
(WebInspector.DetailedHeapshotView.prototype.hide):
(WebInspector.DetailedHeapshotProfileType):
(WebInspector.DetailedHeapshotProfileType.prototype.get buttonTooltip):
(WebInspector.DetailedHeapshotProfileType.prototype.get buttonStyle):
(WebInspector.DetailedHeapshotProfileType.prototype.buttonClicked):
(WebInspector.DetailedHeapshotProfileType.prototype.get welcomeMessage):
(WebInspector.DetailedHeapshotProfileType.prototype.createSidebarTreeElementForProfile):
(WebInspector.DetailedHeapshotProfileType.prototype.createView):
* inspector/front-end/HeapSnapshot.js: Added.
(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):
* inspector/front-end/HeapSnapshotView.js:
(WebInspector.HeapSnapshotProfileType.prototype.buttonClicked):
* inspector/front-end/ProfilesPanel.js:
(WebInspector.ProfilesPanel.prototype._setRecordingProfile):
(WebInspector.ProfilesPanel.prototype._reportHeapSnapshotProgress):
(WebInspector.ProfilerDispatcher.prototype.setRecordingProfile):
(WebInspector.ProfilerDispatcher.prototype.reportHeapSnapshotProgress):
* inspector/front-end/Settings.js:
* inspector/front-end/WebKit.qrc:
* inspector/front-end/inspector.html:
* inspector/front-end/inspector.js:
(WebInspector._createPanels):
2011-01-25 Yury Semikhatsky <yurys@chromium.org>
 
Reviewed by Pavel Feldman.
......@@ -4663,6 +4663,7 @@
'inspector/front-end/DatabaseTableView.js',
'inspector/front-end/DataGrid.js',
'inspector/front-end/DebuggerModel.js',
'inspector/front-end/DetailedHeapshotView.js',
'inspector/front-end/DOMAgent.js',
'inspector/front-end/DOMStorage.js',
'inspector/front-end/DOMStorageItemsView.js',
......@@ -4681,6 +4682,7 @@
'inspector/front-end/FontView.js',
'inspector/front-end/GoToLineDialog.js',
'inspector/front-end/HAREntry.js',
'inspector/front-end/HeapSnapshot.js',
'inspector/front-end/HeapSnapshotView.js',
'inspector/front-end/HelpScreen.js',
'inspector/front-end/ImageView.js',
......
......@@ -65456,6 +65456,10 @@
RelativePath="..\inspector\front-end\DebuggerModel.js"
>
</File>
<File
RelativePath="..\inspector\front-end\DetailedHeapshotView.js"
>
</File>
<File
RelativePath="..\inspector\front-end\DOMAgent.js"
>
......@@ -65536,6 +65540,10 @@
RelativePath="..\inspector\front-end\heapProfiler.css"
>
</File>
<File
RelativePath="..\inspector\front-end\HeapSnapshot.js"
>
</File>
<File
RelativePath="..\inspector\front-end\HeapSnapshotView.js"
>
......@@ -38,9 +38,18 @@ namespace WebCore {
class ScriptProfiler {
WTF_MAKE_NONCOPYABLE(ScriptProfiler);
public:
class HeapSnapshotProgress {
public:
virtual ~HeapSnapshotProgress() { }
virtual void Start(int totalWork) = 0;
virtual void Worked(int workDone) = 0;
virtual void Done() = 0;
virtual bool isCanceled() = 0;
};
static void start(ScriptState* state, const String& title);
static PassRefPtr<ScriptProfile> stop(ScriptState* state, const String& title);
static PassRefPtr<ScriptHeapSnapshot> takeHeapSnapshot(const String&) { return 0; }
static PassRefPtr<ScriptHeapSnapshot> takeHeapSnapshot(const String&, HeapSnapshotProgress*) { return 0; }
static bool isProfilerAlwaysEnabled();
};
......
......@@ -53,10 +53,40 @@ PassRefPtr<ScriptProfile> ScriptProfiler::stop(ScriptState* state, const String&
return profile ? ScriptProfile::create(profile) : 0;
}
PassRefPtr<ScriptHeapSnapshot> ScriptProfiler::takeHeapSnapshot(const String& title)
namespace {
class ActivityControlAdapter : public v8::ActivityControl {
public:
ActivityControlAdapter(ScriptProfiler::HeapSnapshotProgress* progress)
: m_progress(progress), m_firstReport(true) { }
ControlOption ReportProgressValue(int done, int total)
{
ControlOption result = m_progress->isCanceled() ? kAbort : kContinue;
if (m_firstReport) {
m_firstReport = false;
m_progress->Start(total);
} else
m_progress->Worked(done);
if (done >= total)
m_progress->Done();
return result;
}
private:
ScriptProfiler::HeapSnapshotProgress* m_progress;
bool m_firstReport;
};
} // namespace
PassRefPtr<ScriptHeapSnapshot> ScriptProfiler::takeHeapSnapshot(const String& title, HeapSnapshotProgress* control)
{
v8::HandleScope hs;
const v8::HeapSnapshot* snapshot = v8::HeapProfiler::TakeSnapshot(v8String(title), v8::HeapSnapshot::kAggregated);
const v8::HeapSnapshot* snapshot = 0;
if (control) {
ActivityControlAdapter adapter(control);
snapshot = v8::HeapProfiler::TakeSnapshot(v8String(title), v8::HeapSnapshot::kFull, &adapter);
} else
snapshot = v8::HeapProfiler::TakeSnapshot(v8String(title), v8::HeapSnapshot::kAggregated);
return snapshot ? ScriptHeapSnapshot::create(snapshot) : 0;
}
......
......@@ -44,9 +44,18 @@ class InspectorObject;
class ScriptProfiler {
WTF_MAKE_NONCOPYABLE(ScriptProfiler);
public:
class HeapSnapshotProgress {
public:
virtual ~HeapSnapshotProgress() { }
virtual void Start(int totalWork) = 0;
virtual void Worked(int workDone) = 0;
virtual void Done() = 0;
virtual bool isCanceled() = 0;
};
static void start(ScriptState* state, const String& title);
static PassRefPtr<ScriptProfile> stop(ScriptState* state, const String& title);
static PassRefPtr<ScriptHeapSnapshot> takeHeapSnapshot(const String& title);
static PassRefPtr<ScriptHeapSnapshot> takeHeapSnapshot(const String& title, HeapSnapshotProgress*);
static bool isProfilerAlwaysEnabled();
};
......
......@@ -304,12 +304,13 @@ module core {
[domain=Profiler] void clearProfiles();
// FIXME: split into Profiler and HeapProfiler.
[domain=Profiler] void takeHeapSnapshot();
[domain=Profiler] void takeHeapSnapshot(in boolean detailed);
[notify, domain=Profiler] void addProfileHeader(out Object header);
[notify, domain=Profiler] void addHeapSnapshotChunk(out unsigned long uid, out String chunk);
[notify, domain=Profiler] void finishHeapSnapshot(out unsigned long uid);
[notify, domain=Profiler] void setRecordingProfile(out boolean isProfiling);
[notify, domain=Profiler] void resetProfiles();
[notify, domain=Profiler] void reportHeapSnapshotProgress(out int done, out int total);
#endif // ENABLE_JAVASCRIPT_DEBUGGER
};
}
......@@ -267,12 +267,37 @@ void InspectorProfilerAgent::stopUserInitiatedProfiling(bool ignoreProfile)
toggleRecordButton(false);
}
void InspectorProfilerAgent::takeHeapSnapshot()
namespace {
class HeapSnapshotProgress: public ScriptProfiler::HeapSnapshotProgress {
public:
explicit HeapSnapshotProgress(InspectorFrontend* frontend)
: m_frontend(frontend) { }
void Start(int totalWork)
{
m_totalWork = totalWork;
}
void Worked(int workDone)
{
if (m_frontend)
m_frontend->reportHeapSnapshotProgress(workDone, m_totalWork);
}
void Done() { }
bool isCanceled() { return false; }
private:
InspectorFrontend* m_frontend;
int m_totalWork;
};
};
void InspectorProfilerAgent::takeHeapSnapshot(bool detailed)
{
String title = makeString(UserInitiatedProfileName, '.', String::number(m_nextUserInitiatedHeapSnapshotNumber));
++m_nextUserInitiatedHeapSnapshotNumber;
RefPtr<ScriptHeapSnapshot> snapshot = ScriptProfiler::takeHeapSnapshot(title);
HeapSnapshotProgress progress(m_frontend);
RefPtr<ScriptHeapSnapshot> snapshot = ScriptProfiler::takeHeapSnapshot(title, detailed ? &progress : 0);
if (snapshot) {
m_snapshots.add(snapshot->uid(), snapshot);
if (m_frontend)
......
......@@ -70,7 +70,7 @@ public:
void setFrontend(InspectorFrontend* frontend) { m_frontend = frontend; }
void startUserInitiatedProfiling();
void stopUserInitiatedProfiling(bool ignoreProfile = false);
void takeHeapSnapshot();
void takeHeapSnapshot(bool detailed);
void toggleRecordButton(bool isProfiling);
private:
......
/*
* Copyright (C) 2011 Google 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:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
* OWNER OR 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.DetailedHeapshotView = function(parent, profile)
{
WebInspector.View.call(this);
this.element.addStyleClass("heap-snapshot-view");
this.parent = parent;
this.profile = profile;
}
WebInspector.DetailedHeapshotView.prototype = {
get profile()
{
return this._profile;
},
set profile(profile)
{
this._profile = profile;
}
};
WebInspector.DetailedHeapshotView.prototype.__proto__ = WebInspector.View.prototype;
WebInspector.DetailedHeapshotProfileType = function()
{
WebInspector.ProfileType.call(this, WebInspector.HeapSnapshotProfileType.TypeId, WebInspector.UIString("HEAP SNAPSHOTS"));
}
WebInspector.DetailedHeapshotProfileType.prototype = {
get buttonTooltip()
{
return WebInspector.UIString("Take heap snapshot.");
},
get buttonStyle()
{
return "heap-snapshot-status-bar-item status-bar-item";
},
buttonClicked: function()
{
InspectorBackend.takeHeapSnapshot(true);
},
get welcomeMessage()
{
return WebInspector.UIString("Get a heap snapshot by pressing the %s button on the status bar.");
},
createSidebarTreeElementForProfile: function(profile)
{
return new WebInspector.ProfileSidebarTreeElement(profile, WebInspector.UIString("Snapshot %d"), "heap-snapshot-sidebar-tree-item");
},
createView: function(profile)
{
return new WebInspector.DetailedHeapshotView(WebInspector.panels.profiles, profile);
}
}
WebInspector.DetailedHeapshotProfileType.prototype.__proto__ = WebInspector.ProfileType.prototype;
/*
* Copyright (C) 2011 Google 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:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
* OWNER OR 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.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._type() === this._snapshot._edgeElementType;
},
get isHidden()
{
return this._type() === this._snapshot._edgeHiddenType;
},
get name()
{
return this.isElement || this.isHidden ? this._nameOrIndex() : this._snapshot._strings[this._nameOrIndex()];
},
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];
},
_nameOrIndex: function()
{
return this._edges[this._edgeIndex + this._snapshot._edgeNameOffset];
},
_type: 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._edges());
},
get edgesCount()
{
return this._nodes[this._nodeIndex + this._snapshot._edgesCountOffset];
},
get instancesCount()
{
return this._nodes[this._nodeIndex + this._snapshot._nodeInstancesCountOffset];
},
get isHidden()
{
return this._type() === this._snapshot._nodeHiddenType;
},
get name()
{
return this._snapshot._strings[this._name()];
},
get selfSize()
{
return this._nodes[this._nodeIndex + this._snapshot._nodeSelfSizeOffset];
},
_name: function()
{
return this._nodes[this._nodeIndex + this._snapshot._nodeNameOffset];
},
_edges: function()
{
var firstEdgeIndex = this._nodeIndex + this._snapshot._firstEdgeOffset;
return this._nodes.slice(firstEdgeIndex, firstEdgeIndex + this.edgesCount * this._snapshot._edgeFieldsCount);
},
_type: 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;
}
};
......@@ -27,154 +27,6 @@
* (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];
},