Web Inspector: add memory reporting routine to Document
authoryurys@chromium.org <yurys@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Jul 2012 11:25:28 +0000 (11:25 +0000)
committeryurys@chromium.org <yurys@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Jul 2012 11:25:28 +0000 (11:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=90668

Reviewed by Pavel Feldman.

Added methods for reporting HashSet, ListHashSet and Vector memory
footprint. Made Document report its size along with its internal
collections sizes.

* dom/Document.cpp:
(WebCore::Document::reportMemoryUsage):
(WebCore):
* dom/Document.h:
(Document):
* dom/MemoryInstrumentation.h:
(MemoryInstrumentation):
(MemoryObjectInfo):
(WebCore::MemoryObjectInfo::reportHashMap):
(WebCore::MemoryObjectInfo::reportHashSet):
(WebCore::MemoryObjectInfo::reportListHashSet):
(WebCore::MemoryObjectInfo::reportVector):
(WebCore::MemoryObjectInfo::memoryInstrumentation):
(WebCore::MemoryInstrumentation::reportHashMap):
(WebCore):
(WebCore::MemoryInstrumentation::reportHashSet):
(WebCore::MemoryInstrumentation::reportListHashSet):
(WebCore::MemoryInstrumentation::reportVector):
* inspector/InspectorMemoryAgent.cpp:
(WebCore):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@121952 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/MemoryInstrumentation.h
Source/WebCore/inspector/InspectorMemoryAgent.cpp

index 489491d..bfbbcec 100644 (file)
@@ -1,3 +1,35 @@
+2012-07-06  Yury Semikhatsky  <yurys@chromium.org>
+
+        Web Inspector: add memory reporting routine to Document
+        https://bugs.webkit.org/show_bug.cgi?id=90668
+
+        Reviewed by Pavel Feldman.
+
+        Added methods for reporting HashSet, ListHashSet and Vector memory
+        footprint. Made Document report its size along with its internal
+        collections sizes.
+
+        * dom/Document.cpp:
+        (WebCore::Document::reportMemoryUsage):
+        (WebCore):
+        * dom/Document.h:
+        (Document):
+        * dom/MemoryInstrumentation.h:
+        (MemoryInstrumentation):
+        (MemoryObjectInfo):
+        (WebCore::MemoryObjectInfo::reportHashMap):
+        (WebCore::MemoryObjectInfo::reportHashSet):
+        (WebCore::MemoryObjectInfo::reportListHashSet):
+        (WebCore::MemoryObjectInfo::reportVector):
+        (WebCore::MemoryObjectInfo::memoryInstrumentation):
+        (WebCore::MemoryInstrumentation::reportHashMap):
+        (WebCore):
+        (WebCore::MemoryInstrumentation::reportHashSet):
+        (WebCore::MemoryInstrumentation::reportListHashSet):
+        (WebCore::MemoryInstrumentation::reportVector):
+        * inspector/InspectorMemoryAgent.cpp:
+        (WebCore):
+
 2012-07-06  Gabor Rapcsanyi  <rgabor@webkit.org>
 
         Fixing defines for NEON intrinsics.
index 2b0cf08..adde312 100644 (file)
 #include "Logging.h"
 #include "MediaQueryList.h"
 #include "MediaQueryMatcher.h"
+#include "MemoryInstrumentation.h"
 #include "MouseEventWithHitTestResults.h"
 #include "NameNodeList.h"
 #include "NestingLevelIncrementer.h"
@@ -5994,6 +5995,42 @@ void Document::setContextFeatures(PassRefPtr<ContextFeatures> features)
     m_contextFeatures = features;
 }
 
+void Document::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
+{
+    memoryObjectInfo->reportObjectInfo(this, MemoryInstrumentation::DOM);
+    ContainerNode::reportMemoryUsage(memoryObjectInfo);
+    memoryObjectInfo->reportVector(m_customFonts);
+    memoryObjectInfo->reportString(m_documentURI);
+    memoryObjectInfo->reportString(m_baseTarget);
+    if (m_pageGroupUserSheets)
+        memoryObjectInfo->reportVector(*m_pageGroupUserSheets.get());
+    if (m_userSheets)
+        memoryObjectInfo->reportVector(*m_userSheets.get());
+    memoryObjectInfo->reportHashSet(m_nodeIterators);
+    memoryObjectInfo->reportHashSet(m_ranges);
+    memoryObjectInfo->reportListHashSet(m_styleSheetCandidateNodes);
+    memoryObjectInfo->reportString(m_preferredStylesheetSet);
+    memoryObjectInfo->reportString(m_selectedStylesheetSet);
+    memoryObjectInfo->reportString(m_title.string());
+    memoryObjectInfo->reportString(m_rawTitle.string());
+    memoryObjectInfo->reportString(m_xmlEncoding);
+    memoryObjectInfo->reportString(m_xmlVersion);
+    memoryObjectInfo->reportString(m_contentLanguage);
+    memoryObjectInfo->reportHashMap(m_documentNamedItemCollections);
+    memoryObjectInfo->reportHashMap(m_windowNamedItemCollections);
+#if ENABLE(DASHBOARD_SUPPORT)
+    memoryObjectInfo->reportVector(m_dashboardRegions);
+#endif
+    memoryObjectInfo->reportHashMap(m_cssCanvasElements);
+    memoryObjectInfo->reportVector(m_iconURLs);
+    memoryObjectInfo->reportHashSet(m_documentSuspensionCallbackElements);
+    memoryObjectInfo->reportHashSet(m_mediaVolumeCallbackElements);
+    memoryObjectInfo->reportHashSet(m_privateBrowsingStateChangedElements);
+    memoryObjectInfo->reportHashMap(m_elementsByAccessKey);
+    memoryObjectInfo->reportHashSet(m_mediaCanStartListeners);
+    memoryObjectInfo->reportVector(m_pendingTasks);
+}
+
 #if ENABLE(UNDO_MANAGER)
 PassRefPtr<UndoManager> Document::undoManager()
 {
index 694b17b..98059aa 100644 (file)
@@ -1143,6 +1143,8 @@ public:
     void setContextFeatures(PassRefPtr<ContextFeatures>);
     ContextFeatures* contextFeatures() { return m_contextFeatures.get(); }
 
+    virtual void reportMemoryUsage(MemoryObjectInfo*) const OVERRIDE;
+
 protected:
     Document(Frame*, const KURL&, bool isXHTML, bool isHTML);
 
index 50a8a6d..1d99a12 100644 (file)
@@ -61,7 +61,10 @@ public:
             return;
         countObjectSize(objectType, sizeof(T));
     }
