Changeset 121530 in webkit


Ignore:
Timestamp:
Jun 29, 2012 1:46:04 AM (12 years ago)
Author:
yurys@chromium.org
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):

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r121529 r121530  
     12012-06-26  Yury Semikhatsky  <yurys@chromium.org>
     2
     3        Web Inspector: add character data to the DOM section of native memory view
     4        https://bugs.webkit.org/show_bug.cgi?id=89968
     5
     6        Reviewed by Vsevolod Vlasov.
     7
     8        Count strings referenced from CharacterData node and its descendants
     9        as part of the DOM tree structures in the native memory view.
     10
     11        * dom/CharacterData.cpp:
     12        (WebCore::CharacterData::reportMemoryUsage):
     13        (WebCore):
     14        * dom/CharacterData.h:
     15        (CharacterData):
     16        * dom/MemoryInstrumentation.h:
     17        (MemoryInstrumentation):
     18        (WebCore::MemoryObjectInfo::reportString):
     19        (MemoryObjectInfo):
     20        * inspector/InspectorMemoryAgent.cpp:
     21        (WebCore):
     22        (WebCore::domTreeInfo):
     23        (WebCore::jsExternalResourcesInfo):
     24        (WebCore::InspectorMemoryAgent::getProcessMemoryDistribution):
     25        * inspector/front-end/NativeMemorySnapshotView.js:
     26        (WebInspector.MemoryBlockViewProperties._initialize):
     27
    1282012-06-29  Eric Seidel  <eric@webkit.org>
    229
  • trunk/Source/WebCore/dom/CharacterData.cpp

    r119705 r121530  
    2727#include "ExceptionCode.h"
    2828#include "InspectorInstrumentation.h"
     29#include "MemoryInstrumentation.h"
    2930#include "MutationEvent.h"
    3031#include "MutationObserverInterestGroup.h"
     
    9394}
    9495
     96void CharacterData::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
     97{
     98    memoryObjectInfo->reportObjectInfo(this, MemoryInstrumentation::DOM);
     99    Node::reportMemoryUsage(memoryObjectInfo);
     100    memoryObjectInfo->reportString(m_data);
     101}
     102
    95103void CharacterData::appendData(const String& data, ExceptionCode&)
    96104{
  • trunk/Source/WebCore/dom/CharacterData.h

    r113312 r121530  
    4848    unsigned parserAppendData(const UChar*, unsigned dataLength, unsigned lengthLimit);
    4949
     50    virtual void reportMemoryUsage(MemoryObjectInfo*) const;
     51
    5052protected:
    5153    CharacterData(Document* document, const String& text, ConstructionType type)
  • trunk/Source/WebCore/dom/MemoryInstrumentation.h

    r121022 r121530  
    3232#define MemoryInstrumentation_h
    3333
     34#include <wtf/Forward.h>
    3435#include <wtf/OwnPtr.h>
    3536#include <wtf/RefPtr.h>
     
    6364    friend class MemoryObjectInfo;
    6465
     66    virtual void reportString(ObjectType, const String&) = 0;
    6567    virtual void countObjectSize(ObjectType, size_t) = 0;
    6668    virtual bool visited(const void*) = 0;
     
    105107    }
    106108
     109    void reportString(const String& string)
     110    {
     111        m_memoryInstrumentation->reportString(objectType(), string);
     112    }
     113
    107114    MemoryInstrumentation::ObjectType objectType() const { return m_objectType; }
    108115    size_t objectSize() const { return m_objectSize; }
  • trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp

    r121144 r121530  
    5656#include <wtf/HashSet.h>
    5757#include <wtf/text/StringBuilder.h>
     58#include <wtf/text/StringImpl.h>
     59#include <wtf/text/WTFString.h>
    5860
    5961using WebCore::TypeBuilder::Memory::DOMGroup;
     
    9395namespace {
    9496
     97typedef HashSet<const void*> VisitedObjects;
     98
    9599String nodeName(Node* node)
    96100{
     
    102106size_t stringSize(StringImpl* string)
    103107{
     108    // TODO: support substrings
    104109    size_t size = string->length();
    105     if (!string->is8Bit())
     110    if (string->is8Bit()) {
     111        if (string->has16BitShadow()) {
     112            size += 2 * size;
     113            if (string->hasTerminatingNullCharacter())
     114                size += 2;
     115        }
     116    } else
    106117        size *= 2;
    107118    return size + sizeof(*string);
     
    316327class ExternalResourceVisitor : public ExternalStringVisitor, public ExternalArrayVisitor {
    317328public:
    318     ExternalResourceVisitor()
    319         : m_jsExternalStringSize(0)
     329    explicit ExternalResourceVisitor(VisitedObjects& visitedObjects)
     330        : m_visitedObjects(visitedObjects)
     331        , m_jsExternalStringSize(0)
    320332        , m_externalArraySize(0)
    321333    { }
     
    328340    {
    329341        ArrayBuffer* buffer = bufferView->buffer().get();
    330         if (m_arrayBuffers.add(buffer).isNewEntry)
     342        if (m_visitedObjects.add(buffer).isNewEntry)
    331343            m_externalArraySize += buffer->byteLength();
    332344    }
    333345    virtual void visitJSExternalString(StringImpl* string)
    334346    {
    335         int size = stringSize(string);
    336         m_jsExternalStringSize += size;
    337     }
    338 
     347        if (m_visitedObjects.add(string).isNewEntry)
     348            m_jsExternalStringSize += stringSize(string);
     349    }
     350
     351    VisitedObjects& m_visitedObjects;
    339352    size_t m_jsExternalStringSize;
    340353    size_t m_externalArraySize;
    341     HashSet<ArrayBuffer*> m_arrayBuffers;
    342354};
    343355
     
    419431class MemoryInstrumentationImpl : public MemoryInstrumentation {
    420432public:
    421     MemoryInstrumentationImpl()
     433    explicit MemoryInstrumentationImpl(VisitedObjects& visitedObjects)
     434        : m_visitedObjects(visitedObjects)
    422435    {
    423436        for (int i = 0; i < LastTypeEntry; ++i)
     
    443456
    444457private:
     458    virtual void reportString(ObjectType objectType, const String& string)
     459    {
     460        if (visited(string.impl()))
     461            return;
     462        countObjectSize(objectType, stringSize(string.impl()));
     463    }
     464
    445465    virtual void countObjectSize(ObjectType objectType, size_t size)
    446466    {
     
    454474    }
    455475    size_t m_totalSizes[LastTypeEntry];
    456     typedef HashSet<const void*> VisitedObjects;
    457     VisitedObjects m_visitedObjects;
     476    VisitedObjects& m_visitedObjects;
    458477};
    459478
    460479class DOMTreesIterator : public NodeWrapperVisitor {
    461480public:
    462     explicit DOMTreesIterator(Page* page) : m_page(page) { }
     481    DOMTreesIterator(Page* page, VisitedObjects& visitedObjects)
     482        : m_page(page)
     483        , m_domMemoryUsage(visitedObjects)
     484    {
     485    }
    463486
    464487    virtual void visitNode(Node* node)
     
    479502}
    480503
    481 static PassRefPtr<InspectorMemoryBlock> domTreeInfo(Page* page)
    482 {
    483     DOMTreesIterator domTreesIterator(page);
     504static PassRefPtr<InspectorMemoryBlock> domTreeInfo(Page* page, VisitedObjects& visitedObjects)
     505{
     506    DOMTreesIterator domTreesIterator(page, visitedObjects);
    484507    ScriptProfiler::visitNodeWrappers(&domTreesIterator);
    485508
     
    514537}
    515538
    516 static PassRefPtr<InspectorMemoryBlock> jsExternalResourcesInfo()
    517 {
    518     ExternalResourceVisitor visitor;
     539static PassRefPtr<InspectorMemoryBlock> jsExternalResourcesInfo(VisitedObjects& visitedObjects)
     540{
     541    ExternalResourceVisitor visitor(visitedObjects);
    519542    ScriptProfiler::visitExternalStrings(&visitor);
    520543    ScriptProfiler::visitExternalArrays(&visitor);
     
    543566    processMemory->setSize(privateBytes);
    544567
     568    VisitedObjects visitedObjects;
    545569    RefPtr<TypeBuilder::Array<InspectorMemoryBlock> > children = TypeBuilder::Array<InspectorMemoryBlock>::create();
    546570    children->addItem(jsHeapInfo());
    547     children->addItem(jsExternalResourcesInfo());
    548571    children->addItem(inspectorData());
    549572    children->addItem(memoryCacheInfo());
    550573    children->addItem(renderTreeInfo(m_page)); // TODO: collect for all pages?
    551     children->addItem(domTreeInfo(m_page)); // TODO: collect for all pages?
     574    children->addItem(domTreeInfo(m_page, visitedObjects)); // TODO: collect for all pages?
     575    children->addItem(jsExternalResourcesInfo(visitedObjects));
    552576    processMemory->setChildren(children);
    553577}
  • trunk/Source/WebCore/inspector/front-end/NativeMemorySnapshotView.js

    r121144 r121530  
    217217    addBlock("hsl(  0,  0%, 100%)", "ProcessPrivateMemory", "Total");
    218218    addBlock("hsl(  0,  0%,  80%)", "Other", "Other");
     219    addBlock("hsl(300, 30%,  80%)", "DOM", "DOM tree structures");
    219220    addBlock("hsl( 90, 60%,  80%)", "JSHeapAllocated", "JavaScript heap");
    220221    addBlock("hsl( 90, 80%,  80%)", "JSHeapUsed", "Used JavaScript heap");
Note: See TracChangeset for help on using the changeset viewer.