Diff
Modified: trunk/Source/WebCore/CMakeLists.txt (137727 => 137728)
--- trunk/Source/WebCore/CMakeLists.txt 2012-12-14 08:33:54 UTC (rev 137727)
+++ trunk/Source/WebCore/CMakeLists.txt 2012-12-14 08:44:17 UTC (rev 137728)
@@ -1576,6 +1576,7 @@
inspector/ContentSearchUtils.cpp
inspector/DOMEditor.cpp
inspector/DOMPatchSupport.cpp
+ inspector/HeapGraphSerializer.cpp
inspector/IdentifiersFactory.cpp
inspector/InjectedScript.cpp
inspector/InjectedScriptBase.cpp
Modified: trunk/Source/WebCore/ChangeLog (137727 => 137728)
--- trunk/Source/WebCore/ChangeLog 2012-12-14 08:33:54 UTC (rev 137727)
+++ trunk/Source/WebCore/ChangeLog 2012-12-14 08:44:17 UTC (rev 137728)
@@ -1,3 +1,55 @@
+2012-12-13 Yury Semikhatsky <[email protected]>
+
+ Web Inspector: collect native heap graph and report it to the front-end
+ https://bugs.webkit.org/show_bug.cgi?id=104888
+
+ Reviewed by Pavel Feldman.
+
+ Added an option to serialize native heap graph in a format similar to that
+ of JS heap profiler and send it in reply to getProcessMemoryDistribution
+ command. This is a first attempt and we likely change the report mechanism to
+ use a stream instread of sending whole graph at once.
+
+ * CMakeLists.txt:
+ * GNUmakefile.list.am:
+ * Target.pri:
+ * WebCore.gypi:
+ * WebCore.vcproj/WebCore.vcproj:
+ * WebCore.xcodeproj/project.pbxproj:
+ * inspector/HeapGraphSerializer.cpp: Added.
+ (WebCore):
+ (HeapGraphNode):
+ (WebCore::HeapGraphNode::HeapGraphNode):
+ (HeapGraphEdge):
+ (WebCore::HeapGraphEdge::HeapGraphEdge):
+ (WebCore::HeapGraphSerializer::HeapGraphSerializer):
+ (WebCore::HeapGraphSerializer::~HeapGraphSerializer):
+ (WebCore::HeapGraphSerializer::serialize):
+ (WebCore::HeapGraphSerializer::reportNode):
+ (WebCore::HeapGraphSerializer::reportEdge):
+ (WebCore::HeapGraphSerializer::reportLeaf):
+ (WebCore::HeapGraphSerializer::reportBaseAddress):
+ (WebCore::HeapGraphSerializer::adjutEdgeTargets):
+ (WebCore::HeapGraphSerializer::addString):
+ * inspector/HeapGraphSerializer.h: Copied from Source/WebCore/inspector/InspectorMemoryAgent.h.
+ (WebCore):
+ (HeapGraphSerializer):
+ * inspector/Inspector.json:
+ * inspector/InspectorMemoryAgent.cpp:
+ (WebCore::InspectorMemoryAgent::getProcessMemoryDistribution):
+ * inspector/InspectorMemoryAgent.h:
+ (InspectorMemoryAgent):
+ * inspector/MemoryInstrumentationImpl.cpp:
+ (WebCore::MemoryInstrumentationClientImpl::reportNode):
+ (WebCore):
+ (WebCore::MemoryInstrumentationClientImpl::reportEdge):
+ (WebCore::MemoryInstrumentationClientImpl::reportLeaf):
+ (WebCore::MemoryInstrumentationClientImpl::reportBaseAddress):
+ * inspector/MemoryInstrumentationImpl.h:
+ (WebCore):
+ (WebCore::MemoryInstrumentationClientImpl::MemoryInstrumentationClientImpl):
+ (MemoryInstrumentationClientImpl):
+
2012-12-14 Yoshifumi Inoue <[email protected]>
Handling autoscroll in EventHandler should be re-factor
Modified: trunk/Source/WebCore/GNUmakefile.list.am (137727 => 137728)
--- trunk/Source/WebCore/GNUmakefile.list.am 2012-12-14 08:33:54 UTC (rev 137727)
+++ trunk/Source/WebCore/GNUmakefile.list.am 2012-12-14 08:44:17 UTC (rev 137728)
@@ -3689,6 +3689,8 @@
Source/WebCore/inspector/DOMEditor.h \
Source/WebCore/inspector/DOMPatchSupport.cpp \
Source/WebCore/inspector/DOMPatchSupport.h \
+ Source/WebCore/inspector/HeapGraphSerializer.cpp \
+ Source/WebCore/inspector/HeapGraphSerializer.h \
Source/WebCore/inspector/IdentifiersFactory.cpp \
Source/WebCore/inspector/IdentifiersFactory.h \
Source/WebCore/inspector/InjectedScript.cpp \
Modified: trunk/Source/WebCore/Target.pri (137727 => 137728)
--- trunk/Source/WebCore/Target.pri 2012-12-14 08:33:54 UTC (rev 137727)
+++ trunk/Source/WebCore/Target.pri 2012-12-14 08:44:17 UTC (rev 137728)
@@ -740,6 +740,7 @@
inspector/ContentSearchUtils.cpp \
inspector/DOMEditor.cpp \
inspector/DOMPatchSupport.cpp \
+ inspector/HeapGraphSerializer.cpp \
inspector/IdentifiersFactory.cpp \
inspector/InjectedScript.cpp \
inspector/InjectedScriptBase.cpp \
@@ -1896,6 +1897,7 @@
inspector/ContentSearchUtils.h \
inspector/DOMEditor.h \
inspector/DOMPatchSupport.h \
+ inspector/HeapGraphSerializer.h \
inspector/IdentifiersFactory.h \
inspector/InjectedScript.h \
inspector/InjectedScriptBase.h \
Modified: trunk/Source/WebCore/WebCore.gypi (137727 => 137728)
--- trunk/Source/WebCore/WebCore.gypi 2012-12-14 08:33:54 UTC (rev 137727)
+++ trunk/Source/WebCore/WebCore.gypi 2012-12-14 08:44:17 UTC (rev 137728)
@@ -1774,6 +1774,8 @@
'inspector/DOMEditor.h',
'inspector/DOMPatchSupport.cpp',
'inspector/DOMPatchSupport.h',
+ 'inspector/HeapGraphSerializer.cpp',
+ 'inspector/HeapGraphSerializer.h',
'inspector/IdentifiersFactory.cpp',
'inspector/IdentifiersFactory.h',
'inspector/InjectedScript.cpp',
Modified: trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj (137727 => 137728)
--- trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj 2012-12-14 08:33:54 UTC (rev 137727)
+++ trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj 2012-12-14 08:44:17 UTC (rev 137728)
@@ -74822,6 +74822,30 @@
>
</File>
<File
+ RelativePath="..\inspector\HeapGraphSerializer.cpp"
+ >
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Production|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\inspector\HeapGraphSerializer.h"
+ >
+ </File>
+ <File
RelativePath="..\inspector\IdentifiersFactory.cpp"
>
<FileConfiguration
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (137727 => 137728)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2012-12-14 08:33:54 UTC (rev 137727)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2012-12-14 08:44:17 UTC (rev 137728)
@@ -3685,8 +3685,6 @@
97BC6A271505F081001B74AC /* DatabaseContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 97BC69E51505F081001B74AC /* DatabaseContext.cpp */; };
97BC6A281505F081001B74AC /* DatabaseContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 97BC69E61505F081001B74AC /* DatabaseContext.h */; settings = {ATTRIBUTES = (Private, ); }; };
97BC6A291505F081001B74AC /* DatabaseDetails.h in Headers */ = {isa = PBXBuildFile; fileRef = 97BC69E71505F081001B74AC /* DatabaseDetails.h */; settings = {ATTRIBUTES = (Private, ); }; };
- FE456F181677D74E005EDDF9 /* DatabaseManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE456F161677D74E005EDDF9 /* DatabaseManager.cpp */; };
- FE456F191677D74E005EDDF9 /* DatabaseManager.h in Headers */ = {isa = PBXBuildFile; fileRef = FE456F171677D74E005EDDF9 /* DatabaseManager.h */; settings = {ATTRIBUTES = (Private, ); }; };
97BC6A2A1505F081001B74AC /* DatabaseSync.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 97BC69E81505F081001B74AC /* DatabaseSync.cpp */; };
97BC6A2B1505F081001B74AC /* DatabaseSync.h in Headers */ = {isa = PBXBuildFile; fileRef = 97BC69E91505F081001B74AC /* DatabaseSync.h */; };
97BC6A2D1505F081001B74AC /* DatabaseTask.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 97BC69EB1505F081001B74AC /* DatabaseTask.cpp */; };
@@ -6290,6 +6288,8 @@
F36E07A41358A8BE00AACBC9 /* WorkerInspectorController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F36E07A21358A8BE00AACBC9 /* WorkerInspectorController.cpp */; };
F36E07A51358A8BE00AACBC9 /* WorkerInspectorController.h in Headers */ = {isa = PBXBuildFile; fileRef = F36E07A31358A8BE00AACBC9 /* WorkerInspectorController.h */; };
F375CC071150D300008DDB81 /* InspectorWorkerResource.h in Headers */ = {isa = PBXBuildFile; fileRef = F375CC061150D300008DDB81 /* InspectorWorkerResource.h */; };
+ F37A56221679CF7B00C57046 /* HeapGraphSerializer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F37A56201679CF7B00C57046 /* HeapGraphSerializer.cpp */; };
+ F37A56231679CF7B00C57046 /* HeapGraphSerializer.h in Headers */ = {isa = PBXBuildFile; fileRef = F37A56211679CF7B00C57046 /* HeapGraphSerializer.h */; };
F3810C1B1365A49600ED6E33 /* InspectorWorkerAgent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F3810C191365A49600ED6E33 /* InspectorWorkerAgent.cpp */; };
F3810C1C1365A49600ED6E33 /* InspectorWorkerAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = F3810C1A1365A49600ED6E33 /* InspectorWorkerAgent.h */; };
F3820892147D35F90010BC06 /* PageConsoleAgent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F382088A147D35F90010BC06 /* PageConsoleAgent.cpp */; };
@@ -6645,6 +6645,8 @@
FDF6BAF9134A4C9800822920 /* JSOfflineAudioCompletionEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = FDF6BAF7134A4C9800822920 /* JSOfflineAudioCompletionEvent.h */; };
FDF7E9C313AC21DB00A51EAC /* JSAudioBufferCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FDF7E9C113AC21DB00A51EAC /* JSAudioBufferCallback.cpp */; };
FDF7E9C413AC21DB00A51EAC /* JSAudioBufferCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = FDF7E9C213AC21DB00A51EAC /* JSAudioBufferCallback.h */; };
+ FE456F181677D74E005EDDF9 /* DatabaseManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE456F161677D74E005EDDF9 /* DatabaseManager.cpp */; };
+ FE456F191677D74E005EDDF9 /* DatabaseManager.h in Headers */ = {isa = PBXBuildFile; fileRef = FE456F171677D74E005EDDF9 /* DatabaseManager.h */; settings = {ATTRIBUTES = (Private, ); }; };
FE6FD4880F676E5700092873 /* Coordinates.h in Headers */ = {isa = PBXBuildFile; fileRef = FE6FD4850F676E5700092873 /* Coordinates.h */; settings = {ATTRIBUTES = (Private, ); }; };
FE6FD48D0F676E9300092873 /* JSCoordinates.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE6FD48B0F676E9300092873 /* JSCoordinates.cpp */; };
FE6FD48E0F676E9300092873 /* JSCoordinates.h in Headers */ = {isa = PBXBuildFile; fileRef = FE6FD48C0F676E9300092873 /* JSCoordinates.h */; };
@@ -13789,6 +13791,8 @@
F36E07A21358A8BE00AACBC9 /* WorkerInspectorController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WorkerInspectorController.cpp; sourceTree = "<group>"; };
F36E07A31358A8BE00AACBC9 /* WorkerInspectorController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WorkerInspectorController.h; sourceTree = "<group>"; };
F375CC061150D300008DDB81 /* InspectorWorkerResource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorWorkerResource.h; sourceTree = "<group>"; };
+ F37A56201679CF7B00C57046 /* HeapGraphSerializer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HeapGraphSerializer.cpp; sourceTree = "<group>"; };
+ F37A56211679CF7B00C57046 /* HeapGraphSerializer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HeapGraphSerializer.h; sourceTree = "<group>"; };
F3810C191365A49600ED6E33 /* InspectorWorkerAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorWorkerAgent.cpp; sourceTree = "<group>"; };
F3810C1A1365A49600ED6E33 /* InspectorWorkerAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorWorkerAgent.h; sourceTree = "<group>"; };
F382088A147D35F90010BC06 /* PageConsoleAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PageConsoleAgent.cpp; sourceTree = "<group>"; };
@@ -14848,6 +14852,8 @@
7AABA25814BC613300AA9A11 /* DOMEditor.h */,
7A54881614E432A1006AE05A /* DOMPatchSupport.cpp */,
7A54881514E432A1006AE05A /* DOMPatchSupport.h */,
+ F37A56201679CF7B00C57046 /* HeapGraphSerializer.cpp */,
+ F37A56211679CF7B00C57046 /* HeapGraphSerializer.h */,
5913A23F13D49EBA00F5B05C /* IdentifiersFactory.cpp */,
5913A24013D49EBA00F5B05C /* IdentifiersFactory.h */,
F3644AFD1119805900E0D537 /* InjectedScript.cpp */,
@@ -25927,6 +25933,7 @@
E1513D4F1677EA8300149FCB /* InitializeLogging.h in Headers */,
FDA9325E16703B2A008982DC /* OfflineAudioContext.h in Headers */,
FDA9326716703BA9008982DC /* JSOfflineAudioContext.h in Headers */,
+ F37A56231679CF7B00C57046 /* HeapGraphSerializer.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -29037,6 +29044,7 @@
FDA9325D16703B2A008982DC /* OfflineAudioContext.cpp in Sources */,
FDA9326616703BA9008982DC /* JSOfflineAudioContext.cpp in Sources */,
FE456F181677D74E005EDDF9 /* DatabaseManager.cpp in Sources */,
+ F37A56221679CF7B00C57046 /* HeapGraphSerializer.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Added: trunk/Source/WebCore/inspector/HeapGraphSerializer.cpp (0 => 137728)
--- trunk/Source/WebCore/inspector/HeapGraphSerializer.cpp (rev 0)
+++ trunk/Source/WebCore/inspector/HeapGraphSerializer.cpp 2012-12-14 08:44:17 UTC (rev 137728)
@@ -0,0 +1,206 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+#include "config.h"
+
+#if ENABLE(INSPECTOR)
+
+#include "HeapGraphSerializer.h"
+
+#include "InspectorValues.h"
+#include "WebCoreMemoryInstrumentation.h"
+#include <wtf/MemoryInstrumentationHashMap.h>
+#include <wtf/MemoryInstrumentationVector.h>
+#include <wtf/MemoryObjectInfo.h>
+#include <wtf/text/CString.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class HeapGraphNode {
+public:
+ HeapGraphNode()
+ : m_type(0)
+ , m_size(0)
+ , m_className(0)
+ , m_name(0)
+ , m_edgeCount(0)
+ {
+ }
+
+ int m_type;
+ unsigned m_size;
+ int m_className;
+ int m_name;
+ int m_edgeCount;
+};
+
+class HeapGraphEdge {
+public:
+ HeapGraphEdge()
+ : m_type(0)
+ , m_targetIndexIsKnown(false)
+ , m_toIndex(0)
+ , m_name(0)
+ {
+ }
+
+ int m_type;
+ bool m_targetIndexIsKnown;
+ union {
+ const void* m_toObject;
+ int m_toIndex;
+ };
+ int m_name;
+};
+
+HeapGraphSerializer::HeapGraphSerializer()
+ : m_lastReportedEdgeIndex(0)
+{
+ m_strings.append(String());
+}
+
+HeapGraphSerializer::~HeapGraphSerializer()
+{
+}
+
+void HeapGraphSerializer::reportNode(const WTF::MemoryObjectInfo& info)
+{
+ HeapGraphNode node;
+ node.m_type = addString(info.objectType());
+ node.m_size = info.objectSize();
+ node.m_className = addString(info.className());
+ node.m_name = addString(info.name());
+ // Node is always reported after its outgoing edges and leaves.
+ node.m_edgeCount = m_edges.size() - m_lastReportedEdgeIndex;
+ m_lastReportedEdgeIndex = m_edges.size();
+
+ m_objectToNodeIndex.set(info.reportedPointer(), m_nodes.size());
+ m_nodes.append(node);
+}
+
+void HeapGraphSerializer::reportEdge(const void*, const void* to, const char* name)
+{
+ HeapGraphEdge edge;
+ edge.m_toObject = to;
+ edge.m_name = addString(name);
+ m_edges.append(edge);
+}
+
+void HeapGraphSerializer::reportLeaf(const void*, const WTF::MemoryObjectInfo& info, const char* edgeName)
+{
+ HeapGraphNode node;
+ node.m_type = addString(info.objectType());
+ node.m_size = info.objectSize();
+ node.m_className = addString(info.className());
+ node.m_name = addString(info.name());
+
+ int nodeIndex = m_nodes.size();
+ m_nodes.append(node);
+
+ HeapGraphEdge edge;
+ edge.m_toIndex = nodeIndex;
+ edge.m_targetIndexIsKnown = true;
+ edge.m_name = addString(edgeName);
+ m_edges.append(edge);
+}
+
+void HeapGraphSerializer::reportBaseAddress(const void* base, const void* real)
+{
+ m_baseToRealAddress.set(base, real);
+}
+
+PassRefPtr<InspectorObject> HeapGraphSerializer::serialize()
+{
+ adjutEdgeTargets();
+ RefPtr<InspectorArray> nodes = InspectorArray::create();
+ for (size_t i = 0; i < m_nodes.size(); i++) {
+ HeapGraphNode& node = m_nodes[i];
+ nodes->pushInt(node.m_type);
+ nodes->pushInt(node.m_size);
+ nodes->pushInt(node.m_className);
+ nodes->pushInt(node.m_name);
+ nodes->pushInt(node.m_edgeCount);
+ }
+ RefPtr<InspectorArray> edges = InspectorArray::create();
+ for (size_t i = 0; i < m_edges.size(); i++) {
+ HeapGraphEdge& edge = m_edges[i];
+ edges->pushInt(edge.m_type);
+ edges->pushInt(edge.m_toIndex);
+ edges->pushInt(edge.m_name);
+ }
+ RefPtr<InspectorArray> strings = InspectorArray::create();
+ for (size_t i = 0; i < m_strings.size(); i++)
+ strings->pushString(m_strings[i]);
+
+ RefPtr<InspectorObject> graph = InspectorObject::create();
+ graph->setArray("nodes", nodes);
+ graph->setArray("edges", edges);
+ graph->setArray("strings", strings);
+ return graph.release();
+}
+
+void HeapGraphSerializer::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
+{
+ MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::Inspector);
+ info.addMember(m_stringToIndex);
+ info.addMember(m_strings);
+ info.addMember(m_objectToNodeIndex);
+ info.addMember(m_baseToRealAddress);
+ info.addMember(m_nodes);
+ info.addMember(m_edges);
+}
+
+int HeapGraphSerializer::addString(const String& string)
+{
+ if (string.isEmpty())
+ return 0;
+ StringMap::AddResult result = m_stringToIndex.add(string, m_strings.size());
+ if (result.isNewEntry)
+ m_strings.append(string);
+ return result.iterator->value;
+}
+
+void HeapGraphSerializer::adjutEdgeTargets()
+{
+ for (size_t i = 0; i < m_edges.size(); i++) {
+ HeapGraphEdge& edge = m_edges[i];
+ if (edge.m_targetIndexIsKnown)
+ continue;
+ const void* realTarget = m_baseToRealAddress.get(edge.m_toObject);
+ if (!realTarget)
+ realTarget = edge.m_toObject;
+ edge.m_toIndex = m_objectToNodeIndex.get(realTarget);
+ }
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(INSPECTOR)
Property changes on: trunk/Source/WebCore/inspector/HeapGraphSerializer.cpp
___________________________________________________________________
Added: svn:eol-style
Copied: trunk/Source/WebCore/inspector/HeapGraphSerializer.h (from rev 137726, trunk/Source/WebCore/inspector/InspectorMemoryAgent.h) (0 => 137728)
--- trunk/Source/WebCore/inspector/HeapGraphSerializer.h (rev 0)
+++ trunk/Source/WebCore/inspector/HeapGraphSerializer.h 2012-12-14 08:44:17 UTC (rev 137728)
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+#ifndef HeapGraphSerializer_h
+#define HeapGraphSerializer_h
+
+#if ENABLE(INSPECTOR)
+
+#include <wtf/Forward.h>
+#include <wtf/HashMap.h>
+#include <wtf/MemoryInstrumentation.h>
+#include <wtf/Noncopyable.h>
+#include <wtf/Vector.h>
+#include <wtf/text/StringHash.h>
+
+namespace WebCore {
+
+class HeapGraphEdge;
+class HeapGraphNode;
+class InspectorObject;
+
+class HeapGraphSerializer {
+ WTF_MAKE_NONCOPYABLE(HeapGraphSerializer);
+public:
+ HeapGraphSerializer();
+ ~HeapGraphSerializer();
+ void reportNode(const WTF::MemoryObjectInfo&);
+ void reportEdge(const void*, const void*, const char*);
+ void reportLeaf(const void*, const WTF::MemoryObjectInfo&, const char*);
+ void reportBaseAddress(const void*, const void*);
+
+ PassRefPtr<InspectorObject> serialize();
+
+ void reportMemoryUsage(MemoryObjectInfo*) const;
+
+private:
+ int addString(const String&);
+ void adjutEdgeTargets();
+
+ typedef HashMap<String, int> StringMap;
+ StringMap m_stringToIndex;
+ Vector<String> m_strings;
+ int m_lastReportedEdgeIndex;
+
+ typedef HashMap<const void*, int> ObjectToNodeIndex;
+ ObjectToNodeIndex m_objectToNodeIndex;
+
+ typedef HashMap<const void*, const void*> BaseToRealAddress;
+ BaseToRealAddress m_baseToRealAddress;
+
+ Vector<HeapGraphNode> m_nodes;
+ Vector<HeapGraphEdge> m_edges;
+};
+
+} // namespace WebCore
+
+#endif // !ENABLE(INSPECTOR)
+#endif // !defined(HeapGraphSerializer_h)
Modified: trunk/Source/WebCore/inspector/Inspector.json (137727 => 137728)
--- trunk/Source/WebCore/inspector/Inspector.json 2012-12-14 08:33:54 UTC (rev 137727)
+++ trunk/Source/WebCore/inspector/Inspector.json 2012-12-14 08:44:17 UTC (rev 137728)
@@ -101,8 +101,12 @@
},
{
"name": "getProcessMemoryDistribution",
+ "parameters": [
+ { "name": "reportGraph", "type": "boolean", "optional": true, "description": "Whether native memory graph should be reported in addition to aggregated statistics." }
+ ],
"returns": [
- { "name": "distribution", "$ref": "MemoryBlock", "description": "An object describing all memory allocated by the process"}
+ { "name": "distribution", "$ref": "MemoryBlock", "description": "An object describing all memory allocated by the process"},
+ { "name": "graph", "type": "object", "optional": true, "description": "Native memory graph."}
]
}
]
Modified: trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp (137727 => 137728)
--- trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp 2012-12-14 08:33:54 UTC (rev 137727)
+++ trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp 2012-12-14 08:44:17 UTC (rev 137728)
@@ -39,6 +39,7 @@
#include "Document.h"
#include "EventListenerMap.h"
#include "Frame.h"
+#include "HeapGraphSerializer.h"
#include "InspectorClient.h"
#include "InspectorDOMStorageAgent.h"
#include "InspectorFrontend.h"
@@ -535,9 +536,12 @@
}
}
-void InspectorMemoryAgent::getProcessMemoryDistribution(ErrorString*, RefPtr<InspectorMemoryBlock>& processMemory)
+void InspectorMemoryAgent::getProcessMemoryDistribution(ErrorString*, const bool* reportGraph, RefPtr<InspectorMemoryBlock>& processMemory, RefPtr<InspectorObject>& graph)
{
- MemoryInstrumentationClientImpl memoryInstrumentationClient;
+ OwnPtr<HeapGraphSerializer> graphSerializer;
+ if (reportGraph)
+ graphSerializer = adoptPtr(new HeapGraphSerializer());
+ MemoryInstrumentationClientImpl memoryInstrumentationClient(graphSerializer.get());
m_inspectorClient->getAllocatedObjects(memoryInstrumentationClient.allocatedObjects());
MemoryInstrumentationImpl memoryInstrumentation(&memoryInstrumentationClient);
@@ -554,6 +558,10 @@
memoryInstrumentation.addRootObject(this);
memoryInstrumentation.addRootObject(memoryInstrumentation);
memoryInstrumentation.addRootObject(memoryInstrumentationClient);
+ if (graphSerializer) {
+ memoryInstrumentation.addRootObject(graphSerializer.get());
+ graph = graphSerializer->serialize();
+ }
m_inspectorClient->dumpUncountedAllocatedObjects(memoryInstrumentationClient.countedObjects());
Modified: trunk/Source/WebCore/inspector/InspectorMemoryAgent.h (137727 => 137728)
--- trunk/Source/WebCore/inspector/InspectorMemoryAgent.h 2012-12-14 08:33:54 UTC (rev 137727)
+++ trunk/Source/WebCore/inspector/InspectorMemoryAgent.h 2012-12-14 08:44:17 UTC (rev 137728)
@@ -59,7 +59,7 @@
virtual ~InspectorMemoryAgent();
virtual void getDOMNodeCount(ErrorString*, RefPtr<TypeBuilder::Array<TypeBuilder::Memory::DOMGroup> >& domGroups, RefPtr<TypeBuilder::Memory::StringStatistics>& strings);
- virtual void getProcessMemoryDistribution(ErrorString*, RefPtr<TypeBuilder::Memory::MemoryBlock>& processMemory);
+ virtual void getProcessMemoryDistribution(ErrorString*, const bool* reportGraph, RefPtr<TypeBuilder::Memory::MemoryBlock>& processMemory, RefPtr<InspectorObject>& graph);
virtual void reportMemoryUsage(MemoryObjectInfo*) const;
Modified: trunk/Source/WebCore/inspector/MemoryInstrumentationImpl.cpp (137727 => 137728)
--- trunk/Source/WebCore/inspector/MemoryInstrumentationImpl.cpp 2012-12-14 08:33:54 UTC (rev 137727)
+++ trunk/Source/WebCore/inspector/MemoryInstrumentationImpl.cpp 2012-12-14 08:44:17 UTC (rev 137728)
@@ -34,6 +34,7 @@
#include "MemoryInstrumentationImpl.h"
+#include "HeapGraphSerializer.h"
#include "WebCoreMemoryInstrumentation.h"
#include <wtf/Assertions.h>
#include <wtf/MemoryInstrumentationHashMap.h>
@@ -94,6 +95,30 @@
return true;
}
+void MemoryInstrumentationClientImpl::reportNode(const MemoryObjectInfo& node)
+{
+ if (m_graphSerializer)
+ m_graphSerializer->reportNode(node);
+}
+
+void MemoryInstrumentationClientImpl::reportEdge(const void* source, const void* target, const char* name)
+{
+ if (m_graphSerializer)
+ m_graphSerializer->reportEdge(source, target, name);
+}
+
+void MemoryInstrumentationClientImpl::reportLeaf(const void* owner, const MemoryObjectInfo& target, const char* edgeName)
+{
+ if (m_graphSerializer)
+ m_graphSerializer->reportLeaf(owner, target, edgeName);
+}
+
+void MemoryInstrumentationClientImpl::reportBaseAddress(const void* base, const void* real)
+{
+ if (m_graphSerializer)
+ m_graphSerializer->reportBaseAddress(base, real);
+}
+
void MemoryInstrumentationClientImpl::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
{
MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::InspectorMemoryAgent);
Modified: trunk/Source/WebCore/inspector/MemoryInstrumentationImpl.h (137727 => 137728)
--- trunk/Source/WebCore/inspector/MemoryInstrumentationImpl.h 2012-12-14 08:33:54 UTC (rev 137727)
+++ trunk/Source/WebCore/inspector/MemoryInstrumentationImpl.h 2012-12-14 08:44:17 UTC (rev 137728)
@@ -43,6 +43,8 @@
namespace WebCore {
+class HeapGraphSerializer;
+
typedef HashSet<const void*> VisitedObjects;
typedef HashMap<String, size_t> TypeNameToSizeMap;
@@ -50,9 +52,10 @@
public:
typedef HashMap<const void*, size_t> ObjectToSizeMap;
- MemoryInstrumentationClientImpl()
+ explicit MemoryInstrumentationClientImpl(HeapGraphSerializer* serializer)
: m_totalCountedObjects(0)
, m_totalObjectsNotInAllocatedSet(0)
+ , m_graphSerializer(serializer)
{ }
size_t totalSize(MemoryObjectType objectType) const
@@ -81,10 +84,10 @@
virtual void countObjectSize(const void*, MemoryObjectType, size_t) OVERRIDE;
virtual bool visited(const void*) OVERRIDE;
virtual bool checkCountedObject(const void*) OVERRIDE;
- virtual void reportNode(const MemoryObjectInfo&) OVERRIDE { }
- virtual void reportEdge(const void*, const void*, const char*) OVERRIDE { }
- virtual void reportLeaf(const void*, const MemoryObjectInfo&, const char*) OVERRIDE { }
- virtual void reportBaseAddress(const void*, const void*) OVERRIDE { }
+ virtual void reportNode(const MemoryObjectInfo&) OVERRIDE;
+ virtual void reportEdge(const void*, const void*, const char*) OVERRIDE;
+ virtual void reportLeaf(const void*, const MemoryObjectInfo&, const char*) OVERRIDE;
+ virtual void reportBaseAddress(const void*, const void*) OVERRIDE;
void reportMemoryUsage(MemoryObjectInfo*) const;
@@ -96,6 +99,7 @@
ObjectToSizeMap m_countedObjects;
size_t m_totalCountedObjects;
size_t m_totalObjectsNotInAllocatedSet;
+ HeapGraphSerializer* m_graphSerializer;
};
class MemoryInstrumentationImpl : public WTF::MemoryInstrumentation {