Title: [121530] trunk/Source/WebCore
Revision
121530
Author
[email protected]
Date
2012-06-29 01:46:04 -0700 (Fri, 29 Jun 2012)

Log Message

Web Inspector: add character data to the DOM section of native memory view
https://bugs.webkit.org/show_bug.cgi?id=89968

Reviewed by Vsevolod Vlasov.

Count strings referenced from CharacterData node and its descendants
as part of the DOM tree structures in the native memory view.

* dom/CharacterData.cpp:
(WebCore::CharacterData::reportMemoryUsage):
(WebCore):
* dom/CharacterData.h:
(CharacterData):
* dom/MemoryInstrumentation.h:
(MemoryInstrumentation):
(WebCore::MemoryObjectInfo::reportString):
(MemoryObjectInfo):
* inspector/InspectorMemoryAgent.cpp:
(WebCore):
(WebCore::domTreeInfo):
(WebCore::jsExternalResourcesInfo):
(WebCore::InspectorMemoryAgent::getProcessMemoryDistribution):
* inspector/front-end/NativeMemorySnapshotView.js:
(WebInspector.MemoryBlockViewProperties._initialize):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (121529 => 121530)


--- trunk/Source/WebCore/ChangeLog	2012-06-29 08:28:15 UTC (rev 121529)
+++ trunk/Source/WebCore/ChangeLog	2012-06-29 08:46:04 UTC (rev 121530)
@@ -1,3 +1,30 @@
+2012-06-26  Yury Semikhatsky  <[email protected]>
+
+        Web Inspector: add character data to the DOM section of native memory view
+        https://bugs.webkit.org/show_bug.cgi?id=89968
+
+        Reviewed by Vsevolod Vlasov.
+
+        Count strings referenced from CharacterData node and its descendants
+        as part of the DOM tree structures in the native memory view.
+
+        * dom/CharacterData.cpp:
+        (WebCore::CharacterData::reportMemoryUsage):
+        (WebCore):
+        * dom/CharacterData.h:
+        (CharacterData):
+        * dom/MemoryInstrumentation.h:
+        (MemoryInstrumentation):
+        (WebCore::MemoryObjectInfo::reportString):
+        (MemoryObjectInfo):
+        * inspector/InspectorMemoryAgent.cpp:
+        (WebCore):
+        (WebCore::domTreeInfo):
+        (WebCore::jsExternalResourcesInfo):
+        (WebCore::InspectorMemoryAgent::getProcessMemoryDistribution):
+        * inspector/front-end/NativeMemorySnapshotView.js:
+        (WebInspector.MemoryBlockViewProperties._initialize):
+
 2012-06-29  Eric Seidel  <[email protected]>
 
         Remove more BUILDING_ON_LEOPARD branches now that no port builds on Leopard

Modified: trunk/Source/WebCore/dom/CharacterData.cpp (121529 => 121530)


--- trunk/Source/WebCore/dom/CharacterData.cpp	2012-06-29 08:28:15 UTC (rev 121529)
+++ trunk/Source/WebCore/dom/CharacterData.cpp	2012-06-29 08:46:04 UTC (rev 121530)
@@ -26,6 +26,7 @@
 #include "EventNames.h"
 #include "ExceptionCode.h"
 #include "InspectorInstrumentation.h"
+#include "MemoryInstrumentation.h"
 #include "MutationEvent.h"
 #include "MutationObserverInterestGroup.h"
 #include "MutationRecord.h"
@@ -92,6 +93,13 @@
     return end;
 }
 