-    template <typename HashMapType> void reportHashMap(const HashMapType&, ObjectType);
+    template <typename HashMapType> void reportHashMap(const HashMapType&, ObjectType, bool contentOnly = false);
+    template <typename HashSetType> void reportHashSet(const HashSetType&, ObjectType, bool contentOnly = false);
+    template <typename ListHashSetType> void reportListHashSet(const ListHashSetType&, ObjectType, bool contentOnly = false);
+    template <typename VectorType> void reportVector(const VectorType&, ObjectType, bool contentOnly = false);
 
 protected:
     class InstrumentedPointerBase {
@@ -129,6 +132,30 @@ public:
         m_objectSize = sizeof(T);
     }
 
+    template <typename HashMapType>
+    void reportHashMap(const HashMapType& map)
+    {
+        m_memoryInstrumentation->reportHashMap(map, objectType(), true);
+    }
+
+    template <typename HashSetType>
+    void reportHashSet(const HashSetType& set)
+    {
+        m_memoryInstrumentation->reportHashSet(set, objectType(), true);
+    }
+
+    template <typename ListHashSetType>
+    void reportListHashSet(const ListHashSetType& set)
+    {
+        m_memoryInstrumentation->reportListHashSet(set, objectType(), true);
+    }
+
+    template <typename VectorType>
+    void reportVector(const VectorType& vector)
+    {
+        m_memoryInstrumentation->reportVector(vector, objectType(), true);
+    }
+
     void reportString(const String& string)
     {
         m_memoryInstrumentation->reportString(objectType(), string);
@@ -137,6 +164,8 @@ public:
     MemoryInstrumentation::ObjectType objectType() const { return m_objectType; }
     size_t objectSize() const { return m_objectSize; }
 
+    MemoryInstrumentation* memoryInstrumentation() { return m_memoryInstrumentation; }
+
  private:
     MemoryInstrumentation* m_memoryInstrumentation;
     MemoryInstrumentation::ObjectType m_objectType;
@@ -161,9 +190,36 @@ void MemoryInstrumentation::reportInstrumentedObject(const T& object)
 }
 
 template<typename HashMapType>
-void MemoryInstrumentation::reportHashMap(const HashMapType& hashMap, ObjectType objectType)
+void MemoryInstrumentation::reportHashMap(const HashMapType& hashMap, ObjectType objectType, bool contentOnly)
+{
+    size_t size = (contentOnly ? 0 : sizeof(HashMapType)) + hashMap.capacity() * sizeof(typename HashMapType::ValueType);
+    countObjectSize(objectType, size);
+}
+
+template<typename HashSetType>
+void MemoryInstrumentation::reportHashSet(const HashSetType& hashSet, ObjectType objectType, bool contentOnly)
+{
+    if (visited(&hashSet))
+        return;
+    size_t size = (contentOnly ? 0 : sizeof(HashSetType)) + hashSet.capacity() * sizeof(typename HashSetType::ValueType);
+    countObjectSize(objectType, size);
+}
+
+template<typename ListHashSetType>
+void MemoryInstrumentation::reportListHashSet(const ListHashSetType& hashSet, ObjectType objectType, bool contentOnly)
 {
-    size_t size = sizeof(HashMapType) + hashMap.capacity() * sizeof(typename HashMapType::ValueType);
+    if (visited(&hashSet))
+        return;
+    size_t size = (contentOnly ? 0 : sizeof(ListHashSetType)) + hashSet.capacity() * sizeof(void*) + hashSet.size() * (sizeof(typename ListHashSetType::ValueType) + 2 * sizeof(void*));
+    countObjectSize(objectType, size);
+}
+
+template <typename VectorType>
+void MemoryInstrumentation::reportVector(const VectorType& vector, ObjectType objectType, bool contentOnly)
+{
+    if (visited(vector.data()))
+        return;
+    size_t size = (contentOnly ? 0 : sizeof(VectorType)) + vector.capacity() * sizeof(typename VectorType::ValueType);
     countObjectSize(objectType, size);
 }
 
index ce46685..e907257 100644 (file)
@@ -471,7 +471,7 @@ public:
 private:
     virtual void reportString(ObjectType objectType, const String& string)
     {
-        if (visited(string.impl()))
+        if (string.isNull() || visited(string.impl()))
             return;
         countObjectSize(objectType, stringSize(string.impl()));
     }