+void CharacterData::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
+{
+    memoryObjectInfo->reportObjectInfo(this, MemoryInstrumentation::DOM);
+    Node::reportMemoryUsage(memoryObjectInfo);
+    memoryObjectInfo->reportString(m_data);
+}
+
 void CharacterData::appendData(const String& data, ExceptionCode&)
 {
     String newStr = m_data;

Modified: trunk/Source/WebCore/dom/CharacterData.h (121529 => 121530)


--- trunk/Source/WebCore/dom/CharacterData.h	2012-06-29 08:28:15 UTC (rev 121529)
+++ trunk/Source/WebCore/dom/CharacterData.h	2012-06-29 08:46:04 UTC (rev 121530)
@@ -47,6 +47,8 @@
     // Returns how much could be added before length limit was met.
     unsigned parserAppendData(const UChar*, unsigned dataLength, unsigned lengthLimit);
 
+    virtual void reportMemoryUsage(MemoryObjectInfo*) const;
+
 protected:
     CharacterData(Document* document, const String& text, ConstructionType type)
         : Node(document, type)

Modified: trunk/Source/WebCore/dom/MemoryInstrumentation.h (121529 => 121530)


--- trunk/Source/WebCore/dom/MemoryInstrumentation.h	2012-06-29 08:28:15 UTC (rev 121529)
+++ trunk/Source/WebCore/dom/MemoryInstrumentation.h	2012-06-29 08:46:04 UTC (rev 121530)
@@ -31,6 +31,7 @@
 #ifndef MemoryInstrumentation_h
 #define MemoryInstrumentation_h
 
+#include <wtf/Forward.h>
 #include <wtf/OwnPtr.h>
 #include <wtf/RefPtr.h>
 
@@ -62,6 +63,7 @@
 private:
     friend class MemoryObjectInfo;
 
+    virtual void reportString(ObjectType, const String&) = 0;
     virtual void countObjectSize(ObjectType, size_t) = 0;
     virtual bool visited(const void*) = 0;
 };
@@ -104,6 +106,11 @@
         m_objectSize = sizeof(T);
     }
 
+    void reportString(const String& string)
+    {
+        m_memoryInstrumentation->reportString(objectType(), string);
+    }
+
     MemoryInstrumentation::ObjectType objectType() const { return m_objectType; }
     size_t objectSize() const { return m_objectSize; }
 

Modified: trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp (121529 => 121530)


--- trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp	2012-06-29 08:28:15 UTC (rev 121529)
+++ trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp	2012-06-29 08:46:04 UTC (rev 121530)
@@ -55,6 +55,8 @@
 #include <wtf/ArrayBufferView.h>
 #include <wtf/HashSet.h>
 #include <wtf/text/StringBuilder.h>
+#include <wtf/text/StringImpl.h>
+#include <wtf/text/WTFString.h>
 
 using WebCore::TypeBuilder::Memory::DOMGroup;
 using WebCore::TypeBuilder::Memory::ListenerCount;
@@ -92,6 +94,8 @@
 
 namespace {
 
+typedef HashSet<const void*> VisitedObjects;
+
 String nodeName(Node* node)
 {
     if (node->document()->isXHTMLDocument())
@@ -101,8 +105,15 @@
 
 size_t stringSize(StringImpl* string)
 {
+    // TODO: support substrings
     size_t size = string->length();
-    if (!string->is8Bit())
+    if (string->is8Bit()) {
+        if (string->has16BitShadow()) {
+            size += 2 * size;
+            if (string->hasTerminatingNullCharacter())
+                size += 2;
+        }
+    } else
         size *= 2;
     return size + sizeof(*string);
 }
@@ -315,8 +326,9 @@
 
 class ExternalResourceVisitor : public ExternalStringVisitor, public ExternalArrayVisitor {
 public:
-    ExternalResourceVisitor()
-        : m_jsExternalStringSize(0)
+    explicit ExternalResourceVisitor(VisitedObjects& visitedObjects)
+        : m_visitedObjects(visitedObjects)
+        , m_jsExternalStringSize(0)
         , m_externalArraySize(0)
     { }
 
@@ -327,18 +339,18 @@
     virtual void visitJSExternalArray(ArrayBufferView* bufferView)
     {
         ArrayBuffer* buffer = bufferView->buffer().get();
-        if (m_arrayBuffers.add(buffer).isNewEntry)
+        if (m_visitedObjects.add(buffer).isNewEntry)
             m_externalArraySize += buffer->byteLength();
     }
     virtual void visitJSExternalString(StringImpl* string)
     {
-        int size = stringSize(string);
-        m_jsExternalStringSize += size;
+        if (m_visitedObjects.add(string).isNewEntry)
+            m_jsExternalStringSize += stringSize(string);
     }
 
+    VisitedObjects& m_visitedObjects;
     size_t m_jsExternalStringSize;
     size_t m_externalArraySize;
-    HashSet<ArrayBuffer*> m_arrayBuffers;
 };
 
 } // namespace
@@ -418,7 +430,8 @@
 
 class MemoryInstrumentationImpl : public MemoryInstrumentation {
 public:
-    MemoryInstrumentationImpl()
+    explicit MemoryInstrumentationImpl(VisitedObjects& visitedObjects)
+        : m_visitedObjects(visitedObjects)
     {
         for (int i = 0; i < LastTypeEntry; ++i)
             m_totalSizes[i] = 0;
@@ -442,6 +455,13 @@
     }
 
 private:
+    virtual void reportString(ObjectType objectType, const String& string)
+    {
+        if (visited(string.impl()))
+            return;
+        countObjectSize(objectType, stringSize(string.impl()));
+    }
+
     virtual void countObjectSize(ObjectType objectType, size_t size)
     {
         ASSERT(objectType >= 0 && objectType < LastTypeEntry);
@@ -453,13 +473,16 @@
         return !m_visitedObjects.add(object).isNewEntry;
     }
     size_t m_totalSizes[LastTypeEntry];
-    typedef HashSet<const void*> VisitedObjects;
-    VisitedObjects m_visitedObjects;
+    VisitedObjects& m_visitedObjects;
 };
 
 class DOMTreesIterator : public NodeWrapperVisitor {
 public:
-    explicit DOMTreesIterator(Page* page) : m_page(page) { }
+    DOMTreesIterator(Page* page, VisitedObjects& visitedObjects)
+        : m_page(page)
+        , m_domMemoryUsage(visitedObjects)
+    {
+    }
 
     virtual void visitNode(Node* node)
     {
@@ -478,9 +501,9 @@
 
 }
 
-static PassRefPtr<InspectorMemoryBlock> domTreeInfo(Page* page)
+static PassRefPtr<InspectorMemoryBlock> domTreeInfo(Page* page, VisitedObjects& visitedObjects)
 {
-    DOMTreesIterator domTreesIterator(page);
+    DOMTreesIterator domTreesIterator(page, visitedObjects);
     ScriptProfiler::visitNodeWrappers(&domTreesIterator);
 
     // Make sure all documents reachable from the main frame are accounted.
@@ -513,9 +536,9 @@
     return memoryCacheStats.release();
 }
 
-static PassRefPtr<InspectorMemoryBlock> jsExternalResourcesInfo()
+static PassRefPtr<InspectorMemoryBlock> jsExternalResourcesInfo(VisitedObjects& visitedObjects)
 {
-    ExternalResourceVisitor visitor;
+    ExternalResourceVisitor visitor(visitedObjects);
     ScriptProfiler::visitExternalStrings(&visitor);
     ScriptProfiler::visitExternalArrays(&visitor);
 
@@ -542,13 +565,14 @@
     processMemory = InspectorMemoryBlock::create().setName(MemoryBlockName::processPrivateMemory);
     processMemory->setSize(privateBytes);
 
+    VisitedObjects visitedObjects;
     RefPtr<TypeBuilder::Array<InspectorMemoryBlock> > children = TypeBuilder::Array<InspectorMemoryBlock>::create();
     children->addItem(jsHeapInfo());
-    children->addItem(jsExternalResourcesInfo());
     children->addItem(inspectorData());
     children->addItem(memoryCacheInfo());
     children->addItem(renderTreeInfo(m_page)); // TODO: collect for all pages?
-    children->addItem(domTreeInfo(m_page)); // TODO: collect for all pages?
+    children->addItem(domTreeInfo(m_page, visitedObjects)); // TODO: collect for all pages?
+    children->addItem(jsExternalResourcesInfo(visitedObjects));
     processMemory->setChildren(children);
 }
 

Modified: trunk/Source/WebCore/inspector/front-end/NativeMemorySnapshotView.js (121529 => 121530)


--- trunk/Source/WebCore/inspector/front-end/NativeMemorySnapshotView.js	2012-06-29 08:28:15 UTC (rev 121529)
+++ trunk/Source/WebCore/inspector/front-end/NativeMemorySnapshotView.js	2012-06-29 08:46:04 UTC (rev 121530)
@@ -216,6 +216,7 @@
     }
     addBlock("hsl(  0,  0%, 100%)", "ProcessPrivateMemory", "Total");
     addBlock("hsl(  0,  0%,  80%)", "Other", "Other");
+    addBlock("hsl(300, 30%,  80%)", "DOM", "DOM tree structures");
     addBlock("hsl( 90, 60%,  80%)", "JSHeapAllocated", "_javascript_ heap");
     addBlock("hsl( 90, 80%,  80%)", "JSHeapUsed", "Used _javascript_ heap");
     addBlock("hsl( 90, 30%,  80%)", "JSExternalResources", "_javascript_ external resources");
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to